Hi all,
I am implementing SPIR-V to LLVM conversion and currently working on control flow.
In SPIR-V, conditional branch instruction takes an optional branch weights attribute (likeliness of branch to be taken). For example:
spv.BranchConditional %true [5, 10], ^one, ^two
In proper LLVM this is modelled with branch weight metadata, particularly for conditional branches:
!0 = metadata !{
metadata !"branch_weights",
i32 <TRUE_BRANCH_WEIGHT>,
i32 <FALSE_BRANCH_WEIGHT>
}
However, there is no such thing in LLVM dialect. This is just a compiler hint, but it will be nice for a better op semantic equivalence in SPIR-V (possibly other dialects) to LLVM conversion and may help with optimisation passes (dead branch elimination etc.).
Since LLVM dialect does not support metadata and uses attribute system for this purpose, I am wondering if it would be useful to add optional branch weight attribute directly to llvm.cond_br
op? When translating later to proper LLVM, this can be translated into actual metadata info.