1; RUN: opt < %s -instsimplify -S | FileCheck %s 2 3define i32 @test1(i32 %x) { 4 %and = and i32 %x, 1 5 %cmp = icmp eq i32 %and, 0 6 %and1 = and i32 %x, -2 7 %and1.x = select i1 %cmp, i32 %and1, i32 %x 8 ret i32 %and1.x 9; CHECK-LABEL: @test1( 10; CHECK: ret i32 %x 11} 12 13define i32 @test2(i32 %x) { 14 %and = and i32 %x, 1 15 %cmp = icmp ne i32 %and, 0 16 %and1 = and i32 %x, -2 17 %and1.x = select i1 %cmp, i32 %x, i32 %and1 18 ret i32 %and1.x 19; CHECK-LABEL: @test2( 20; CHECK: ret i32 %x 21} 22 23define i32 @test3(i32 %x) { 24 %and = and i32 %x, 1 25 %cmp = icmp ne i32 %and, 0 26 %and1 = and i32 %x, -2 27 %and1.x = select i1 %cmp, i32 %and1, i32 %x 28 ret i32 %and1.x 29; CHECK-LABEL: @test3( 30; CHECK: %[[and:.*]] = and i32 %x, -2 31; CHECK: ret i32 %[[and]] 32} 33 34define i32 @test4(i32 %X) { 35 %cmp = icmp slt i32 %X, 0 36 %or = or i32 %X, -2147483648 37 %cond = select i1 %cmp, i32 %X, i32 %or 38 ret i32 %cond 39; CHECK-LABEL: @test4 40; CHECK: %[[or:.*]] = or i32 %X, -2147483648 41; CHECK: ret i32 %[[or]] 42} 43 44define i32 @test5(i32 %X) { 45 %cmp = icmp slt i32 %X, 0 46 %or = or i32 %X, -2147483648 47 %cond = select i1 %cmp, i32 %or, i32 %X 48 ret i32 %cond 49; CHECK-LABEL: @test5 50; CHECK: ret i32 %X 51} 52 53define i32 @test6(i32 %X) { 54 %cmp = icmp slt i32 %X, 0 55 %and = and i32 %X, 2147483647 56 %cond = select i1 %cmp, i32 %and, i32 %X 57 ret i32 %cond 58; CHECK-LABEL: @test6 59; CHECK: %[[and:.*]] = and i32 %X, 2147483647 60; CHECK: ret i32 %[[and]] 61} 62 63define i32 @test7(i32 %X) { 64 %cmp = icmp slt i32 %X, 0 65 %and = and i32 %X, 2147483647 66 %cond = select i1 %cmp, i32 %X, i32 %and 67 ret i32 %cond 68; CHECK-LABEL: @test7 69; CHECK: ret i32 %X 70} 71 72define i32 @test8(i32 %X) { 73 %cmp = icmp sgt i32 %X, -1 74 %or = or i32 %X, -2147483648 75 %cond = select i1 %cmp, i32 %X, i32 %or 76 ret i32 %cond 77; CHECK-LABEL: @test8 78; CHECK: ret i32 %X 79} 80 81define i32 @test9(i32 %X) { 82 %cmp = icmp sgt i32 %X, -1 83 %or = or i32 %X, -2147483648 84 %cond = select i1 %cmp, i32 %or, i32 %X 85 ret i32 %cond 86; CHECK-LABEL: @test9 87; CHECK: %[[or:.*]] = or i32 %X, -2147483648 88; CHECK: ret i32 %[[or]] 89} 90 91define i32 @test10(i32 %X) { 92 %cmp = icmp sgt i32 %X, -1 93 %and = and i32 %X, 2147483647 94 %cond = select i1 %cmp, i32 %and, i32 %X 95 ret i32 %cond 96; CHECK-LABEL: @test10 97; CHECK: ret i32 %X 98} 99 100define i32 @test11(i32 %X) { 101 %cmp = icmp sgt i32 %X, -1 102 %and = and i32 %X, 2147483647 103 %cond = select i1 %cmp, i32 %X, i32 %and 104 ret i32 %cond 105; CHECK-LABEL: @test11 106; CHECK: %[[and:.*]] = and i32 %X, 2147483647 107; CHECK: ret i32 %[[and]] 108} 109 110; CHECK-LABEL: @select_icmp_and_8_eq_0_or_8( 111; CHECK-NEXT: [[OR:%[a-z0-9]+]] = or i32 %x, 8 112; CHECK-NEXT: ret i32 [[OR]] 113define i32 @select_icmp_and_8_eq_0_or_8(i32 %x) { 114 %and = and i32 %x, 8 115 %cmp = icmp eq i32 %and, 0 116 %or = or i32 %x, 8 117 %or.x = select i1 %cmp, i32 %or, i32 %x 118 ret i32 %or.x 119} 120 121; CHECK-LABEL: @select_icmp_and_8_ne_0_and_not_8( 122; CHECK-NEXT: [[AND:%[a-z0-9]+]] = and i32 %x, -9 123; CHECK-NEXT: ret i32 [[AND]] 124define i32 @select_icmp_and_8_ne_0_and_not_8(i32 %x) { 125 %and = and i32 %x, 8 126 %cmp = icmp eq i32 %and, 0 127 %and1 = and i32 %x, -9 128 %x.and1 = select i1 %cmp, i32 %x, i32 %and1 129 ret i32 %x.and1 130} 131 132; CHECK-LABEL: @select_icmp_and_8_eq_0_and_not_8( 133; CHECK-NEXT: ret i32 %x 134define i32 @select_icmp_and_8_eq_0_and_not_8(i32 %x) { 135 %and = and i32 %x, 8 136 %cmp = icmp eq i32 %and, 0 137 %and1 = and i32 %x, -9 138 %and1.x = select i1 %cmp, i32 %and1, i32 %x 139 ret i32 %and1.x 140} 141 142; CHECK-LABEL: @select_icmp_x_and_8_eq_0_y_and_not_8( 143; CHECK: select i1 %cmp, i64 %y, i64 %and1 144define i64 @select_icmp_x_and_8_eq_0_y_and_not_8(i32 %x, i64 %y) { 145 %and = and i32 %x, 8 146 %cmp = icmp eq i32 %and, 0 147 %and1 = and i64 %y, -9 148 %y.and1 = select i1 %cmp, i64 %y, i64 %and1 149 ret i64 %y.and1 150} 151 152; CHECK-LABEL: @select_icmp_x_and_8_ne_0_y_and_not_8( 153; CHECK: select i1 %cmp, i64 %and1, i64 %y 154define i64 @select_icmp_x_and_8_ne_0_y_and_not_8(i32 %x, i64 %y) { 155 %and = and i32 %x, 8 156 %cmp = icmp eq i32 %and, 0 157 %and1 = and i64 %y, -9 158 %and1.y = select i1 %cmp, i64 %and1, i64 %y 159 ret i64 %and1.y 160} 161 162