1; NOTE: Assertions have been autogenerated by utils/update_test_checks.py 2; RUN: opt -S -instsimplify < %s | FileCheck %s 3 4define i1 @test1(i32 %a) { 5; CHECK-LABEL: @test1( 6; CHECK-NEXT: ret i1 false 7; 8 %rhs = add i32 %a, -1 9 %and = and i32 %a, %rhs 10 %res = icmp eq i32 %and, 1 11 ret i1 %res 12} 13 14define i1 @test1v(<2 x i32> %a) { 15; CHECK-LABEL: @test1v( 16; CHECK-NEXT: ret i1 false 17; 18 %rhs = add <2 x i32> %a, <i32 -1, i32 0> 19 %and = and <2 x i32> %a, %rhs 20 %ext = extractelement <2 x i32> %and, i32 0 21 %res = icmp eq i32 %ext, 1 22 ret i1 %res 23} 24 25define i1 @test2(i32 %a) { 26; CHECK-LABEL: @test2( 27; CHECK-NEXT: ret i1 false 28; 29 %rhs = add i32 %a, 1 30 %and = and i32 %a, %rhs 31 %res = icmp eq i32 %and, 1 32 ret i1 %res 33} 34 35define i1 @test2v(<2 x i32> %a) { 36; CHECK-LABEL: @test2v( 37; CHECK-NEXT: ret i1 false 38; 39 %rhs = add <2 x i32> %a, <i32 0, i32 1> 40 %and = and <2 x i32> %a, %rhs 41 %ext = extractelement <2 x i32> %and, i32 1 42 %res = icmp eq i32 %ext, 1 43 ret i1 %res 44} 45 46define i1 @test3(i32 %a) { 47; CHECK-LABEL: @test3( 48; CHECK-NEXT: ret i1 false 49; 50 %rhs = add i32 %a, 7 51 %and = and i32 %a, %rhs 52 %res = icmp eq i32 %and, 1 53 ret i1 %res 54} 55 56define i1 @test3v(<2 x i32> %a) { 57; CHECK-LABEL: @test3v( 58; CHECK-NEXT: ret i1 false 59; 60 %rhs = add <2 x i32> %a, <i32 7, i32 0> 61 %and = and <2 x i32> %a, %rhs 62 %ext = extractelement <2 x i32> %and, i32 0 63 %res = icmp eq i32 %ext, 1 64 ret i1 %res 65} 66 67@B = external global i32 68declare void @llvm.assume(i1) 69 70; Known bits without a constant 71define i1 @test4(i32 %a) { 72; CHECK-LABEL: @test4( 73; CHECK-NEXT: [[B:%.*]] = load i32, i32* @B 74; CHECK-NEXT: [[B_AND:%.*]] = and i32 [[B]], 1 75; CHECK-NEXT: [[B_CND:%.*]] = icmp eq i32 [[B_AND]], 1 76; CHECK-NEXT: call void @llvm.assume(i1 [[B_CND]]) 77; CHECK-NEXT: ret i1 false 78; 79 %b = load i32, i32* @B 80 %b.and = and i32 %b, 1 81 %b.cnd = icmp eq i32 %b.and, 1 82 call void @llvm.assume(i1 %b.cnd) 83 84 %rhs = add i32 %a, %b 85 %and = and i32 %a, %rhs 86 %res = icmp eq i32 %and, 1 87 ret i1 %res 88} 89 90; Negative test - even number 91define i1 @test5(i32 %a) { 92; CHECK-LABEL: @test5( 93; CHECK-NEXT: [[RHS:%.*]] = add i32 [[A:%.*]], 2 94; CHECK-NEXT: [[AND:%.*]] = and i32 [[A]], [[RHS]] 95; CHECK-NEXT: [[RES:%.*]] = icmp eq i32 [[AND]], 1 96; CHECK-NEXT: ret i1 [[RES]] 97; 98 %rhs = add i32 %a, 2 99 %and = and i32 %a, %rhs 100 %res = icmp eq i32 %and, 1 101 ret i1 %res 102} 103 104define i1 @test5v(<2 x i32> %a) { 105; CHECK-LABEL: @test5v( 106; CHECK-NEXT: [[RHS:%.*]] = add <2 x i32> [[A:%.*]], <i32 2, i32 0> 107; CHECK-NEXT: [[AND:%.*]] = and <2 x i32> [[A]], [[RHS]] 108; CHECK-NEXT: [[EXT:%.*]] = extractelement <2 x i32> [[AND]], i32 1 109; CHECK-NEXT: [[RES:%.*]] = icmp eq i32 [[EXT]], 1 110; CHECK-NEXT: ret i1 [[RES]] 111; 112 %rhs = add <2 x i32> %a, <i32 2, i32 0> 113 %and = and <2 x i32> %a, %rhs 114 %ext = extractelement <2 x i32> %and, i32 1 115 %res = icmp eq i32 %ext, 1 116 ret i1 %res 117} 118 119define i1 @test6(i32 %a) { 120; CHECK-LABEL: @test6( 121; CHECK-NEXT: ret i1 false 122; 123 %lhs = add i32 %a, -1 124 %and = and i32 %lhs, %a 125 %res = icmp eq i32 %and, 1 126 ret i1 %res 127} 128 129define i1 @test6v(<2 x i32> %a) { 130; CHECK-LABEL: @test6v( 131; CHECK-NEXT: ret i1 false 132; 133 %lhs = add <2 x i32> %a, <i32 0, i32 -1> 134 %and = and <2 x i32> %lhs, %a 135 %ext = extractelement <2 x i32> %and, i32 1 136 %res = icmp eq i32 %ext, 1 137 ret i1 %res 138} 139