Home | History | Annotate | Download | only in X86
      1 ; RUN: llc -o - %s | FileCheck %s
      2 target triple = "x86_64-unknown-unknown"
      3 
      4 ; select with and i1/or i1 condition should be implemented as a series of 2
      5 ; cmovs, not by producing two conditions and using and on them.
      6 
      7 define i32 @select_and(i32 %a0, i32 %a1, float %a2, float %a3, i32 %a4, i32 %a5) {
      8 ; CHECK-LABEL: select_and
      9 ; CHECK-NOT: set
     10 ; CHECK-NOT: and[lb]
     11 ; CHECK-NOT: test
     12 ; CHECK: cmov
     13 ; CHECK: cmov
     14   %cmp0 = icmp ult i32 %a0, %a1
     15   %cmp1 = fcmp olt float %a2, %a3
     16   %and = and i1 %cmp0, %cmp1
     17   %res = select i1 %and, i32 %a4, i32 %a5
     18   ret i32 %res
     19 }
     20 
     21 define i32 @select_or(i32 %a0, i32 %a1, float %a2, float %a3, i32 %a4, i32 %a5) {
     22 ; select with and i1 condition should be implemented as a series of 2 cmovs, not
     23 ; by producing two conditions and using and on them.
     24 ; CHECK-LABEL: select_or
     25 ; CHECK-NOT: set
     26 ; CHECK-NOT: or[lb]
     27 ; CHECK-NOT: test
     28 ; CHECK: cmov
     29 ; CHECK: cmov
     30   %cmp0 = icmp ult i32 %a0, %a1
     31   %cmp1 = fcmp olt float %a2, %a3
     32   %and = or i1 %cmp0, %cmp1
     33   %res = select i1 %and, i32 %a4, i32 %a5
     34   ret i32 %res
     35 }
     36 
     37 ; If one of the conditions is materialized as a 0/1 value anyway, then the
     38 ; sequence of 2 cmovs should not be used.
     39 
     40 @var32 = global i32 0
     41 define i32 @select_noopt(i32 %a0, i32 %a1, i32 %a2, i32 %a3, i32 %a4) {
     42 ; CHECK-LABEL: select_noopt
     43 ; CHECK: cmov
     44 ; CHECK-NOT: cmov
     45   %cmp0 = icmp ult i32 %a0, %a1
     46   %cmp1 = icmp ult i32 %a1, %a2
     47   %or = or i1 %cmp0, %cmp1
     48   %zero_one = zext i1 %or to i32
     49   store volatile i32 %zero_one, i32* @var32
     50   %res = select i1 %or, i32 %a3, i32 %a4
     51   ret i32 %res
     52 }
     53