[LLVMdev] llvm 'select' instruction

Jan Tlatlik jtlatlik at techfak.uni-bielefeld.de
Sun Apr 14 06:34:20 PDT 2013


On 04/14/2013 02:17 PM, Dong Chen wrote:
> hello guys:
> i am thinking about what kind of C instructions can turn into llvm IR
> 'select' instruction.
> i tried "d=a?b:c" and compiled it using clang, i still didn't get 'select'
> is there anybody who knows this?
> thank you

Did you try to compile this with optimization enabled? (at least -O1)

For me, this gets compiled to a select instruction:

int a;

int main() {
 return a > 0 ? 123: 321;
}

Results in:

@a = common global i32 0, align 4

define i32 @main() nounwind uwtable readonly {
entry:
  %0 = load i32* @a, align 4, !tbaa !0
  %cmp = icmp sgt i32 %0, 0
  %cond = select i1 %cmp, i32 123, i32 321
  ret i32 %cond
}

!0 = metadata !{metadata !"int", metadata !1}
!1 = metadata !{metadata !"omnipotent char", metadata !2}
!2 = metadata !{metadata !"Simple C/C++ TBAA"}


Greetings,
Jan



More information about the llvm-dev mailing list