Home | History | Annotate | Download | only in InstCombine
      1 ; RUN: opt -instcombine -S < %s | FileCheck %s
      2 
      3 define i32 @test1(i32 %x) nounwind {
      4   %and = and i32 %x, 31
      5   %sub = sub i32 63, %and
      6   ret i32 %sub
      7 
      8 ; CHECK-LABEL: @test1(
      9 ; CHECK-NEXT: and i32 %x, 31
     10 ; CHECK-NEXT: xor i32 %and, 63
     11 ; CHECK-NEXT: ret
     12 }
     13 
     14 declare i32 @llvm.ctlz.i32(i32, i1) nounwind readnone
     15 
     16 define i32 @test2(i32 %x) nounwind {
     17   %count = tail call i32 @llvm.ctlz.i32(i32 %x, i1 true) nounwind readnone
     18   %sub = sub i32 31, %count
     19   ret i32 %sub
     20 
     21 ; CHECK-LABEL: @test2(
     22 ; CHECK-NEXT: ctlz
     23 ; CHECK-NEXT: xor i32 %count, 31
     24 ; CHECK-NEXT: ret
     25 }
     26 
     27 define i32 @test3(i32 %x) nounwind {
     28   %and = and i32 %x, 31
     29   %sub = xor i32 31, %and
     30   %add = add i32 %sub, 42
     31   ret i32 %add
     32 
     33 ; CHECK-LABEL: @test3(
     34 ; CHECK-NEXT: and i32 %x, 31
     35 ; CHECK-NEXT: sub i32 73, %and
     36 ; CHECK-NEXT: ret
     37 }
     38 
     39 define i32 @test4(i32 %x) nounwind {
     40   %sub = xor i32 %x, 2147483648
     41   %add = add i32 %sub, 42
     42   ret i32 %add
     43 
     44 ; CHECK-LABEL: @test4(
     45 ; CHECK-NEXT: add i32 %x, -2147483606
     46 ; CHECK-NEXT: ret
     47 }
     48