Home | History | Annotate | Download | only in InstSimplify
      1 ; RUN: opt -S -instsimplify < %s | FileCheck %s
      2 
      3 define i1 @test(i32 %a) {
      4 ; CHECK-LABEL: @test
      5 ; CHECK: ret i1 false
      6   %rhs = add i32 %a, -1
      7   %and = and i32 %a, %rhs
      8   %res = icmp eq i32 %and, 1
      9   ret i1 %res
     10 }
     11 
     12 define i1 @test2(i32 %a) {
     13 ; CHECK-LABEL: @test2
     14 ; CHECK: ret i1 false
     15   %rhs = add i32 %a, 1
     16   %and = and i32 %a, %rhs
     17   %res = icmp eq i32 %and, 1
     18   ret i1 %res
     19 }
     20 
     21 define i1 @test3(i32 %a) {
     22 ; CHECK-LABEL: @test3
     23 ; CHECK: ret i1 false
     24   %rhs = add i32 %a, 7
     25   %and = and i32 %a, %rhs
     26   %res = icmp eq i32 %and, 1
     27   ret i1 %res
     28 }
     29 
     30 @B = external global i32
     31 declare void @llvm.assume(i1)
     32 
     33 ; Known bits without a constant
     34 define i1 @test4(i32 %a) {
     35 ; CHECK-LABEL: @test4
     36 ; CHECK: ret i1 false
     37   %b = load i32, i32* @B
     38   %b.and = and i32 %b, 1
     39   %b.cnd = icmp eq i32 %b.and, 1
     40   call void @llvm.assume(i1 %b.cnd)
     41 
     42   %rhs = add i32 %a, %b
     43   %and = and i32 %a, %rhs
     44   %res = icmp eq i32 %and, 1
     45   ret i1 %res
     46 }
     47 
     48 ; Negative test - even number
     49 define i1 @test5(i32 %a) {
     50 ; CHECK-LABEL: @test5
     51 ; CHECK: ret i1 %res
     52   %rhs = add i32 %a, 2
     53   %and = and i32 %a, %rhs
     54   %res = icmp eq i32 %and, 1
     55   ret i1 %res
     56 }
     57 
     58 define i1 @test6(i32 %a) {
     59 ; CHECK-LABEL: @test6
     60 ; CHECK: ret i1 false
     61   %lhs = add i32 %a, -1
     62   %and = and i32 %lhs, %a
     63   %res = icmp eq i32 %and, 1
     64   ret i1 %res
     65 }
     66