|
4 | 4 | target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
5 | 5 | target triple = "x86_64-unknown-linux-gnu"
|
6 | 6 |
|
| 7 | +declare void @use.i8(i8) |
| 8 | + |
7 | 9 | ; Should be optimized to one and.
|
8 | 10 | define i1 @test1(i32 %a, i32 %b) {
|
9 | 11 | ; CHECK-LABEL: @test1(
|
@@ -75,3 +77,158 @@ define <2 x i1> @test3vec(<2 x i64> %A) {
|
75 | 77 | ret <2 x i1> %cmp
|
76 | 78 | }
|
77 | 79 |
|
| 80 | +define i1 @test_eq_p2(i8 %x, i8 %yy) { |
| 81 | +; CHECK-LABEL: @test_eq_p2( |
| 82 | +; CHECK-NEXT: [[Y:%.*]] = shl nuw nsw i8 1, [[YY:%.*]] |
| 83 | +; CHECK-NEXT: [[TMP1:%.*]] = add nsw i8 [[Y]], -1 |
| 84 | +; CHECK-NEXT: [[TMP2:%.*]] = xor i8 [[Y]], [[TMP1]] |
| 85 | +; CHECK-NEXT: [[R:%.*]] = icmp uge i8 [[TMP2]], [[X:%.*]] |
| 86 | +; CHECK-NEXT: ret i1 [[R]] |
| 87 | +; |
| 88 | + %y = shl nsw i8 1, %yy |
| 89 | + %neg_y = sub i8 0, %y |
| 90 | + %and_x_neg_y = and i8 %x, %neg_y |
| 91 | + %and_x_y = and i8 %x, %y |
| 92 | + |
| 93 | + %r = icmp eq i8 %and_x_y, %and_x_neg_y |
| 94 | + ret i1 %r |
| 95 | +} |
| 96 | + |
| 97 | +define i1 @test_eq_p2_2(i8 %x, i8 %yy) { |
| 98 | +; CHECK-LABEL: @test_eq_p2_2( |
| 99 | +; CHECK-NEXT: [[Y:%.*]] = shl nuw nsw i8 1, [[YY:%.*]] |
| 100 | +; CHECK-NEXT: [[TMP1:%.*]] = add nsw i8 [[Y]], -1 |
| 101 | +; CHECK-NEXT: [[TMP2:%.*]] = xor i8 [[Y]], [[TMP1]] |
| 102 | +; CHECK-NEXT: [[R:%.*]] = icmp uge i8 [[TMP2]], [[X:%.*]] |
| 103 | +; CHECK-NEXT: ret i1 [[R]] |
| 104 | +; |
| 105 | + %y = shl nsw i8 1, %yy |
| 106 | + %neg_y = sub i8 0, %y |
| 107 | + %and_x_neg_y = and i8 %x, %neg_y |
| 108 | + %and_x_y = and i8 %x, %y |
| 109 | + |
| 110 | + %r = icmp eq i8 %and_x_neg_y, %and_x_y |
| 111 | + ret i1 %r |
| 112 | +} |
| 113 | + |
| 114 | +define i1 @test_eq_p2_fail_maybe_zero(i8 %x, i8 %yy) { |
| 115 | +; CHECK-LABEL: @test_eq_p2_fail_maybe_zero( |
| 116 | +; CHECK-NEXT: [[Y:%.*]] = shl i8 2, [[YY:%.*]] |
| 117 | +; CHECK-NEXT: [[TMP1:%.*]] = add i8 [[Y]], -1 |
| 118 | +; CHECK-NEXT: [[TMP2:%.*]] = xor i8 [[Y]], [[TMP1]] |
| 119 | +; CHECK-NEXT: [[R:%.*]] = icmp uge i8 [[TMP2]], [[X:%.*]] |
| 120 | +; CHECK-NEXT: ret i1 [[R]] |
| 121 | +; |
| 122 | + %yyy = shl nsw i8 1, %yy |
| 123 | + %y = add i8 %yyy, %yyy |
| 124 | + %neg_y = sub nsw i8 0, %y |
| 125 | + %and_x_neg_y = and i8 %x, %neg_y |
| 126 | + %and_x_y = and i8 %x, %y |
| 127 | + |
| 128 | + %r = icmp eq i8 %and_x_neg_y, %and_x_y |
| 129 | + ret i1 %r |
| 130 | +} |
| 131 | + |
| 132 | +define i1 @test_eq_p2_fail_maybe_int_min(i8 %x, i8 %yy) { |
| 133 | +; CHECK-LABEL: @test_eq_p2_fail_maybe_int_min( |
| 134 | +; CHECK-NEXT: [[Y:%.*]] = shl nuw i8 1, [[YY:%.*]] |
| 135 | +; CHECK-NEXT: [[TMP1:%.*]] = add i8 [[Y]], -1 |
| 136 | +; CHECK-NEXT: [[TMP2:%.*]] = xor i8 [[Y]], [[TMP1]] |
| 137 | +; CHECK-NEXT: [[R:%.*]] = icmp uge i8 [[TMP2]], [[X:%.*]] |
| 138 | +; CHECK-NEXT: ret i1 [[R]] |
| 139 | +; |
| 140 | + %y = shl i8 1, %yy |
| 141 | + %neg_y = sub i8 0, %y |
| 142 | + %and_x_neg_y = and i8 %x, %neg_y |
| 143 | + %and_x_y = and i8 %x, %y |
| 144 | + |
| 145 | + %r = icmp eq i8 %and_x_y, %and_x_neg_y |
| 146 | + ret i1 %r |
| 147 | +} |
| 148 | + |
| 149 | +define i1 @test_eq_p2_fail_multiuse(i8 %x, i8 %yy) { |
| 150 | +; CHECK-LABEL: @test_eq_p2_fail_multiuse( |
| 151 | +; CHECK-NEXT: [[Y:%.*]] = shl nuw nsw i8 1, [[YY:%.*]] |
| 152 | +; CHECK-NEXT: [[NEG_Y:%.*]] = sub nsw i8 0, [[Y]] |
| 153 | +; CHECK-NEXT: [[AND_X_NEG_Y:%.*]] = and i8 [[NEG_Y]], [[X:%.*]] |
| 154 | +; CHECK-NEXT: [[AND_X_Y:%.*]] = and i8 [[Y]], [[X]] |
| 155 | +; CHECK-NEXT: call void @use.i8(i8 [[AND_X_Y]]) |
| 156 | +; CHECK-NEXT: [[R:%.*]] = icmp eq i8 [[AND_X_Y]], [[AND_X_NEG_Y]] |
| 157 | +; CHECK-NEXT: ret i1 [[R]] |
| 158 | +; |
| 159 | + %y = shl nsw i8 1, %yy |
| 160 | + %neg_y = sub i8 0, %y |
| 161 | + %and_x_neg_y = and i8 %x, %neg_y |
| 162 | + %and_x_y = and i8 %x, %y |
| 163 | + call void @use.i8(i8 %and_x_y) |
| 164 | + %r = icmp eq i8 %and_x_y, %and_x_neg_y |
| 165 | + ret i1 %r |
| 166 | +} |
| 167 | + |
| 168 | +define i1 @test_ne_cp2(i8 %x, i8 %yy) { |
| 169 | +; CHECK-LABEL: @test_ne_cp2( |
| 170 | +; CHECK-NEXT: [[AND_X_NEG_Y:%.*]] = and i8 [[X:%.*]], -16 |
| 171 | +; CHECK-NEXT: [[AND_X_Y:%.*]] = and i8 [[X]], 16 |
| 172 | +; CHECK-NEXT: call void @use.i8(i8 [[AND_X_NEG_Y]]) |
| 173 | +; CHECK-NEXT: call void @use.i8(i8 [[AND_X_Y]]) |
| 174 | +; CHECK-NEXT: [[R:%.*]] = icmp ne i8 [[AND_X_NEG_Y]], [[AND_X_Y]] |
| 175 | +; CHECK-NEXT: ret i1 [[R]] |
| 176 | +; |
| 177 | + %and_x_neg_y = and i8 %x, -16 |
| 178 | + %and_x_y = and i8 %x, 16 |
| 179 | + call void @use.i8(i8 %and_x_neg_y) |
| 180 | + call void @use.i8(i8 %and_x_y) |
| 181 | + %r = icmp ne i8 %and_x_neg_y, %and_x_y |
| 182 | + ret i1 %r |
| 183 | +} |
| 184 | + |
| 185 | +define i1 @test_ne_cp2_2(i8 %x, i8 %yy) { |
| 186 | +; CHECK-LABEL: @test_ne_cp2_2( |
| 187 | +; CHECK-NEXT: [[AND_X_NEG_Y:%.*]] = and i8 [[X:%.*]], -4 |
| 188 | +; CHECK-NEXT: [[AND_X_Y:%.*]] = and i8 [[X]], 4 |
| 189 | +; CHECK-NEXT: call void @use.i8(i8 [[AND_X_NEG_Y]]) |
| 190 | +; CHECK-NEXT: call void @use.i8(i8 [[AND_X_Y]]) |
| 191 | +; CHECK-NEXT: [[R:%.*]] = icmp ne i8 [[AND_X_Y]], [[AND_X_NEG_Y]] |
| 192 | +; CHECK-NEXT: ret i1 [[R]] |
| 193 | +; |
| 194 | + %and_x_neg_y = and i8 %x, -4 |
| 195 | + %and_x_y = and i8 %x, 4 |
| 196 | + call void @use.i8(i8 %and_x_neg_y) |
| 197 | + call void @use.i8(i8 %and_x_y) |
| 198 | + %r = icmp ne i8 %and_x_y, %and_x_neg_y |
| 199 | + ret i1 %r |
| 200 | +} |
| 201 | + |
| 202 | +define i1 @test_ne_cp2_other_fail(i8 %x, i8 %yy) { |
| 203 | +; CHECK-LABEL: @test_ne_cp2_other_fail( |
| 204 | +; CHECK-NEXT: [[AND_X_NEG_Y:%.*]] = and i8 [[X:%.*]], -17 |
| 205 | +; CHECK-NEXT: [[AND_X_Y:%.*]] = and i8 [[X]], 16 |
| 206 | +; CHECK-NEXT: call void @use.i8(i8 [[AND_X_NEG_Y]]) |
| 207 | +; CHECK-NEXT: call void @use.i8(i8 [[AND_X_Y]]) |
| 208 | +; CHECK-NEXT: [[R:%.*]] = icmp ne i8 [[AND_X_NEG_Y]], [[AND_X_Y]] |
| 209 | +; CHECK-NEXT: ret i1 [[R]] |
| 210 | +; |
| 211 | + %and_x_neg_y = and i8 %x, -17 |
| 212 | + %and_x_y = and i8 %x, 16 |
| 213 | + call void @use.i8(i8 %and_x_neg_y) |
| 214 | + call void @use.i8(i8 %and_x_y) |
| 215 | + %r = icmp ne i8 %and_x_neg_y, %and_x_y |
| 216 | + ret i1 %r |
| 217 | +} |
| 218 | + |
| 219 | +define i1 @test_ne_cp2_other_fail2(i8 %x, i8 %yy) { |
| 220 | +; CHECK-LABEL: @test_ne_cp2_other_fail2( |
| 221 | +; CHECK-NEXT: [[AND_X_NEG_Y:%.*]] = and i8 [[X:%.*]], -16 |
| 222 | +; CHECK-NEXT: [[AND_X_Y:%.*]] = and i8 [[X]], 17 |
| 223 | +; CHECK-NEXT: call void @use.i8(i8 [[AND_X_NEG_Y]]) |
| 224 | +; CHECK-NEXT: call void @use.i8(i8 [[AND_X_Y]]) |
| 225 | +; CHECK-NEXT: [[R:%.*]] = icmp ne i8 [[AND_X_NEG_Y]], [[AND_X_Y]] |
| 226 | +; CHECK-NEXT: ret i1 [[R]] |
| 227 | +; |
| 228 | + %and_x_neg_y = and i8 %x, -16 |
| 229 | + %and_x_y = and i8 %x, 17 |
| 230 | + call void @use.i8(i8 %and_x_neg_y) |
| 231 | + call void @use.i8(i8 %and_x_y) |
| 232 | + %r = icmp ne i8 %and_x_neg_y, %and_x_y |
| 233 | + ret i1 %r |
| 234 | +} |
0 commit comments