1 ; RUN: opt < %s -instcombine -S | FileCheck %s
2 ; This test makes sure that these instructions are properly eliminated.
5 target datalayout = "e-p:64:64-p1:16:16-p2:32:32:32-p3:64:64:64"
7 define i32 @test1(i32 %A, i32 %B) {
8 %C = select i1 false, i32 %A, i32 %B
10 ; CHECK-LABEL: @test1(
14 define i32 @test2(i32 %A, i32 %B) {
15 %C = select i1 true, i32 %A, i32 %B
17 ; CHECK-LABEL: @test2(
22 define i32 @test3(i1 %C, i32 %I) {
24 %V = select i1 %C, i32 %I, i32 %I
26 ; CHECK-LABEL: @test3(
30 define i1 @test4(i1 %C) {
32 %V = select i1 %C, i1 true, i1 false
34 ; CHECK-LABEL: @test4(
38 define i1 @test5(i1 %C) {
40 %V = select i1 %C, i1 false, i1 true
42 ; CHECK-LABEL: @test5(
43 ; CHECK: xor i1 %C, true
47 define i32 @test6(i1 %C) {
49 %V = select i1 %C, i32 1, i32 0
51 ; CHECK-LABEL: @test6(
52 ; CHECK: %V = zext i1 %C to i32
56 define i1 @test7(i1 %C, i1 %X) {
58 %R = select i1 %C, i1 true, i1 %X
60 ; CHECK-LABEL: @test7(
61 ; CHECK: %R = or i1 %C, %X
65 define i1 @test8(i1 %C, i1 %X) {
67 %R = select i1 %C, i1 %X, i1 false
69 ; CHECK-LABEL: @test8(
70 ; CHECK: %R = and i1 %C, %X
74 define i1 @test9(i1 %C, i1 %X) {
76 %R = select i1 %C, i1 false, i1 %X
78 ; CHECK-LABEL: @test9(
79 ; CHECK: xor i1 %C, true
84 define i1 @test10(i1 %C, i1 %X) {
86 %R = select i1 %C, i1 %X, i1 true
88 ; CHECK-LABEL: @test10(
89 ; CHECK: xor i1 %C, true
94 define i32 @test11(i32 %a) {
95 %C = icmp eq i32 %a, 0
96 %R = select i1 %C, i32 0, i32 1
98 ; CHECK-LABEL: @test11(
99 ; CHECK: icmp ne i32 %a, 0
100 ; CHECK: %R = zext i1
104 define i32 @test12(i1 %cond, i32 %a) {
106 %c = select i1 %cond, i32 %b, i32 %a
108 ; CHECK-LABEL: @test12(
109 ; CHECK: %b = zext i1 %cond to i32
110 ; CHECK: %c = or i32 %b, %a
114 define i32 @test12a(i1 %cond, i32 %a) {
116 %c = select i1 %cond, i32 %b, i32 %a
118 ; CHECK-LABEL: @test12a(
119 ; CHECK: %b = zext i1 %cond to i32
120 ; CHECK: %c = ashr i32 %a, %b
124 define i32 @test12b(i1 %cond, i32 %a) {
126 %c = select i1 %cond, i32 %a, i32 %b
128 ; CHECK-LABEL: @test12b(
129 ; CHECK: zext i1 %cond to i32
130 ; CHECK: %b = xor i32
131 ; CHECK: %c = ashr i32 %a, %b
135 define i32 @test13(i32 %a, i32 %b) {
136 %C = icmp eq i32 %a, %b
137 %V = select i1 %C, i32 %a, i32 %b
139 ; CHECK-LABEL: @test13(
143 define i32 @test13a(i32 %a, i32 %b) {
144 %C = icmp ne i32 %a, %b
145 %V = select i1 %C, i32 %a, i32 %b
147 ; CHECK-LABEL: @test13a(
151 define i32 @test13b(i32 %a, i32 %b) {
152 %C = icmp eq i32 %a, %b
153 %V = select i1 %C, i32 %b, i32 %a
155 ; CHECK-LABEL: @test13b(
159 define i1 @test14a(i1 %C, i32 %X) {
160 %V = select i1 %C, i32 %X, i32 0
162 %R = icmp slt i32 %V, 1
164 ; CHECK-LABEL: @test14a(
165 ; CHECK: icmp slt i32 %X, 1
166 ; CHECK: xor i1 %C, true
171 define i1 @test14b(i1 %C, i32 %X) {
172 %V = select i1 %C, i32 0, i32 %X
174 %R = icmp slt i32 %V, 1
176 ; CHECK-LABEL: @test14b(
177 ; CHECK: icmp slt i32 %X, 1
182 ;; Code sequence for (X & 16) ? 16 : 0
183 define i32 @test15a(i32 %X) {
185 %t2 = icmp eq i32 %t1, 0
186 %t3 = select i1 %t2, i32 0, i32 16
188 ; CHECK-LABEL: @test15a(
189 ; CHECK: %t1 = and i32 %X, 16
193 ;; Code sequence for (X & 32) ? 0 : 24
194 define i32 @test15b(i32 %X) {
196 %t2 = icmp eq i32 %t1, 0
197 %t3 = select i1 %t2, i32 32, i32 0
199 ; CHECK-LABEL: @test15b(
200 ; CHECK: %t1 = and i32 %X, 32
201 ; CHECK: xor i32 %t1, 32
205 ;; Alternate code sequence for (X & 16) ? 16 : 0
206 define i32 @test15c(i32 %X) {
208 %t2 = icmp eq i32 %t1, 16
209 %t3 = select i1 %t2, i32 16, i32 0
211 ; CHECK-LABEL: @test15c(
212 ; CHECK: %t1 = and i32 %X, 16
216 ;; Alternate code sequence for (X & 16) ? 16 : 0
217 define i32 @test15d(i32 %X) {
219 %t2 = icmp ne i32 %t1, 0
220 %t3 = select i1 %t2, i32 16, i32 0
222 ; CHECK-LABEL: @test15d(
223 ; CHECK: %t1 = and i32 %X, 16
227 ;; (a & 128) ? 256 : 0
228 define i32 @test15e(i32 %X) {
229 %t1 = and i32 %X, 128
230 %t2 = icmp ne i32 %t1, 0
231 %t3 = select i1 %t2, i32 256, i32 0
233 ; CHECK-LABEL: @test15e(
234 ; CHECK: %t1 = shl i32 %X, 1
235 ; CHECK: and i32 %t1, 256
239 ;; (a & 128) ? 0 : 256
240 define i32 @test15f(i32 %X) {
241 %t1 = and i32 %X, 128
242 %t2 = icmp ne i32 %t1, 0
243 %t3 = select i1 %t2, i32 0, i32 256
245 ; CHECK-LABEL: @test15f(
246 ; CHECK: %t1 = shl i32 %X, 1
247 ; CHECK: and i32 %t1, 256
248 ; CHECK: xor i32 %{{.*}}, 256
253 define i32 @test15g(i32 %X) {
255 %t2 = icmp ne i32 %t1, 0
256 %t3 = select i1 %t2, i32 -1, i32 -9
258 ; CHECK-LABEL: @test15g(
259 ; CHECK-NEXT: %1 = or i32 %X, -9
260 ; CHECK-NEXT: ret i32 %1
264 define i32 @test15h(i32 %X) {
266 %t2 = icmp ne i32 %t1, 0
267 %t3 = select i1 %t2, i32 -9, i32 -1
269 ; CHECK-LABEL: @test15h(
270 ; CHECK-NEXT: %1 = or i32 %X, -9
271 ; CHECK-NEXT: %2 = xor i32 %1, 8
272 ; CHECK-NEXT: ret i32 %2
275 ;; (a & 2) ? 577 : 1089
276 define i32 @test15i(i32 %X) {
278 %t2 = icmp ne i32 %t1, 0
279 %t3 = select i1 %t2, i32 577, i32 1089
281 ; CHECK-LABEL: @test15i(
282 ; CHECK-NEXT: %t1 = shl i32 %X, 8
283 ; CHECK-NEXT: %1 = and i32 %t1, 512
284 ; CHECK-NEXT: %2 = xor i32 %1, 512
285 ; CHECK-NEXT: %3 = add nuw nsw i32 %2, 577
286 ; CHECK-NEXT: ret i32 %3
289 ;; (a & 2) ? 1089 : 577
290 define i32 @test15j(i32 %X) {
292 %t2 = icmp ne i32 %t1, 0
293 %t3 = select i1 %t2, i32 1089, i32 577
295 ; CHECK-LABEL: @test15j(
296 ; CHECK-NEXT: %t1 = shl i32 %X, 8
297 ; CHECK-NEXT: %1 = and i32 %t1, 512
298 ; CHECK-NEXT: %2 = add nuw nsw i32 %1, 577
299 ; CHECK-NEXT: ret i32 %2
302 define i32 @test16(i1 %C, i32* %P) {
303 %P2 = select i1 %C, i32* %P, i32* null
306 ; CHECK-LABEL: @test16(
307 ; CHECK-NEXT: %V = load i32* %P
311 define i1 @test17(i32* %X, i1 %C) {
312 %R = select i1 %C, i32* %X, i32* null
313 %RV = icmp eq i32* %R, null
315 ; CHECK-LABEL: @test17(
316 ; CHECK: icmp eq i32* %X, null
317 ; CHECK: xor i1 %C, true
322 define i32 @test18(i32 %X, i32 %Y, i1 %C) {
323 %R = select i1 %C, i32 %X, i32 0
326 ; CHECK-LABEL: @test18(
327 ; CHECK: %V = sdiv i32 %Y, %X
331 define i32 @test19(i32 %x) {
332 %tmp = icmp ugt i32 %x, 2147483647
333 %retval = select i1 %tmp, i32 -1, i32 0
335 ; CHECK-LABEL: @test19(
336 ; CHECK-NEXT: ashr i32 %x, 31
337 ; CHECK-NEXT: ret i32
340 define i32 @test20(i32 %x) {
341 %tmp = icmp slt i32 %x, 0
342 %retval = select i1 %tmp, i32 -1, i32 0
344 ; CHECK-LABEL: @test20(
345 ; CHECK-NEXT: ashr i32 %x, 31
346 ; CHECK-NEXT: ret i32
349 define i64 @test21(i32 %x) {
350 %tmp = icmp slt i32 %x, 0
351 %retval = select i1 %tmp, i64 -1, i64 0
353 ; CHECK-LABEL: @test21(
354 ; CHECK-NEXT: ashr i32 %x, 31
355 ; CHECK-NEXT: sext i32
356 ; CHECK-NEXT: ret i64
359 define i16 @test22(i32 %x) {
360 %tmp = icmp slt i32 %x, 0
361 %retval = select i1 %tmp, i16 -1, i16 0
363 ; CHECK-LABEL: @test22(
364 ; CHECK-NEXT: ashr i32 %x, 31
365 ; CHECK-NEXT: trunc i32
366 ; CHECK-NEXT: ret i16
369 define i1 @test23(i1 %a, i1 %b) {
370 %c = select i1 %a, i1 %b, i1 %a
372 ; CHECK-LABEL: @test23(
373 ; CHECK-NEXT: %c = and i1 %a, %b
374 ; CHECK-NEXT: ret i1 %c
377 define i1 @test24(i1 %a, i1 %b) {
378 %c = select i1 %a, i1 %a, i1 %b
380 ; CHECK-LABEL: @test24(
381 ; CHECK-NEXT: %c = or i1 %a, %b
382 ; CHECK-NEXT: ret i1 %c
385 define i32 @test25(i1 %c) {
387 br i1 %c, label %jump, label %ret
391 %a = phi i1 [true, %jump], [false, %entry]
392 %b = select i1 %a, i32 10, i32 20
394 ; CHECK-LABEL: @test25(
395 ; CHECK: %a = phi i32 [ 10, %jump ], [ 20, %entry ]
396 ; CHECK-NEXT: ret i32 %a
399 define i32 @test26(i1 %cond) {
401 br i1 %cond, label %jump, label %ret
403 %c = or i1 false, false
406 %a = phi i1 [true, %jump], [%c, %entry]
407 %b = select i1 %a, i32 10, i32 20
409 ; CHECK-LABEL: @test26(
410 ; CHECK: %a = phi i32 [ 10, %jump ], [ 20, %entry ]
411 ; CHECK-NEXT: ret i32 %a
414 define i32 @test27(i1 %c, i32 %A, i32 %B) {
416 br i1 %c, label %jump, label %ret
420 %a = phi i1 [true, %jump], [false, %entry]
421 %b = select i1 %a, i32 %A, i32 %B
423 ; CHECK-LABEL: @test27(
424 ; CHECK: %a = phi i32 [ %A, %jump ], [ %B, %entry ]
425 ; CHECK-NEXT: ret i32 %a
428 define i32 @test28(i1 %cond, i32 %A, i32 %B) {
430 br i1 %cond, label %jump, label %ret
434 %c = phi i32 [%A, %jump], [%B, %entry]
435 %a = phi i1 [true, %jump], [false, %entry]
436 %b = select i1 %a, i32 %A, i32 %c
438 ; CHECK-LABEL: @test28(
439 ; CHECK: %a = phi i32 [ %A, %jump ], [ %B, %entry ]
440 ; CHECK-NEXT: ret i32 %a
443 define i32 @test29(i1 %cond, i32 %A, i32 %B) {
445 br i1 %cond, label %jump, label %ret
449 %c = phi i32 [%A, %jump], [%B, %entry]
450 %a = phi i1 [true, %jump], [false, %entry]
454 %b = select i1 %a, i32 %A, i32 %c
456 ; CHECK-LABEL: @test29(
457 ; CHECK: %a = phi i32 [ %A, %jump ], [ %B, %entry ]
462 ; SMAX(SMAX(x, y), x) -> SMAX(x, y)
463 define i32 @test30(i32 %x, i32 %y) {
464 %cmp = icmp sgt i32 %x, %y
465 %cond = select i1 %cmp, i32 %x, i32 %y
467 %cmp5 = icmp sgt i32 %cond, %x
468 %retval = select i1 %cmp5, i32 %cond, i32 %x
470 ; CHECK-LABEL: @test30(
471 ; CHECK: ret i32 %cond
474 ; UMAX(UMAX(x, y), x) -> UMAX(x, y)
475 define i32 @test31(i32 %x, i32 %y) {
476 %cmp = icmp ugt i32 %x, %y
477 %cond = select i1 %cmp, i32 %x, i32 %y
478 %cmp5 = icmp ugt i32 %cond, %x
479 %retval = select i1 %cmp5, i32 %cond, i32 %x
481 ; CHECK-LABEL: @test31(
482 ; CHECK: ret i32 %cond
485 ; SMIN(SMIN(x, y), x) -> SMIN(x, y)
486 define i32 @test32(i32 %x, i32 %y) {
487 %cmp = icmp sgt i32 %x, %y
488 %cond = select i1 %cmp, i32 %y, i32 %x
489 %cmp5 = icmp sgt i32 %cond, %x
490 %retval = select i1 %cmp5, i32 %x, i32 %cond
492 ; CHECK-LABEL: @test32(
493 ; CHECK: ret i32 %cond
496 ; MAX(MIN(x, y), x) -> x
497 define i32 @test33(i32 %x, i32 %y) {
498 %cmp = icmp sgt i32 %x, %y
499 %cond = select i1 %cmp, i32 %y, i32 %x
500 %cmp5 = icmp sgt i32 %cond, %x
501 %retval = select i1 %cmp5, i32 %cond, i32 %x
503 ; CHECK-LABEL: @test33(
507 ; MIN(MAX(x, y), x) -> x
508 define i32 @test34(i32 %x, i32 %y) {
509 %cmp = icmp sgt i32 %x, %y
510 %cond = select i1 %cmp, i32 %x, i32 %y
511 %cmp5 = icmp sgt i32 %cond, %x
512 %retval = select i1 %cmp5, i32 %x, i32 %cond
514 ; CHECK-LABEL: @test34(
518 define i32 @test35(i32 %x) {
519 %cmp = icmp sge i32 %x, 0
520 %cond = select i1 %cmp, i32 60, i32 100
522 ; CHECK-LABEL: @test35(
523 ; CHECK: ashr i32 %x, 31
524 ; CHECK: and i32 {{.*}}, 40
525 ; CHECK: add nuw nsw i32 {{.*}}, 60
529 define i32 @test36(i32 %x) {
530 %cmp = icmp slt i32 %x, 0
531 %cond = select i1 %cmp, i32 60, i32 100
533 ; CHECK-LABEL: @test36(
534 ; CHECK: ashr i32 %x, 31
535 ; CHECK: and i32 {{.*}}, -40
536 ; CHECK: add nsw i32 {{.*}}, 100
540 define i32 @test37(i32 %x) {
541 %cmp = icmp sgt i32 %x, -1
542 %cond = select i1 %cmp, i32 1, i32 -1
544 ; CHECK-LABEL: @test37(
545 ; CHECK: ashr i32 %x, 31
546 ; CHECK: or i32 {{.*}}, 1
550 define i1 @test38(i1 %cond) {
553 %ptr = select i1 %cond, i32* %zero, i32* %one
554 %isnull = icmp eq i32* %ptr, null
556 ; CHECK-LABEL: @test38(
557 ; CHECK: ret i1 false
560 define i1 @test39(i1 %cond, double %x) {
561 %s = select i1 %cond, double %x, double 0x7FF0000000000000 ; RHS = +infty
562 %cmp = fcmp ule double %x, %s
564 ; CHECK-LABEL: @test39(
568 define i1 @test40(i1 %cond) {
572 %s = select i1 %cond, i32* %a, i32* %b
573 %r = icmp eq i32* %s, %c
575 ; CHECK-LABEL: @test40(
576 ; CHECK: ret i1 false
579 define i32 @test41(i1 %cond, i32 %x, i32 %y) {
581 %s = select i1 %cond, i32 %y, i32 %z
584 ; CHECK-LABEL: @test41(
585 ; CHECK-NEXT: and i32 %x, %y
586 ; CHECK-NEXT: ret i32
589 define i32 @test42(i32 %x, i32 %y) {
591 %cond = icmp eq i32 %x, 0
592 %c = select i1 %cond, i32 %b, i32 %y
594 ; CHECK-LABEL: @test42(
595 ; CHECK-NEXT: %cond = icmp eq i32 %x, 0
596 ; CHECK-NEXT: %b = sext i1 %cond to i32
597 ; CHECK-NEXT: %c = add i32 %b, %y
598 ; CHECK-NEXT: ret i32 %c
601 define i64 @test43(i32 %a) nounwind {
602 %a_ext = sext i32 %a to i64
603 %is_a_nonnegative = icmp sgt i32 %a, -1
604 %max = select i1 %is_a_nonnegative, i64 %a_ext, i64 0
606 ; CHECK-LABEL: @test43(
607 ; CHECK-NEXT: %a_ext = sext i32 %a to i64
608 ; CHECK-NEXT: %is_a_nonnegative = icmp slt i64 %a_ext, 0
609 ; CHECK-NEXT: %max = select i1 %is_a_nonnegative, i64 0, i64 %a_ext
610 ; CHECK-NEXT: ret i64 %max
613 define i64 @test44(i32 %a) nounwind {
614 %a_ext = sext i32 %a to i64
615 %is_a_nonpositive = icmp slt i32 %a, 1
616 %min = select i1 %is_a_nonpositive, i64 %a_ext, i64 0
618 ; CHECK-LABEL: @test44(
619 ; CHECK-NEXT: %a_ext = sext i32 %a to i64
620 ; CHECK-NEXT: %is_a_nonpositive = icmp sgt i64 %a_ext, 0
621 ; CHECK-NEXT: %min = select i1 %is_a_nonpositive, i64 0, i64 %a_ext
622 ; CHECK-NEXT: ret i64 %min
624 define i64 @test45(i32 %a) nounwind {
625 %a_ext = zext i32 %a to i64
626 %is_a_nonnegative = icmp ugt i32 %a, 2
627 %max = select i1 %is_a_nonnegative, i64 %a_ext, i64 3
629 ; CHECK-LABEL: @test45(
630 ; CHECK-NEXT: %a_ext = zext i32 %a to i64
631 ; CHECK-NEXT: %is_a_nonnegative = icmp ult i64 %a_ext, 3
632 ; CHECK-NEXT: %max = select i1 %is_a_nonnegative, i64 3, i64 %a_ext
633 ; CHECK-NEXT: ret i64 %max
636 define i64 @test46(i32 %a) nounwind {
637 %a_ext = zext i32 %a to i64
638 %is_a_nonpositive = icmp ult i32 %a, 3
639 %min = select i1 %is_a_nonpositive, i64 %a_ext, i64 2
641 ; CHECK-LABEL: @test46(
642 ; CHECK-NEXT: %a_ext = zext i32 %a to i64
643 ; CHECK-NEXT: %is_a_nonpositive = icmp ugt i64 %a_ext, 2
644 ; CHECK-NEXT: %min = select i1 %is_a_nonpositive, i64 2, i64 %a_ext
645 ; CHECK-NEXT: ret i64 %min
647 define i64 @test47(i32 %a) nounwind {
648 %a_ext = sext i32 %a to i64
649 %is_a_nonnegative = icmp ugt i32 %a, 2
650 %max = select i1 %is_a_nonnegative, i64 %a_ext, i64 3
652 ; CHECK-LABEL: @test47(
653 ; CHECK-NEXT: %a_ext = sext i32 %a to i64
654 ; CHECK-NEXT: %is_a_nonnegative = icmp ult i64 %a_ext, 3
655 ; CHECK-NEXT: %max = select i1 %is_a_nonnegative, i64 3, i64 %a_ext
656 ; CHECK-NEXT: ret i64 %max
659 define i64 @test48(i32 %a) nounwind {
660 %a_ext = sext i32 %a to i64
661 %is_a_nonpositive = icmp ult i32 %a, 3
662 %min = select i1 %is_a_nonpositive, i64 %a_ext, i64 2
664 ; CHECK-LABEL: @test48(
665 ; CHECK-NEXT: %a_ext = sext i32 %a to i64
666 ; CHECK-NEXT: %is_a_nonpositive = icmp ugt i64 %a_ext, 2
667 ; CHECK-NEXT: %min = select i1 %is_a_nonpositive, i64 2, i64 %a_ext
668 ; CHECK-NEXT: ret i64 %min
671 define i64 @test49(i32 %a) nounwind {
672 %a_ext = sext i32 %a to i64
673 %is_a_nonpositive = icmp ult i32 %a, 3
674 %min = select i1 %is_a_nonpositive, i64 2, i64 %a_ext
676 ; CHECK-LABEL: @test49(
677 ; CHECK-NEXT: %a_ext = sext i32 %a to i64
678 ; CHECK-NEXT: %is_a_nonpositive = icmp ugt i64 %a_ext, 2
679 ; CHECK-NEXT: %min = select i1 %is_a_nonpositive, i64 %a_ext, i64 2
680 ; CHECK-NEXT: ret i64 %min
682 define i64 @test50(i32 %a) nounwind {
683 %is_a_nonpositive = icmp ult i32 %a, 3
684 %a_ext = sext i32 %a to i64
685 %min = select i1 %is_a_nonpositive, i64 2, i64 %a_ext
687 ; CHECK-LABEL: @test50(
688 ; CHECK-NEXT: %a_ext = sext i32 %a to i64
689 ; CHECK-NEXT: %is_a_nonpositive = icmp ugt i64 %a_ext, 2
690 ; CHECK-NEXT: %min = select i1 %is_a_nonpositive, i64 %a_ext, i64 2
691 ; CHECK-NEXT: ret i64 %min
696 ; This select instruction can't be eliminated because trying to do so would
697 ; change the number of vector elements. This used to assert.
698 define i48 @test51(<3 x i1> %icmp, <3 x i16> %tmp) {
699 ; CHECK-LABEL: @test51(
700 %select = select <3 x i1> %icmp, <3 x i16> zeroinitializer, <3 x i16> %tmp
701 ; CHECK: select <3 x i1>
702 %tmp2 = bitcast <3 x i16> %select to i48
708 define i32 @test52(i32 %n, i32 %m) nounwind {
709 ; CHECK-LABEL: @test52(
710 %cmp = icmp sgt i32 %n, %m
711 %. = select i1 %cmp, i32 1, i32 3
712 %add = add nsw i32 %., 3
713 %storemerge = select i1 %cmp, i32 %., i32 %add
714 ; CHECK: select i1 %cmp, i32 1, i32 6
719 define i32 @test53(i32 %x) nounwind {
721 %cmp = icmp eq i32 %and, %x
722 %sel = select i1 %cmp, i32 2, i32 1
724 ; CHECK-LABEL: @test53(
725 ; CHECK: select i1 %cmp
729 define i32 @test54(i32 %X, i32 %Y) {
730 %A = ashr exact i32 %X, %Y
731 %B = icmp eq i32 %A, 0
732 %C = select i1 %B, i32 %A, i32 1
734 ; CHECK-LABEL: @test54(
737 ; CHECK: icmp ne i32 %X, 0
742 define i1 @test55(i1 %X, i32 %Y, i32 %Z) {
743 %A = ashr exact i32 %Y, %Z
744 %B = select i1 %X, i32 %Y, i32 %A
745 %C = icmp eq i32 %B, 0
747 ; CHECK-LABEL: @test55(
754 define i32 @test56(i16 %x) nounwind {
755 %tobool = icmp eq i16 %x, 0
756 %conv = zext i16 %x to i32
757 %cond = select i1 %tobool, i32 0, i32 %conv
759 ; CHECK-LABEL: @test56(
764 define i32 @test57(i32 %x, i32 %y) nounwind {
765 %and = and i32 %x, %y
766 %tobool = icmp eq i32 %x, 0
767 %.and = select i1 %tobool, i32 0, i32 %and
769 ; CHECK-LABEL: @test57(
770 ; CHECK-NEXT: and i32 %x, %y
774 define i32 @test58(i16 %x) nounwind {
775 %tobool = icmp ne i16 %x, 1
776 %conv = zext i16 %x to i32
777 %cond = select i1 %tobool, i32 %conv, i32 1
779 ; CHECK-LABEL: @test58(
784 define i32 @test59(i32 %x, i32 %y) nounwind {
785 %and = and i32 %x, %y
786 %tobool = icmp ne i32 %x, %y
787 %.and = select i1 %tobool, i32 %and, i32 %y
789 ; CHECK-LABEL: @test59(
790 ; CHECK-NEXT: and i32 %x, %y
794 define i1 @test60(i32 %x, i1* %y) nounwind {
795 %cmp = icmp eq i32 %x, 0
796 %load = load i1* %y, align 1
797 %cmp1 = icmp slt i32 %x, 1
798 %sel = select i1 %cmp, i1 %load, i1 %cmp1
800 ; CHECK-LABEL: @test60(
804 @glbl = constant i32 10
805 define i32 @test61(i32* %ptr) {
807 %B = icmp eq i32* %ptr, @glbl
808 %C = select i1 %B, i32 %A, i32 10
810 ; CHECK-LABEL: @test61(
814 define i1 @test62(i1 %A, i1 %B) {
815 %not = xor i1 %A, true
816 %C = select i1 %A, i1 %not, i1 %B
818 ; CHECK-LABEL: @test62(
819 ; CHECK: %not = xor i1 %A, true
820 ; CHECK: %C = and i1 %not, %B
824 define i1 @test63(i1 %A, i1 %B) {
825 %not = xor i1 %A, true
826 %C = select i1 %A, i1 %B, i1 %not
828 ; CHECK-LABEL: @test63(
829 ; CHECK: %not = xor i1 %A, true
830 ; CHECK: %C = or i1 %B, %not
835 define void @test64(i32 %p, i16 %b) noreturn nounwind {
837 %p.addr.0.insert.mask = and i32 %p, -65536
838 %conv2 = and i32 %p, 65535
839 br i1 undef, label %lor.rhs, label %lor.end
842 %p.addr.0.extract.trunc = trunc i32 %p.addr.0.insert.mask to i16
843 %phitmp = zext i16 %p.addr.0.extract.trunc to i32
847 %t.1 = phi i32 [ 0, %entry ], [ %phitmp, %lor.rhs ]
848 %conv6 = zext i16 %b to i32
849 %div = udiv i32 %conv6, %t.1
850 %tobool8 = icmp eq i32 %div, 0
851 %cmp = icmp eq i32 %t.1, 0
852 %cmp12 = icmp ult i32 %conv2, 2
853 %cmp.sink = select i1 %tobool8, i1 %cmp12, i1 %cmp
854 br i1 %cmp.sink, label %cond.end17, label %cond.false16
864 ; CHECK-LABEL: @test64(
868 ; CHECK-LABEL: @select_icmp_eq_and_1_0_or_2(
869 ; CHECK-NEXT: [[SHL:%[a-z0-9]+]] = shl i32 %x, 1
870 ; CHECK-NEXT: [[AND:%[a-z0-9]+]] = and i32 [[SHL]], 2
871 ; CHECK-NEXT: [[OR:%[a-z0-9]+]] = or i32 [[AND]], %y
872 ; CHECK-NEXT: ret i32 [[OR]]
873 define i32 @select_icmp_eq_and_1_0_or_2(i32 %x, i32 %y) {
875 %cmp = icmp eq i32 %and, 0
877 %select = select i1 %cmp, i32 %y, i32 %or
881 ; CHECK-LABEL: @select_icmp_eq_and_32_0_or_8(
882 ; CHECK-NEXT: [[LSHR:%[a-z0-9]+]] = lshr i32 %x, 2
883 ; CHECK-NEXT: [[AND:%[a-z0-9]+]] = and i32 [[LSHR]], 8
884 ; CHECK-NEXT: [[OR:%[a-z0-9]+]] = or i32 [[AND]], %y
885 ; CHECK-NEXT: ret i32 [[OR]]
886 define i32 @select_icmp_eq_and_32_0_or_8(i32 %x, i32 %y) {
887 %and = and i32 %x, 32
888 %cmp = icmp eq i32 %and, 0
890 %select = select i1 %cmp, i32 %y, i32 %or
894 ; CHECK-LABEL: @select_icmp_ne_0_and_4096_or_4096(
895 ; CHECK-NEXT: [[AND:%[a-z0-9]+]] = and i32 %x, 4096
896 ; CHECK-NEXT: [[XOR:%[a-z0-9]+]] = xor i32 [[AND]], 4096
897 ; CHECK-NEXT: [[OR:%[a-z0-9]+]] = or i32 [[XOR]], %y
898 ; CHECK-NEXT: ret i32 [[OR]]
899 define i32 @select_icmp_ne_0_and_4096_or_4096(i32 %x, i32 %y) {
900 %and = and i32 %x, 4096
901 %cmp = icmp ne i32 0, %and
902 %or = or i32 %y, 4096
903 %select = select i1 %cmp, i32 %y, i32 %or
907 ; CHECK-LABEL: @select_icmp_eq_and_4096_0_or_4096(
908 ; CHECK-NEXT: [[AND:%[a-z0-9]+]] = and i32 %x, 4096
909 ; CHECK-NEXT: [[OR:%[a-z0-9]+]] = or i32 [[AND]], %y
910 ; CHECK-NEXT: ret i32 [[OR]]
911 define i32 @select_icmp_eq_and_4096_0_or_4096(i32 %x, i32 %y) {
912 %and = and i32 %x, 4096
913 %cmp = icmp eq i32 %and, 0
914 %or = or i32 %y, 4096
915 %select = select i1 %cmp, i32 %y, i32 %or
919 ; CHECK-LABEL: @select_icmp_eq_0_and_1_or_1(
920 ; CHECK-NEXT: [[TRUNC:%.+]] = trunc i64 %x to i32
921 ; CHECK-NEXT: [[AND:%.+]] = and i32 [[TRUNC]], 1
922 ; CHECK-NEXT: [[OR:%.+]] = or i32 [[XOR]], %y
923 ; CHECK-NEXT: ret i32 [[OR]]
924 define i32 @select_icmp_eq_0_and_1_or_1(i64 %x, i32 %y) {
926 %cmp = icmp eq i64 %and, 0
928 %select = select i1 %cmp, i32 %y, i32 %or
932 ; CHECK-LABEL: @select_icmp_ne_0_and_4096_or_32(
933 ; CHECK-NEXT: [[LSHR:%[a-z0-9]+]] = lshr i32 %x, 7
934 ; CHECK-NEXT: [[AND:%[a-z0-9]+]] = and i32 [[LSHR]], 32
935 ; CHECK-NEXT: [[XOR:%[a-z0-9]+]] = xor i32 [[AND]], 32
936 ; CHECK-NEXT: [[OR:%[a-z0-9]+]] = or i32 [[XOR]], %y
937 ; CHECK-NEXT: ret i32 [[OR]]
938 define i32 @select_icmp_ne_0_and_4096_or_32(i32 %x, i32 %y) {
939 %and = and i32 %x, 4096
940 %cmp = icmp ne i32 0, %and
942 %select = select i1 %cmp, i32 %y, i32 %or
946 ; CHECK-LABEL: @select_icmp_ne_0_and_32_or_4096(
947 ; CHECK-NEXT: [[SHL:%[a-z0-9]+]] = shl i32 %x, 7
948 ; CHECK-NEXT: [[AND:%[a-z0-9]+]] = and i32 [[SHL]], 4096
949 ; CHECK-NEXT: [[XOR:%[a-z0-9]+]] = xor i32 [[AND]], 4096
950 ; CHECK-NEXT: [[OR:%[a-z0-9]+]] = or i32 [[XOR]], %y
951 ; CHECK-NEXT: ret i32 [[OR]]
952 define i32 @select_icmp_ne_0_and_32_or_4096(i32 %x, i32 %y) {
953 %and = and i32 %x, 32
954 %cmp = icmp ne i32 0, %and
955 %or = or i32 %y, 4096
956 %select = select i1 %cmp, i32 %y, i32 %or
960 ; CHECK-LABEL: @select_icmp_ne_0_and_1073741824_or_8(
961 ; CHECK-NEXT: [[LSHR:%.+]] = lshr i32 %x, 27
962 ; CHECK-NEXT: [[TRUNC:%.+]] = trunc i32 [[LSHR]] to i8
963 ; CHECK-NEXT: [[AND:%.+]] = and i8 [[TRUNC]], 8
964 ; CHECK-NEXT: [[XOR:%.+]] = xor i8 [[AND]], 8
965 ; CHECK-NEXT: [[OR:%.+]] = or i8 [[XOR]], %y
966 ; CHECK-NEXT: ret i8 [[OR]]
967 define i8 @select_icmp_ne_0_and_1073741824_or_8(i32 %x, i8 %y) {
968 %and = and i32 %x, 1073741824
969 %cmp = icmp ne i32 0, %and
971 %select = select i1 %cmp, i8 %y, i8 %or
975 ; CHECK-LABEL: @select_icmp_ne_0_and_8_or_1073741824(
976 ; CHECK-NEXT: [[AND:%[a-z0-9]+]] = and i8 %x, 8
977 ; CHECK-NEXT: [[ZEXT:%[a-z0-9]+]] = zext i8 [[AND]] to i32
978 ; CHECK-NEXT: [[SHL:%[a-z0-9]+]] = shl nuw nsw i32 [[ZEXT]], 27
979 ; CHECK-NEXT: [[XOR:%[a-z0-9]+]] = xor i32 [[SHL]], 1073741824
980 ; CHECK-NEXT: [[OR:%[a-z0-9]+]] = or i32 [[XOR]], %y
981 ; CHECK-NEXT: ret i32 [[OR]]
982 define i32 @select_icmp_ne_0_and_8_or_1073741824(i8 %x, i32 %y) {
984 %cmp = icmp ne i8 0, %and
985 %or = or i32 %y, 1073741824
986 %select = select i1 %cmp, i32 %y, i32 %or
990 ; We can't combine here, because the cmp is scalar and the or vector.
991 ; Just make sure we don't assert.
992 define <2 x i32> @select_icmp_eq_and_1_0_or_vector_of_2s(i32 %x, <2 x i32> %y) {
994 %cmp = icmp eq i32 %and, 0
995 %or = or <2 x i32> %y, <i32 2, i32 2>
996 %select = select i1 %cmp, <2 x i32> %y, <2 x i32> %or
997 ret <2 x i32> %select
1000 ; CHECK-LABEL: @select_icmp_and_8_eq_0_or_8(
1001 ; CHECK-NEXT: [[OR:%[a-z0-9]+]] = or i32 %x, 8
1002 ; CHECK-NEXT: ret i32 [[OR]]
1003 define i32 @select_icmp_and_8_eq_0_or_8(i32 %x) {
1004 %and = and i32 %x, 8
1005 %cmp = icmp eq i32 %and, 0
1007 %or.x = select i1 %cmp, i32 %or, i32 %x
1011 ; CHECK-LABEL: @select_icmp_and_8_ne_0_xor_8(
1012 ; CHECK-NEXT: [[AND:%[a-z0-9]+]] = and i32 %x, -9
1013 ; CHECK-NEXT: ret i32 [[AND]]
1014 define i32 @select_icmp_and_8_ne_0_xor_8(i32 %x) {
1015 %and = and i32 %x, 8
1016 %cmp = icmp eq i32 %and, 0
1017 %xor = xor i32 %x, 8
1018 %x.xor = select i1 %cmp, i32 %x, i32 %xor
1022 ; CHECK-LABEL: @select_icmp_and_8_eq_0_xor_8(
1023 ; CHECK-NEXT: [[OR:%[a-z0-9]+]] = or i32 %x, 8
1024 ; CHECK-NEXT: ret i32 [[OR]]
1025 define i32 @select_icmp_and_8_eq_0_xor_8(i32 %x) {
1026 %and = and i32 %x, 8
1027 %cmp = icmp eq i32 %and, 0
1028 %xor = xor i32 %x, 8
1029 %xor.x = select i1 %cmp, i32 %xor, i32 %x
1033 ; CHECK-LABEL: @select_icmp_and_8_ne_0_and_not_8(
1034 ; CHECK-NEXT: [[AND:%[a-z0-9]+]] = and i32 %x, -9
1035 ; CHECK-NEXT: ret i32 [[AND]]
1036 define i32 @select_icmp_and_8_ne_0_and_not_8(i32 %x) {
1037 %and = and i32 %x, 8
1038 %cmp = icmp eq i32 %and, 0
1039 %and1 = and i32 %x, -9
1040 %x.and1 = select i1 %cmp, i32 %x, i32 %and1
1044 ; CHECK-LABEL: @select_icmp_and_8_eq_0_and_not_8(
1045 ; CHECK-NEXT: ret i32 %x
1046 define i32 @select_icmp_and_8_eq_0_and_not_8(i32 %x) {
1047 %and = and i32 %x, 8
1048 %cmp = icmp eq i32 %and, 0
1049 %and1 = and i32 %x, -9
1050 %and1.x = select i1 %cmp, i32 %and1, i32 %x
1054 ; CHECK-LABEL: @select_icmp_x_and_8_eq_0_y_xor_8(
1055 ; CHECK: select i1 %cmp, i64 %y, i64 %xor
1056 define i64 @select_icmp_x_and_8_eq_0_y_xor_8(i32 %x, i64 %y) {
1057 %and = and i32 %x, 8
1058 %cmp = icmp eq i32 %and, 0
1059 %xor = xor i64 %y, 8
1060 %y.xor = select i1 %cmp, i64 %y, i64 %xor
1064 ; CHECK-LABEL: @select_icmp_x_and_8_eq_0_y_and_not_8(
1065 ; CHECK: select i1 %cmp, i64 %y, i64 %and1
1066 define i64 @select_icmp_x_and_8_eq_0_y_and_not_8(i32 %x, i64 %y) {
1067 %and = and i32 %x, 8
1068 %cmp = icmp eq i32 %and, 0
1069 %and1 = and i64 %y, -9
1070 %y.and1 = select i1 %cmp, i64 %y, i64 %and1
1074 ; CHECK-LABEL: @select_icmp_x_and_8_ne_0_y_xor_8(
1075 ; CHECK: select i1 %cmp, i64 %xor, i64 %y
1076 define i64 @select_icmp_x_and_8_ne_0_y_xor_8(i32 %x, i64 %y) {
1077 %and = and i32 %x, 8
1078 %cmp = icmp eq i32 %and, 0
1079 %xor = xor i64 %y, 8
1080 %xor.y = select i1 %cmp, i64 %xor, i64 %y
1084 ; CHECK-LABEL: @select_icmp_x_and_8_ne_0_y_and_not_8(
1085 ; CHECK: select i1 %cmp, i64 %and1, i64 %y
1086 define i64 @select_icmp_x_and_8_ne_0_y_and_not_8(i32 %x, i64 %y) {
1087 %and = and i32 %x, 8
1088 %cmp = icmp eq i32 %and, 0
1089 %and1 = and i64 %y, -9
1090 %and1.y = select i1 %cmp, i64 %and1, i64 %y
1094 ; CHECK-LABEL: @select_icmp_x_and_8_ne_0_y_or_8(
1095 ; CHECK: xor i64 %1, 8
1096 ; CHECK: or i64 %2, %y
1097 define i64 @select_icmp_x_and_8_ne_0_y_or_8(i32 %x, i64 %y) {
1098 %and = and i32 %x, 8
1099 %cmp = icmp eq i32 %and, 0
1101 %or.y = select i1 %cmp, i64 %or, i64 %y
1105 define i32 @test65(i64 %x) {
1107 %2 = icmp ne i64 %1, 0
1108 %3 = select i1 %2, i32 40, i32 42
1111 ; CHECK-LABEL: @test65(
1112 ; CHECK: %[[TRUNC:.*]] = trunc i64 %x to i32
1113 ; CHECK: %[[LSHR:.*]] = lshr i32 %[[TRUNC]], 3
1114 ; CHECK: %[[AND:.*]] = and i32 %[[LSHR]], 2
1115 ; CHECK: %[[XOR:.*]] = xor i32 %[[AND]], 42
1116 ; CHECK: ret i32 %[[XOR]]
1119 define i32 @test66(i64 %x) {
1120 %1 = and i64 %x, 4294967296
1121 %2 = icmp ne i64 %1, 0
1122 %3 = select i1 %2, i32 40, i32 42
1125 ; CHECK-LABEL: @test66(
1129 define i32 @test67(i16 %x) {
1131 %2 = icmp ne i16 %1, 0
1132 %3 = select i1 %2, i32 40, i32 42
1135 ; CHECK-LABEL: @test67(
1136 ; CHECK: and i16 %x, 4
1137 ; CHECK: zext i16 %1 to i32
1138 ; CHECK: lshr exact i32 %2, 1
1139 ; CHECK: xor i32 %3, 42
1142 ; SMIN(SMIN(X, 11), 92) -> SMIN(X, 11)
1143 define i32 @test68(i32 %x) {
1145 %cmp = icmp slt i32 11, %x
1146 %cond = select i1 %cmp, i32 11, i32 %x
1147 %cmp3 = icmp slt i32 92, %cond
1148 %retval = select i1 %cmp3, i32 92, i32 %cond
1150 ; CHECK-LABEL: @test68(
1151 ; CHECK: ret i32 %cond
1154 ; MIN(MIN(X, 24), 83) -> MIN(X, 24)
1155 define i32 @test69(i32 %x) {
1157 %cmp = icmp ult i32 24, %x
1158 %cond = select i1 %cmp, i32 24, i32 %x
1159 %cmp3 = icmp ult i32 83, %cond
1160 %retval = select i1 %cmp3, i32 83, i32 %cond
1162 ; CHECK-LABEL: @test69(
1163 ; CHECK: ret i32 %cond
1166 ; SMAX(SMAX(X, 75), 36) -> SMAX(X, 75)
1167 define i32 @test70(i32 %x) {
1169 %cmp = icmp slt i32 %x, 75
1170 %cond = select i1 %cmp, i32 75, i32 %x
1171 %cmp3 = icmp slt i32 %cond, 36
1172 %retval = select i1 %cmp3, i32 36, i32 %cond
1174 ; CHECK-LABEL: @test70(
1175 ; CHECK: ret i32 %cond
1178 ; MAX(MAX(X, 68), 47) -> MAX(X, 68)
1179 define i32 @test71(i32 %x) {
1181 %cmp = icmp ult i32 %x, 68
1182 %cond = select i1 %cmp, i32 68, i32 %x
1183 %cmp3 = icmp ult i32 %cond, 47
1184 %retval = select i1 %cmp3, i32 47, i32 %cond
1186 ; CHECK-LABEL: @test71(
1187 ; CHECK: ret i32 %cond
1190 ; SMIN(SMIN(X, 92), 11) -> SMIN(X, 11)
1191 define i32 @test72(i32 %x) {
1192 %cmp = icmp sgt i32 %x, 92
1193 %cond = select i1 %cmp, i32 92, i32 %x
1194 %cmp3 = icmp sgt i32 %cond, 11
1195 %retval = select i1 %cmp3, i32 11, i32 %cond
1197 ; CHECK-LABEL: @test72(
1198 ; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp sgt i32 %x, 11
1199 ; CHECK-NEXT: [[SEL:%[a-z0-9]+]] = select i1 [[CMP]], i32 11, i32 %x
1200 ; CHECK-NEXT: ret i32 [[SEL]]
1203 ; MIN(MIN(X, 83), 24) -> MIN(X, 24)
1204 define i32 @test73(i32 %x) {
1205 %cmp = icmp ugt i32 %x, 83
1206 %cond = select i1 %cmp, i32 83, i32 %x
1207 %cmp3 = icmp ugt i32 %cond, 24
1208 %retval = select i1 %cmp3, i32 24, i32 %cond
1210 ; CHECK-LABEL: @test73(
1211 ; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp ugt i32 %x, 24
1212 ; CHECK-NEXT: [[SEL:%[a-z0-9]+]] = select i1 [[CMP]], i32 24, i32 %x
1213 ; CHECK-NEXT: ret i32 [[SEL]]
1216 ; SMAX(SMAX(X, 36), 75) -> SMAX(X, 75)
1217 define i32 @test74(i32 %x) {
1218 %cmp = icmp slt i32 %x, 36
1219 %cond = select i1 %cmp, i32 36, i32 %x
1220 %cmp3 = icmp slt i32 %cond, 75
1221 %retval = select i1 %cmp3, i32 75, i32 %cond
1223 ; CHECK-LABEL: @test74(
1224 ; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp slt i32 %x, 75
1225 ; CHECK-NEXT: [[SEL:%[a-z0-9]+]] = select i1 [[CMP]], i32 75, i32 %x
1226 ; CHECK-NEXT: ret i32 [[SEL]]
1229 ; MAX(MAX(X, 47), 68) -> MAX(X, 68)
1230 define i32 @test75(i32 %x) {
1231 %cmp = icmp ult i32 %x, 47
1232 %cond = select i1 %cmp, i32 47, i32 %x
1233 %cmp3 = icmp ult i32 %cond, 68
1234 %retval = select i1 %cmp3, i32 68, i32 %cond
1236 ; CHECK-LABEL: @test75(
1237 ; CHECK-NEXT: [[CMP:%[a-z0-9]+]] = icmp ult i32 %x, 68
1238 ; CHECK-NEXT: [[SEL:%[a-z0-9]+]] = select i1 [[CMP]], i32 68, i32 %x
1239 ; CHECK-NEXT: ret i32 [[SEL]]
1242 @under_aligned = external global i32, align 1
1244 define i32 @test76(i1 %flag, i32* %x) {
1245 ; The load here must not be speculated around the select. One side of the
1246 ; select is trivially dereferencable but may have a lower alignment than the
1248 ; CHECK-LABEL: @test76(
1249 ; CHECK: store i32 0, i32* %x
1250 ; CHECK: %[[P:.*]] = select i1 %flag, i32* @under_aligned, i32* %x
1251 ; CHECK: load i32* %[[P]]
1253 store i32 0, i32* %x
1254 %p = select i1 %flag, i32* @under_aligned, i32* %x
1259 declare void @scribble_on_i32(i32*)
1261 define i32 @test77(i1 %flag, i32* %x) {
1262 ; The load here must not be speculated around the select. One side of the
1263 ; select is trivially dereferencable but may have a lower alignment than the
1265 ; CHECK-LABEL: @test77(
1266 ; CHECK: %[[A:.*]] = alloca i32, align 1
1267 ; CHECK: call void @scribble_on_i32(i32* %[[A]])
1268 ; CHECK: store i32 0, i32* %x
1269 ; CHECK: %[[P:.*]] = select i1 %flag, i32* %[[A]], i32* %x
1270 ; CHECK: load i32* %[[P]]
1272 %under_aligned = alloca i32, align 1
1273 call void @scribble_on_i32(i32* %under_aligned)
1274 store i32 0, i32* %x
1275 %p = select i1 %flag, i32* %under_aligned, i32* %x
1280 define i32 @test78(i1 %flag, i32* %x, i32* %y, i32* %z) {
1281 ; Test that we can speculate the loads around the select even when we can't
1282 ; fold the load completely away.
1283 ; CHECK-LABEL: @test78(
1284 ; CHECK: %[[V1:.*]] = load i32* %x
1285 ; CHECK-NEXT: %[[V2:.*]] = load i32* %y
1286 ; CHECK-NEXT: %[[S:.*]] = select i1 %flag, i32 %[[V1]], i32 %[[V2]]
1287 ; CHECK-NEXT: ret i32 %[[S]]
1289 store i32 0, i32* %x
1290 store i32 0, i32* %y
1291 ; Block forwarding by storing to %z which could alias either %x or %y.
1292 store i32 42, i32* %z
1293 %p = select i1 %flag, i32* %x, i32* %y
1298 define float @test79(i1 %flag, float* %x, i32* %y, i32* %z) {
1299 ; Test that we can speculate the loads around the select even when we can't
1300 ; fold the load completely away.
1301 ; CHECK-LABEL: @test79(
1302 ; CHECK: %[[V1:.*]] = load float* %x
1303 ; CHECK-NEXT: %[[V2:.*]] = load float* %y
1304 ; CHECK-NEXT: %[[S:.*]] = select i1 %flag, float %[[V1]], float %[[V2]]
1305 ; CHECK-NEXT: ret float %[[S]]
1307 %x1 = bitcast float* %x to i32*
1308 %y1 = bitcast i32* %y to float*
1309 store i32 0, i32* %x1
1310 store i32 0, i32* %y
1311 ; Block forwarding by storing to %z which could alias either %x or %y.
1312 store i32 42, i32* %z
1313 %p = select i1 %flag, float* %x, float* %y1
1318 define i32 @test80(i1 %flag) {
1319 ; Test that when we speculate the loads around the select they fold throug
1320 ; load->load folding and load->store folding.
1321 ; CHECK-LABEL: @test80(
1322 ; CHECK: %[[X:.*]] = alloca i32
1323 ; CHECK-NEXT: %[[Y:.*]] = alloca i32
1324 ; CHECK: %[[V:.*]] = load i32* %[[X]]
1325 ; CHECK-NEXT: store i32 %[[V]], i32* %[[Y]]
1326 ; CHECK-NEXT: ret i32 %[[V]]
1330 call void @scribble_on_i32(i32* %x)
1331 call void @scribble_on_i32(i32* %y)
1333 store i32 %tmp, i32* %y
1334 %p = select i1 %flag, i32* %x, i32* %y
1339 define float @test81(i1 %flag) {
1340 ; Test that we can speculate the load around the select even though they use
1341 ; differently typed pointers.
1342 ; CHECK-LABEL: @test81(
1343 ; CHECK: %[[X:.*]] = alloca i32
1344 ; CHECK-NEXT: %[[Y:.*]] = alloca i32
1345 ; CHECK: %[[V:.*]] = load i32* %[[X]]
1346 ; CHECK-NEXT: store i32 %[[V]], i32* %[[Y]]
1347 ; CHECK-NEXT: %[[C:.*]] = bitcast i32 %[[V]] to float
1348 ; CHECK-NEXT: ret float %[[C]]
1352 %x1 = bitcast float* %x to i32*
1353 %y1 = bitcast i32* %y to float*
1354 call void @scribble_on_i32(i32* %x1)
1355 call void @scribble_on_i32(i32* %y)
1356 %tmp = load i32* %x1
1357 store i32 %tmp, i32* %y
1358 %p = select i1 %flag, float* %x, float* %y1
1363 define i32 @test82(i1 %flag) {
1364 ; Test that we can speculate the load around the select even though they use
1365 ; differently typed pointers.
1366 ; CHECK-LABEL: @test82(
1367 ; CHECK: %[[X:.*]] = alloca float
1368 ; CHECK-NEXT: %[[Y:.*]] = alloca i32
1369 ; CHECK-NEXT: %[[X1:.*]] = bitcast float* %[[X]] to i32*
1370 ; CHECK-NEXT: %[[Y1:.*]] = bitcast i32* %[[Y]] to float*
1371 ; CHECK: %[[V:.*]] = load float* %[[X]]
1372 ; CHECK-NEXT: store float %[[V]], float* %[[Y1]]
1373 ; CHECK-NEXT: %[[C:.*]] = bitcast float %[[V]] to i32
1374 ; CHECK-NEXT: ret i32 %[[C]]
1378 %x1 = bitcast float* %x to i32*
1379 %y1 = bitcast i32* %y to float*
1380 call void @scribble_on_i32(i32* %x1)
1381 call void @scribble_on_i32(i32* %y)
1382 %tmp = load float* %x
1383 store float %tmp, float* %y1
1384 %p = select i1 %flag, i32* %x1, i32* %y
1389 declare void @scribble_on_i64(i64*)
1390 declare void @scribble_on_i128(i128*)
1392 define i8* @test83(i1 %flag) {
1393 ; Test that we can speculate the load around the select even though they use
1394 ; differently typed pointers and requires inttoptr casts.
1395 ; CHECK-LABEL: @test83(
1396 ; CHECK: %[[X:.*]] = alloca i8*
1397 ; CHECK-NEXT: %[[Y:.*]] = alloca i8*
1398 ; CHECK-DAG: %[[X2:.*]] = bitcast i8** %[[X]] to i64*
1399 ; CHECK-DAG: %[[Y2:.*]] = bitcast i8** %[[Y]] to i64*
1400 ; CHECK: %[[V:.*]] = load i64* %[[X2]]
1401 ; CHECK-NEXT: store i64 %[[V]], i64* %[[Y2]]
1402 ; CHECK-NEXT: %[[C:.*]] = inttoptr i64 %[[V]] to i8*
1403 ; CHECK-NEXT: ret i8* %[[S]]
1407 %x1 = bitcast i8** %x to i64*
1408 %y1 = bitcast i64* %y to i8**
1409 call void @scribble_on_i64(i64* %x1)
1410 call void @scribble_on_i64(i64* %y)
1411 %tmp = load i64* %x1
1412 store i64 %tmp, i64* %y
1413 %p = select i1 %flag, i8** %x, i8** %y1
1418 define i64 @test84(i1 %flag) {
1419 ; Test that we can speculate the load around the select even though they use
1420 ; differently typed pointers and requires a ptrtoint cast.
1421 ; CHECK-LABEL: @test84(
1422 ; CHECK: %[[X:.*]] = alloca i8*
1423 ; CHECK-NEXT: %[[Y:.*]] = alloca i8*
1424 ; CHECK: %[[V:.*]] = load i8** %[[X]]
1425 ; CHECK-NEXT: store i8* %[[V]], i8** %[[Y]]
1426 ; CHECK-NEXT: %[[C:.*]] = ptrtoint i8* %[[V]] to i64
1427 ; CHECK-NEXT: ret i64 %[[C]]
1431 %x1 = bitcast i8** %x to i64*
1432 %y1 = bitcast i64* %y to i8**
1433 call void @scribble_on_i64(i64* %x1)
1434 call void @scribble_on_i64(i64* %y)
1436 store i8* %tmp, i8** %y1
1437 %p = select i1 %flag, i64* %x1, i64* %y
1442 define i8* @test85(i1 %flag) {
1443 ; Test that we can't speculate the load around the select. The load of the
1444 ; pointer doesn't load all of the stored integer bits. We could fix this, but it
1445 ; would require endianness checks and other nastiness.
1446 ; CHECK-LABEL: @test85(
1447 ; CHECK: %[[T:.*]] = load i128*
1448 ; CHECK-NEXT: store i128 %[[T]], i128*
1449 ; CHECK-NEXT: %[[X:.*]] = load i8**
1450 ; CHECK-NEXT: %[[Y:.*]] = load i8**
1451 ; CHECK-NEXT: %[[V:.*]] = select i1 %flag, i8* %[[X]], i8* %[[Y]]
1452 ; CHECK-NEXT: ret i8* %[[V]]
1454 %x = alloca [2 x i8*]
1456 %x1 = bitcast [2 x i8*]* %x to i8**
1457 %x2 = bitcast i8** %x1 to i128*
1458 %y1 = bitcast i128* %y to i8**
1459 call void @scribble_on_i128(i128* %x2)
1460 call void @scribble_on_i128(i128* %y)
1461 %tmp = load i128* %x2
1462 store i128 %tmp, i128* %y
1463 %p = select i1 %flag, i8** %x1, i8** %y1
1468 define i128 @test86(i1 %flag) {
1469 ; Test that we can't speculate the load around the select when the integer size
1470 ; is larger than the pointer size. The store of the pointer doesn't store to all
1471 ; the bits of the integer.
1473 ; CHECK-LABEL: @test86(
1474 ; CHECK: %[[T:.*]] = load i8**
1475 ; CHECK-NEXT: store i8* %[[T]], i8**
1476 ; CHECK-NEXT: %[[X:.*]] = load i128*
1477 ; CHECK-NEXT: %[[Y:.*]] = load i128*
1478 ; CHECK-NEXT: %[[V:.*]] = select i1 %flag, i128 %[[X]], i128 %[[Y]]
1479 ; CHECK-NEXT: ret i128 %[[V]]
1481 %x = alloca [2 x i8*]
1483 %x1 = bitcast [2 x i8*]* %x to i8**
1484 %x2 = bitcast i8** %x1 to i128*
1485 %y1 = bitcast i128* %y to i8**
1486 call void @scribble_on_i128(i128* %x2)
1487 call void @scribble_on_i128(i128* %y)
1488 %tmp = load i8** %x1
1489 store i8* %tmp, i8** %y1
1490 %p = select i1 %flag, i128* %x2, i128* %y