Reputation: 1356
LLVM has a SelectInst
that is used to represent expressions like something = cond ? true-part : false-part
.
What is the benefit of this instruction in the IR, as ?:
could also always be lowered to a BranchInst
by the compiler? Are there CPUs that support such instructions? Or is select
lowered to jumps by the CodeGenerator anyway?
I reckon there may be benefits for analysis passes as the select
guarantees two "branches" of the implicit if
. But on the other hand, compilers are not required to use the instruction at all, so these passes must be able to deal with br
s anyway.
Upvotes: 4
Views: 1336
Reputation: 26868
Yes, you can use always use a conditional branch instead of a select instruction, but a select has several advantages:
Upvotes: 7