1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
6 define i41 @test5(i41 %X) {
8 ; CHECK-NEXT: [[Y:%.*]] = and i41 [[X:%.*]], 32
9 ; CHECK-NEXT: ret i41 [[Y]]
12 %t = icmp ne i41 %Y, 0
13 %V = select i1 %t, i41 32, i41 0
17 ;; ((X & 27) ? 27 : 0)
19 define i1023 @test6(i1023 %X) {
20 ; CHECK-LABEL: @test6(
21 ; CHECK-NEXT: [[Y:%.*]] = and i1023 [[X:%.*]], 64
22 ; CHECK-NEXT: ret i1023 [[Y]]
25 %t = icmp ne i1023 %Y, 0
26 %V = select i1 %t, i1023 64, i1023 0
30 define i32 @test35(i32 %x) {
31 ; CHECK-LABEL: @test35(
32 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X:%.*]], -1
33 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 60, i32 100
34 ; CHECK-NEXT: ret i32 [[COND]]
36 %cmp = icmp sge i32 %x, 0
37 %cond = select i1 %cmp, i32 60, i32 100
41 define <2 x i32> @test35vec(<2 x i32> %x) {
42 ; CHECK-LABEL: @test35vec(
43 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i32> [[X:%.*]], <i32 -1, i32 -1>
44 ; CHECK-NEXT: [[COND:%.*]] = select <2 x i1> [[CMP]], <2 x i32> <i32 60, i32 60>, <2 x i32> <i32 100, i32 100>
45 ; CHECK-NEXT: ret <2 x i32> [[COND]]
47 %cmp = icmp sge <2 x i32> %x, <i32 0, i32 0>
48 %cond = select <2 x i1> %cmp, <2 x i32> <i32 60, i32 60>, <2 x i32> <i32 100, i32 100>
52 ; Make sure we can still perform this optimization with a truncate present
53 define i32 @test35_with_trunc(i64 %x) {
54 ; CHECK-LABEL: @test35_with_trunc(
55 ; CHECK-NEXT: [[X1:%.*]] = trunc i64 [[X:%.*]] to i32
56 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X1]], -1
57 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 60, i32 100
58 ; CHECK-NEXT: ret i32 [[COND]]
60 %x1 = trunc i64 %x to i32
61 %cmp = icmp sge i32 %x1, 0
62 %cond = select i1 %cmp, i32 60, i32 100
66 define i32 @test36(i32 %x) {
67 ; CHECK-LABEL: @test36(
68 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i32 [[X:%.*]], 0
69 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 60, i32 100
70 ; CHECK-NEXT: ret i32 [[COND]]
72 %cmp = icmp slt i32 %x, 0
73 %cond = select i1 %cmp, i32 60, i32 100
77 define <2 x i32> @test36vec(<2 x i32> %x) {
78 ; CHECK-LABEL: @test36vec(
79 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i32> [[X:%.*]], zeroinitializer
80 ; CHECK-NEXT: [[COND:%.*]] = select <2 x i1> [[CMP]], <2 x i32> <i32 60, i32 60>, <2 x i32> <i32 100, i32 100>
81 ; CHECK-NEXT: ret <2 x i32> [[COND]]
83 %cmp = icmp slt <2 x i32> %x, <i32 0, i32 0>
84 %cond = select <2 x i1> %cmp, <2 x i32> <i32 60, i32 60>, <2 x i32> <i32 100, i32 100>
88 define i32 @test37(i32 %x) {
89 ; CHECK-LABEL: @test37(
90 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X:%.*]], -1
91 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 1, i32 -1
92 ; CHECK-NEXT: ret i32 [[COND]]
94 %cmp = icmp sgt i32 %x, -1
95 %cond = select i1 %cmp, i32 1, i32 -1
99 define <2 x i32> @test37vec(<2 x i32> %x) {
100 ; CHECK-LABEL: @test37vec(
101 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt <2 x i32> [[X:%.*]], <i32 -1, i32 -1>
102 ; CHECK-NEXT: [[COND:%.*]] = select <2 x i1> [[CMP]], <2 x i32> <i32 1, i32 1>, <2 x i32> <i32 -1, i32 -1>
103 ; CHECK-NEXT: ret <2 x i32> [[COND]]
105 %cmp = icmp sgt <2 x i32> %x, <i32 -1, i32 -1>
106 %cond = select <2 x i1> %cmp, <2 x i32> <i32 1, i32 1>, <2 x i32> <i32 -1, i32 -1>
110 define i32 @test65(i64 %x) {
111 ; CHECK-LABEL: @test65(
112 ; CHECK-NEXT: [[TMP1:%.*]] = and i64 [[X:%.*]], 16
113 ; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i64 [[TMP1]], 0
114 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[TMP2]], i32 42, i32 40
115 ; CHECK-NEXT: ret i32 [[TMP3]]
118 %2 = icmp ne i64 %1, 0
119 %3 = select i1 %2, i32 40, i32 42
123 define <2 x i32> @test65vec(<2 x i64> %x) {
124 ; CHECK-LABEL: @test65vec(
125 ; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i64> [[X:%.*]], <i64 16, i64 16>
126 ; CHECK-NEXT: [[TMP2:%.*]] = icmp eq <2 x i64> [[TMP1]], zeroinitializer
127 ; CHECK-NEXT: [[TMP3:%.*]] = select <2 x i1> [[TMP2]], <2 x i32> <i32 42, i32 42>, <2 x i32> <i32 40, i32 40>
128 ; CHECK-NEXT: ret <2 x i32> [[TMP3]]
130 %1 = and <2 x i64> %x, <i64 16, i64 16>
131 %2 = icmp ne <2 x i64> %1, zeroinitializer
132 %3 = select <2 x i1> %2, <2 x i32> <i32 40, i32 40>, <2 x i32> <i32 42, i32 42>
136 define i32 @test66(i64 %x) {
137 ; CHECK-LABEL: @test66(
138 ; CHECK-NEXT: [[TMP1:%.*]] = and i64 [[X:%.*]], 4294967296
139 ; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i64 [[TMP1]], 0
140 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[TMP2]], i32 42, i32 40
141 ; CHECK-NEXT: ret i32 [[TMP3]]
143 %1 = and i64 %x, 4294967296
144 %2 = icmp ne i64 %1, 0
145 %3 = select i1 %2, i32 40, i32 42
149 define <2 x i32> @test66vec(<2 x i64> %x) {
150 ; CHECK-LABEL: @test66vec(
151 ; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i64> [[X:%.*]], <i64 4294967296, i64 4294967296>
152 ; CHECK-NEXT: [[TMP2:%.*]] = icmp eq <2 x i64> [[TMP1]], zeroinitializer
153 ; CHECK-NEXT: [[TMP3:%.*]] = select <2 x i1> [[TMP2]], <2 x i32> <i32 42, i32 42>, <2 x i32> <i32 40, i32 40>
154 ; CHECK-NEXT: ret <2 x i32> [[TMP3]]
156 %1 = and <2 x i64> %x, <i64 4294967296, i64 4294967296>
157 %2 = icmp ne <2 x i64> %1, zeroinitializer
158 %3 = select <2 x i1> %2, <2 x i32> <i32 40, i32 40>, <2 x i32> <i32 42, i32 42>
162 ; Make sure we don't try to optimize a scalar 'and' with a vector select.
163 define <2 x i32> @test66vec_scalar_and(i64 %x) {
164 ; CHECK-LABEL: @test66vec_scalar_and(
165 ; CHECK-NEXT: [[TMP1:%.*]] = and i64 [[X:%.*]], 4294967296
166 ; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i64 [[TMP1]], 0
167 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[TMP2]], <2 x i32> <i32 42, i32 42>, <2 x i32> <i32 40, i32 40>
168 ; CHECK-NEXT: ret <2 x i32> [[TMP3]]
170 %1 = and i64 %x, 4294967296
171 %2 = icmp ne i64 %1, 0
172 %3 = select i1 %2, <2 x i32> <i32 40, i32 40>, <2 x i32> <i32 42, i32 42>
176 define i32 @test67(i16 %x) {
177 ; CHECK-LABEL: @test67(
178 ; CHECK-NEXT: [[TMP1:%.*]] = and i16 [[X:%.*]], 4
179 ; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i16 [[TMP1]], 0
180 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[TMP2]], i32 42, i32 40
181 ; CHECK-NEXT: ret i32 [[TMP3]]
184 %2 = icmp ne i16 %1, 0
185 %3 = select i1 %2, i32 40, i32 42
189 define <2 x i32> @test67vec(<2 x i16> %x) {
190 ; CHECK-LABEL: @test67vec(
191 ; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i16> [[X:%.*]], <i16 4, i16 4>
192 ; CHECK-NEXT: [[TMP2:%.*]] = icmp eq <2 x i16> [[TMP1]], zeroinitializer
193 ; CHECK-NEXT: [[TMP3:%.*]] = select <2 x i1> [[TMP2]], <2 x i32> <i32 42, i32 42>, <2 x i32> <i32 40, i32 40>
194 ; CHECK-NEXT: ret <2 x i32> [[TMP3]]
196 %1 = and <2 x i16> %x, <i16 4, i16 4>
197 %2 = icmp ne <2 x i16> %1, zeroinitializer
198 %3 = select <2 x i1> %2, <2 x i32> <i32 40, i32 40>, <2 x i32> <i32 42, i32 42>
202 define i32 @test71(i32 %x) {
203 ; CHECK-LABEL: @test71(
204 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], 128
205 ; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i32 [[TMP1]], 0
206 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[TMP2]], i32 42, i32 40
207 ; CHECK-NEXT: ret i32 [[TMP3]]
210 %2 = icmp ne i32 %1, 0
211 %3 = select i1 %2, i32 40, i32 42
215 define <2 x i32> @test71vec(<2 x i32> %x) {
216 ; CHECK-LABEL: @test71vec(
217 ; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i32> [[X:%.*]], <i32 128, i32 128>
218 ; CHECK-NEXT: [[TMP2:%.*]] = icmp eq <2 x i32> [[TMP1]], zeroinitializer
219 ; CHECK-NEXT: [[TMP3:%.*]] = select <2 x i1> [[TMP2]], <2 x i32> <i32 42, i32 42>, <2 x i32> <i32 40, i32 40>
220 ; CHECK-NEXT: ret <2 x i32> [[TMP3]]
222 %1 = and <2 x i32> %x, <i32 128, i32 128>
223 %2 = icmp ne <2 x i32> %1, <i32 0, i32 0>
224 %3 = select <2 x i1> %2, <2 x i32> <i32 40, i32 40>, <2 x i32> <i32 42, i32 42>
228 define i32 @test72(i32 %x) {
229 ; CHECK-LABEL: @test72(
230 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], 128
231 ; CHECK-NEXT: [[TMP2:%.*]] = icmp eq i32 [[TMP1]], 0
232 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[TMP2]], i32 40, i32 42
233 ; CHECK-NEXT: ret i32 [[TMP3]]
236 %2 = icmp eq i32 %1, 0
237 %3 = select i1 %2, i32 40, i32 42
241 define <2 x i32> @test72vec(<2 x i32> %x) {
242 ; CHECK-LABEL: @test72vec(
243 ; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i32> [[X:%.*]], <i32 128, i32 128>
244 ; CHECK-NEXT: [[TMP2:%.*]] = icmp eq <2 x i32> [[TMP1]], zeroinitializer
245 ; CHECK-NEXT: [[TMP3:%.*]] = select <2 x i1> [[TMP2]], <2 x i32> <i32 40, i32 40>, <2 x i32> <i32 42, i32 42>
246 ; CHECK-NEXT: ret <2 x i32> [[TMP3]]
248 %1 = and <2 x i32> %x, <i32 128, i32 128>
249 %2 = icmp eq <2 x i32> %1, <i32 0, i32 0>
250 %3 = select <2 x i1> %2, <2 x i32> <i32 40, i32 40>, <2 x i32> <i32 42, i32 42>
254 define i32 @test73(i32 %x) {
255 ; CHECK-LABEL: @test73(
256 ; CHECK-NEXT: [[TMP1:%.*]] = trunc i32 [[X:%.*]] to i8
257 ; CHECK-NEXT: [[TMP2:%.*]] = icmp sgt i8 [[TMP1]], -1
258 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[TMP2]], i32 40, i32 42
259 ; CHECK-NEXT: ret i32 [[TMP3]]
261 %1 = trunc i32 %x to i8
262 %2 = icmp sgt i8 %1, -1
263 %3 = select i1 %2, i32 40, i32 42
267 define <2 x i32> @test73vec(<2 x i32> %x) {
268 ; CHECK-LABEL: @test73vec(
269 ; CHECK-NEXT: [[TMP1:%.*]] = trunc <2 x i32> [[X:%.*]] to <2 x i8>
270 ; CHECK-NEXT: [[TMP2:%.*]] = icmp sgt <2 x i8> [[TMP1]], <i8 -1, i8 -1>
271 ; CHECK-NEXT: [[TMP3:%.*]] = select <2 x i1> [[TMP2]], <2 x i32> <i32 40, i32 40>, <2 x i32> <i32 42, i32 42>
272 ; CHECK-NEXT: ret <2 x i32> [[TMP3]]
274 %1 = trunc <2 x i32> %x to <2 x i8>
275 %2 = icmp sgt <2 x i8> %1, <i8 -1, i8 -1>
276 %3 = select <2 x i1> %2, <2 x i32> <i32 40, i32 40>, <2 x i32> <i32 42, i32 42>
280 define i32 @test74(i32 %x) {
281 ; CHECK-LABEL: @test74(
282 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i32 [[X:%.*]], -1
283 ; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[TMP1]], i32 40, i32 42
284 ; CHECK-NEXT: ret i32 [[TMP2]]
286 %1 = icmp sgt i32 %x, -1
287 %2 = select i1 %1, i32 40, i32 42
291 define <2 x i32> @test74vec(<2 x i32> %x) {
292 ; CHECK-LABEL: @test74vec(
293 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt <2 x i32> [[X:%.*]], <i32 -1, i32 -1>
294 ; CHECK-NEXT: [[TMP2:%.*]] = select <2 x i1> [[TMP1]], <2 x i32> <i32 40, i32 40>, <2 x i32> <i32 42, i32 42>
295 ; CHECK-NEXT: ret <2 x i32> [[TMP2]]
297 %1 = icmp sgt <2 x i32> %x, <i32 -1, i32 -1>
298 %2 = select <2 x i1> %1, <2 x i32> <i32 40, i32 40>, <2 x i32> <i32 42, i32 42>
302 ;; Code sequence for (X & 16) ? 16 : 0
303 define i32 @test15a(i32 %X) {
304 ; CHECK-LABEL: @test15a(
305 ; CHECK-NEXT: [[T1:%.*]] = and i32 [[X:%.*]], 16
306 ; CHECK-NEXT: ret i32 [[T1]]
309 %t2 = icmp eq i32 %t1, 0
310 %t3 = select i1 %t2, i32 0, i32 16
314 ;; Code sequence for (X & 32) ? 0 : 24
315 define i32 @test15b(i32 %X) {
316 ; CHECK-LABEL: @test15b(
317 ; CHECK-NEXT: [[T1:%.*]] = and i32 [[X:%.*]], 32
318 ; CHECK-NEXT: [[TMP1:%.*]] = xor i32 [[T1]], 32
319 ; CHECK-NEXT: ret i32 [[TMP1]]
322 %t2 = icmp eq i32 %t1, 0
323 %t3 = select i1 %t2, i32 32, i32 0
327 ;; Alternate code sequence for (X & 16) ? 16 : 0
328 define i32 @test15c(i32 %X) {
329 ; CHECK-LABEL: @test15c(
330 ; CHECK-NEXT: [[T1:%.*]] = and i32 [[X:%.*]], 16
331 ; CHECK-NEXT: ret i32 [[T1]]
334 %t2 = icmp eq i32 %t1, 16
335 %t3 = select i1 %t2, i32 16, i32 0
339 ;; Alternate code sequence for (X & 16) ? 16 : 0
340 define i32 @test15d(i32 %X) {
341 ; CHECK-LABEL: @test15d(
342 ; CHECK-NEXT: [[T1:%.*]] = and i32 [[X:%.*]], 16
343 ; CHECK-NEXT: ret i32 [[T1]]
346 %t2 = icmp ne i32 %t1, 0
347 %t3 = select i1 %t2, i32 16, i32 0
351 ;; (a & 128) ? 256 : 0
352 define i32 @test15e(i32 %X) {
353 ; CHECK-LABEL: @test15e(
354 ; CHECK-NEXT: [[T1:%.*]] = shl i32 [[X:%.*]], 1
355 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[T1]], 256
356 ; CHECK-NEXT: ret i32 [[TMP1]]
358 %t1 = and i32 %X, 128
359 %t2 = icmp ne i32 %t1, 0
360 %t3 = select i1 %t2, i32 256, i32 0
364 ;; (a & 128) ? 0 : 256
365 define i32 @test15f(i32 %X) {
366 ; CHECK-LABEL: @test15f(
367 ; CHECK-NEXT: [[T1:%.*]] = shl i32 [[X:%.*]], 1
368 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[T1]], 256
369 ; CHECK-NEXT: [[TMP2:%.*]] = xor i32 [[TMP1]], 256
370 ; CHECK-NEXT: ret i32 [[TMP2]]
372 %t1 = and i32 %X, 128
373 %t2 = icmp ne i32 %t1, 0
374 %t3 = select i1 %t2, i32 0, i32 256
379 define i32 @test15g(i32 %X) {
380 ; CHECK-LABEL: @test15g(
381 ; CHECK-NEXT: [[TMP1:%.*]] = or i32 [[X:%.*]], -9
382 ; CHECK-NEXT: ret i32 [[TMP1]]
385 %t2 = icmp ne i32 %t1, 0
386 %t3 = select i1 %t2, i32 -1, i32 -9
391 define i32 @test15h(i32 %X) {
392 ; CHECK-LABEL: @test15h(
393 ; CHECK-NEXT: [[T1:%.*]] = and i32 [[X:%.*]], 8
394 ; CHECK-NEXT: [[TMP1:%.*]] = xor i32 [[T1]], -1
395 ; CHECK-NEXT: ret i32 [[TMP1]]
398 %t2 = icmp ne i32 %t1, 0
399 %t3 = select i1 %t2, i32 -9, i32 -1
403 ;; (a & 2) ? 577 : 1089
404 define i32 @test15i(i32 %X) {
405 ; CHECK-LABEL: @test15i(
406 ; CHECK-NEXT: [[T1:%.*]] = and i32 [[X:%.*]], 2
407 ; CHECK-NEXT: [[T2:%.*]] = icmp eq i32 [[T1]], 0
408 ; CHECK-NEXT: [[T3:%.*]] = select i1 [[T2]], i32 1089, i32 577
409 ; CHECK-NEXT: ret i32 [[T3]]
412 %t2 = icmp ne i32 %t1, 0
413 %t3 = select i1 %t2, i32 577, i32 1089
417 ;; (a & 2) ? 1089 : 577
418 define i32 @test15j(i32 %X) {
419 ; CHECK-LABEL: @test15j(
420 ; CHECK-NEXT: [[T1:%.*]] = and i32 [[X:%.*]], 2
421 ; CHECK-NEXT: [[T2:%.*]] = icmp eq i32 [[T1]], 0
422 ; CHECK-NEXT: [[T3:%.*]] = select i1 [[T2]], i32 577, i32 1089
423 ; CHECK-NEXT: ret i32 [[T3]]
426 %t2 = icmp ne i32 %t1, 0
427 %t3 = select i1 %t2, i32 1089, i32 577
431 declare void @use1(i1)
433 ; (X & 8) == 0 ? -3 : -11 --> (X & 8) ^ -3
434 ; Extra cmp use ensures that cmp predicate canonicalization is thwarted.
436 define i32 @clear_to_set(i32 %x) {
437 ; CHECK-LABEL: @clear_to_set(
438 ; CHECK-NEXT: [[T1:%.*]] = and i32 [[X:%.*]], 8
439 ; CHECK-NEXT: [[T2:%.*]] = icmp eq i32 [[T1]], 0
440 ; CHECK-NEXT: [[TMP1:%.*]] = xor i32 [[T1]], -3
441 ; CHECK-NEXT: call void @use1(i1 [[T2]])
442 ; CHECK-NEXT: ret i32 [[TMP1]]
445 %t2 = icmp eq i32 %t1, 0
446 %t3 = select i1 %t2, i32 -3, i32 -11
447 call void @use1(i1 %t2)
451 ; (X & 8) == 0 ? -11 : -3 --> (X & 8) | -11
452 ; Extra cmp use ensures that cmp predicate canonicalization is thwarted.
454 define i32 @clear_to_clear(i32 %x) {
455 ; CHECK-LABEL: @clear_to_clear(
456 ; CHECK-NEXT: [[T1:%.*]] = and i32 [[X:%.*]], 8
457 ; CHECK-NEXT: [[T2:%.*]] = icmp eq i32 [[T1]], 0
458 ; CHECK-NEXT: [[TMP1:%.*]] = or i32 [[T1]], -11
459 ; CHECK-NEXT: call void @use1(i1 [[T2]])
460 ; CHECK-NEXT: ret i32 [[TMP1]]
463 %t2 = icmp eq i32 %t1, 0
464 %t3 = select i1 %t2, i32 -11, i32 -3
465 call void @use1(i1 %t2)
469 ; (X & 8) != 0 ? -3 : -11 --> (X & 8) | -11
470 ; Extra cmp use ensures that cmp predicate canonicalization is thwarted.
472 define i32 @set_to_set(i32 %x) {
473 ; CHECK-LABEL: @set_to_set(
474 ; CHECK-NEXT: [[T1:%.*]] = and i32 [[X:%.*]], 8
475 ; CHECK-NEXT: [[T2:%.*]] = icmp ne i32 [[T1]], 0
476 ; CHECK-NEXT: [[TMP1:%.*]] = or i32 [[T1]], -11
477 ; CHECK-NEXT: call void @use1(i1 [[T2]])
478 ; CHECK-NEXT: ret i32 [[TMP1]]
481 %t2 = icmp ne i32 %t1, 0
482 %t3 = select i1 %t2, i32 -3, i32 -11
483 call void @use1(i1 %t2)
487 ; (X & 8) != 0 ? -3 : -11 --> (X & 8) ^ -3
488 ; Extra cmp use ensures that cmp predicate canonicalization is thwarted.
490 define i32 @set_to_clear(i32 %x) {
491 ; CHECK-LABEL: @set_to_clear(
492 ; CHECK-NEXT: [[T1:%.*]] = and i32 [[X:%.*]], 8
493 ; CHECK-NEXT: [[T2:%.*]] = icmp ne i32 [[T1]], 0
494 ; CHECK-NEXT: [[TMP1:%.*]] = xor i32 [[T1]], -3
495 ; CHECK-NEXT: call void @use1(i1 [[T2]])
496 ; CHECK-NEXT: ret i32 [[TMP1]]
499 %t2 = icmp ne i32 %t1, 0
500 %t3 = select i1 %t2, i32 -11, i32 -3
501 call void @use1(i1 %t2)
505 ; (X & 128) == 0 ? 131 : 3 --> (X & 128) ^ 131
507 define i8 @clear_to_set_decomposebittest(i8 %x) {
508 ; CHECK-LABEL: @clear_to_set_decomposebittest(
509 ; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[X:%.*]], -128
510 ; CHECK-NEXT: [[TMP2:%.*]] = xor i8 [[TMP1]], -125
511 ; CHECK-NEXT: ret i8 [[TMP2]]
513 %t2 = icmp sgt i8 %x, -1
514 %t3 = select i1 %t2, i8 131, i8 3
518 ; (X & 128) == 0 ? 3 : 131 --> (X & 128) | 3
520 define i8 @clear_to_clear_decomposebittest(i8 %x) {
521 ; CHECK-LABEL: @clear_to_clear_decomposebittest(
522 ; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[X:%.*]], -128
523 ; CHECK-NEXT: [[TMP2:%.*]] = or i8 [[TMP1]], 3
524 ; CHECK-NEXT: ret i8 [[TMP2]]
526 %t2 = icmp sgt i8 %x, -1
527 %t3 = select i1 %t2, i8 3, i8 131
531 ; (X & 128) != 0 ? 131 : 3 --> (X & 128) | 3
533 define i8 @set_to_set_decomposebittest(i8 %x) {
534 ; CHECK-LABEL: @set_to_set_decomposebittest(
535 ; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[X:%.*]], -128
536 ; CHECK-NEXT: [[TMP2:%.*]] = or i8 [[TMP1]], 3
537 ; CHECK-NEXT: ret i8 [[TMP2]]
539 %t2 = icmp slt i8 %x, 0
540 %t3 = select i1 %t2, i8 131, i8 3
544 ; (X & 128) != 0 ? 3 : 131 --> (X & 128) ^ 131
546 define i8 @set_to_clear_decomposebittest(i8 %x) {
547 ; CHECK-LABEL: @set_to_clear_decomposebittest(
548 ; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[X:%.*]], -128
549 ; CHECK-NEXT: [[TMP2:%.*]] = xor i8 [[TMP1]], -125
550 ; CHECK-NEXT: ret i8 [[TMP2]]
552 %t2 = icmp slt i8 %x, 0
553 %t3 = select i1 %t2, i8 3, i8 131
557 ; (X & 128) == 0 ? 131 : 3 --> (X & 128) ^ 131
558 ; Extra cmp use to verify that we are not creating extra instructions.
560 define i8 @clear_to_set_decomposebittest_extra_use(i8 %x) {
561 ; CHECK-LABEL: @clear_to_set_decomposebittest_extra_use(
562 ; CHECK-NEXT: [[T2:%.*]] = icmp sgt i8 [[X:%.*]], -1
563 ; CHECK-NEXT: [[T3:%.*]] = select i1 [[T2]], i8 -125, i8 3
564 ; CHECK-NEXT: call void @use1(i1 [[T2]])
565 ; CHECK-NEXT: ret i8 [[T3]]
567 %t2 = icmp sgt i8 %x, -1
568 %t3 = select i1 %t2, i8 131, i8 3
569 call void @use1(i1 %t2)
573 ; (X & 128) == 0 ? 3 : 131 --> (X & 128) | 3
574 ; Extra cmp use to verify that we are not creating extra instructions.
576 define i8 @clear_to_clear_decomposebittest_extra_use(i8 %x) {
577 ; CHECK-LABEL: @clear_to_clear_decomposebittest_extra_use(
578 ; CHECK-NEXT: [[T2:%.*]] = icmp sgt i8 [[X:%.*]], -1
579 ; CHECK-NEXT: [[T3:%.*]] = select i1 [[T2]], i8 3, i8 -125
580 ; CHECK-NEXT: call void @use1(i1 [[T2]])
581 ; CHECK-NEXT: ret i8 [[T3]]
583 %t2 = icmp sgt i8 %x, -1
584 %t3 = select i1 %t2, i8 3, i8 131
585 call void @use1(i1 %t2)
589 ; (X & 128) != 0 ? 131 : 3 --> (X & 128) | 3
590 ; Extra cmp use to verify that we are not creating extra instructions.
592 define i8 @set_to_set_decomposebittest_extra_use(i8 %x) {
593 ; CHECK-LABEL: @set_to_set_decomposebittest_extra_use(
594 ; CHECK-NEXT: [[T2:%.*]] = icmp slt i8 [[X:%.*]], 0
595 ; CHECK-NEXT: [[T3:%.*]] = select i1 [[T2]], i8 -125, i8 3
596 ; CHECK-NEXT: call void @use1(i1 [[T2]])
597 ; CHECK-NEXT: ret i8 [[T3]]
599 %t2 = icmp slt i8 %x, 0
600 %t3 = select i1 %t2, i8 131, i8 3
601 call void @use1(i1 %t2)
605 ; (X & 128) != 0 ? 3 : 131 --> (X & 128) ^ 131
606 ; Extra cmp use to verify that we are not creating extra instructions.
608 define i8 @set_to_clear_decomposebittest_extra_use(i8 %x) {
609 ; CHECK-LABEL: @set_to_clear_decomposebittest_extra_use(
610 ; CHECK-NEXT: [[T2:%.*]] = icmp slt i8 [[X:%.*]], 0
611 ; CHECK-NEXT: [[T3:%.*]] = select i1 [[T2]], i8 3, i8 -125
612 ; CHECK-NEXT: call void @use1(i1 [[T2]])
613 ; CHECK-NEXT: ret i8 [[T3]]
615 %t2 = icmp slt i8 %x, 0
616 %t3 = select i1 %t2, i8 3, i8 131
617 call void @use1(i1 %t2)