1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
6 target datalayout = "e-p:64:64-p1:16:16-p2:32:32:32-p3:64:64:64"
8 define i32 @test1(i32 %A, i32 %B) {
10 ; CHECK-NEXT: ret i32 [[B:%.*]]
12 %C = select i1 false, i32 %A, i32 %B
16 define i32 @test2(i32 %A, i32 %B) {
17 ; CHECK-LABEL: @test2(
18 ; CHECK-NEXT: ret i32 [[A:%.*]]
20 %C = select i1 true, i32 %A, i32 %B
25 define i32 @test3(i1 %C, i32 %I) {
26 ; CHECK-LABEL: @test3(
27 ; CHECK-NEXT: ret i32 [[I:%.*]]
29 %V = select i1 %C, i32 %I, i32 %I
33 define i1 @test4(i1 %C) {
34 ; CHECK-LABEL: @test4(
35 ; CHECK-NEXT: ret i1 [[C:%.*]]
37 %V = select i1 %C, i1 true, i1 false
41 define i1 @test5(i1 %C) {
42 ; CHECK-LABEL: @test5(
43 ; CHECK-NEXT: [[NOT_C:%.*]] = xor i1 [[C:%.*]], true
44 ; CHECK-NEXT: ret i1 [[NOT_C]]
46 %V = select i1 %C, i1 false, i1 true
50 define i32 @test6(i1 %C) {
51 ; CHECK-LABEL: @test6(
52 ; CHECK-NEXT: [[V:%.*]] = zext i1 [[C:%.*]] to i32
53 ; CHECK-NEXT: ret i32 [[V]]
55 %V = select i1 %C, i32 1, i32 0
59 define i1 @trueval_is_true(i1 %C, i1 %X) {
60 ; CHECK-LABEL: @trueval_is_true(
61 ; CHECK-NEXT: [[R:%.*]] = or i1 [[C:%.*]], [[X:%.*]]
62 ; CHECK-NEXT: ret i1 [[R]]
64 %R = select i1 %C, i1 true, i1 %X
68 define <2 x i1> @trueval_is_true_vec(<2 x i1> %C, <2 x i1> %X) {
69 ; CHECK-LABEL: @trueval_is_true_vec(
70 ; CHECK-NEXT: [[R:%.*]] = or <2 x i1> [[C:%.*]], [[X:%.*]]
71 ; CHECK-NEXT: ret <2 x i1> [[R]]
73 %R = select <2 x i1> %C, <2 x i1> <i1 true, i1 true>, <2 x i1> %X
77 define <2 x i1> @trueval_is_true_vec_undef_elt(<2 x i1> %C, <2 x i1> %X) {
78 ; CHECK-LABEL: @trueval_is_true_vec_undef_elt(
79 ; CHECK-NEXT: [[R:%.*]] = or <2 x i1> [[C:%.*]], [[X:%.*]]
80 ; CHECK-NEXT: ret <2 x i1> [[R]]
82 %R = select <2 x i1> %C, <2 x i1> <i1 undef, i1 true>, <2 x i1> %X
86 define i1 @test8(i1 %C, i1 %X) {
87 ; CHECK-LABEL: @test8(
88 ; CHECK-NEXT: [[R:%.*]] = and i1 [[C:%.*]], [[X:%.*]]
89 ; CHECK-NEXT: ret i1 [[R]]
91 %R = select i1 %C, i1 %X, i1 false
95 define <2 x i1> @test8vec(<2 x i1> %C, <2 x i1> %X) {
96 ; CHECK-LABEL: @test8vec(
97 ; CHECK-NEXT: [[R:%.*]] = and <2 x i1> [[C:%.*]], [[X:%.*]]
98 ; CHECK-NEXT: ret <2 x i1> [[R]]
100 %R = select <2 x i1> %C, <2 x i1> %X, <2 x i1> <i1 false, i1 false>
104 define i1 @test9(i1 %C, i1 %X) {
105 ; CHECK-LABEL: @test9(
106 ; CHECK-NEXT: [[NOT_C:%.*]] = xor i1 [[C:%.*]], true
107 ; CHECK-NEXT: [[R:%.*]] = and i1 [[NOT_C]], [[X:%.*]]
108 ; CHECK-NEXT: ret i1 [[R]]
110 %R = select i1 %C, i1 false, i1 %X
114 define <2 x i1> @test9vec(<2 x i1> %C, <2 x i1> %X) {
115 ; CHECK-LABEL: @test9vec(
116 ; CHECK-NEXT: [[NOT_C:%.*]] = xor <2 x i1> [[C:%.*]], <i1 true, i1 true>
117 ; CHECK-NEXT: [[R:%.*]] = and <2 x i1> [[NOT_C]], [[X:%.*]]
118 ; CHECK-NEXT: ret <2 x i1> [[R]]
120 %R = select <2 x i1> %C, <2 x i1> <i1 false, i1 false>, <2 x i1> %X
124 define i1 @test10(i1 %C, i1 %X) {
125 ; CHECK-LABEL: @test10(
126 ; CHECK-NEXT: [[NOT_C:%.*]] = xor i1 [[C:%.*]], true
127 ; CHECK-NEXT: [[R:%.*]] = or i1 [[NOT_C]], [[X:%.*]]
128 ; CHECK-NEXT: ret i1 [[R]]
130 %R = select i1 %C, i1 %X, i1 true
134 define <2 x i1> @test10vec(<2 x i1> %C, <2 x i1> %X) {
135 ; CHECK-LABEL: @test10vec(
136 ; CHECK-NEXT: [[NOT_C:%.*]] = xor <2 x i1> [[C:%.*]], <i1 true, i1 true>
137 ; CHECK-NEXT: [[R:%.*]] = or <2 x i1> [[NOT_C]], [[X:%.*]]
138 ; CHECK-NEXT: ret <2 x i1> [[R]]
140 %R = select <2 x i1> %C, <2 x i1> %X, <2 x i1> <i1 true, i1 true>
144 define i1 @test23(i1 %a, i1 %b) {
145 ; CHECK-LABEL: @test23(
146 ; CHECK-NEXT: [[C:%.*]] = and i1 [[A:%.*]], [[B:%.*]]
147 ; CHECK-NEXT: ret i1 [[C]]
149 %c = select i1 %a, i1 %b, i1 %a
153 define <2 x i1> @test23vec(<2 x i1> %a, <2 x i1> %b) {
154 ; CHECK-LABEL: @test23vec(
155 ; CHECK-NEXT: [[C:%.*]] = and <2 x i1> [[A:%.*]], [[B:%.*]]
156 ; CHECK-NEXT: ret <2 x i1> [[C]]
158 %c = select <2 x i1> %a, <2 x i1> %b, <2 x i1> %a
162 define i1 @test24(i1 %a, i1 %b) {
163 ; CHECK-LABEL: @test24(
164 ; CHECK-NEXT: [[C:%.*]] = or i1 [[A:%.*]], [[B:%.*]]
165 ; CHECK-NEXT: ret i1 [[C]]
167 %c = select i1 %a, i1 %a, i1 %b
171 define <2 x i1> @test24vec(<2 x i1> %a, <2 x i1> %b) {
172 ; CHECK-LABEL: @test24vec(
173 ; CHECK-NEXT: [[C:%.*]] = or <2 x i1> [[A:%.*]], [[B:%.*]]
174 ; CHECK-NEXT: ret <2 x i1> [[C]]
176 %c = select <2 x i1> %a, <2 x i1> %a, <2 x i1> %b
180 define i1 @test62(i1 %A, i1 %B) {
181 ; CHECK-LABEL: @test62(
182 ; CHECK-NEXT: [[NOT:%.*]] = xor i1 [[A:%.*]], true
183 ; CHECK-NEXT: [[C:%.*]] = and i1 [[NOT]], [[B:%.*]]
184 ; CHECK-NEXT: ret i1 [[C]]
186 %not = xor i1 %A, true
187 %C = select i1 %A, i1 %not, i1 %B
191 define <2 x i1> @test62vec(<2 x i1> %A, <2 x i1> %B) {
192 ; CHECK-LABEL: @test62vec(
193 ; CHECK-NEXT: [[NOT:%.*]] = xor <2 x i1> [[A:%.*]], <i1 true, i1 true>
194 ; CHECK-NEXT: [[C:%.*]] = and <2 x i1> [[NOT]], [[B:%.*]]
195 ; CHECK-NEXT: ret <2 x i1> [[C]]
197 %not = xor <2 x i1> %A, <i1 true, i1 true>
198 %C = select <2 x i1> %A, <2 x i1> %not, <2 x i1> %B
202 define i1 @test63(i1 %A, i1 %B) {
203 ; CHECK-LABEL: @test63(
204 ; CHECK-NEXT: [[NOT:%.*]] = xor i1 [[A:%.*]], true
205 ; CHECK-NEXT: [[C:%.*]] = or i1 [[NOT]], [[B:%.*]]
206 ; CHECK-NEXT: ret i1 [[C]]
208 %not = xor i1 %A, true
209 %C = select i1 %A, i1 %B, i1 %not
213 define <2 x i1> @test63vec(<2 x i1> %A, <2 x i1> %B) {
214 ; CHECK-LABEL: @test63vec(
215 ; CHECK-NEXT: [[NOT:%.*]] = xor <2 x i1> [[A:%.*]], <i1 true, i1 true>
216 ; CHECK-NEXT: [[C:%.*]] = or <2 x i1> [[NOT]], [[B:%.*]]
217 ; CHECK-NEXT: ret <2 x i1> [[C]]
219 %not = xor <2 x i1> %A, <i1 true, i1 true>
220 %C = select <2 x i1> %A, <2 x i1> %B, <2 x i1> %not
224 define i32 @test11(i32 %a) {
225 ; CHECK-LABEL: @test11(
226 ; CHECK-NEXT: [[C:%.*]] = icmp ne i32 [[A:%.*]], 0
227 ; CHECK-NEXT: [[R:%.*]] = zext i1 [[C]] to i32
228 ; CHECK-NEXT: ret i32 [[R]]
230 %C = icmp eq i32 %a, 0
231 %R = select i1 %C, i32 0, i32 1
235 define i32 @test12(i1 %cond, i32 %a) {
236 ; CHECK-LABEL: @test12(
237 ; CHECK-NEXT: [[B:%.*]] = zext i1 [[COND:%.*]] to i32
238 ; CHECK-NEXT: [[C:%.*]] = or i32 [[B]], [[A:%.*]]
239 ; CHECK-NEXT: ret i32 [[C]]
242 %c = select i1 %cond, i32 %b, i32 %a
246 define <2 x i32> @test12vec(<2 x i1> %cond, <2 x i32> %a) {
247 ; CHECK-LABEL: @test12vec(
248 ; CHECK-NEXT: [[B:%.*]] = zext <2 x i1> [[COND:%.*]] to <2 x i32>
249 ; CHECK-NEXT: [[C:%.*]] = or <2 x i32> [[B]], [[A:%.*]]
250 ; CHECK-NEXT: ret <2 x i32> [[C]]
252 %b = or <2 x i32> %a, <i32 1, i32 1>
253 %c = select <2 x i1> %cond, <2 x i32> %b, <2 x i32> %a
257 define i32 @test12a(i1 %cond, i32 %a) {
258 ; CHECK-LABEL: @test12a(
259 ; CHECK-NEXT: [[B:%.*]] = zext i1 [[COND:%.*]] to i32
260 ; CHECK-NEXT: [[C:%.*]] = ashr i32 [[A:%.*]], [[B]]
261 ; CHECK-NEXT: ret i32 [[C]]
264 %c = select i1 %cond, i32 %b, i32 %a
268 define <2 x i32> @test12avec(<2 x i1> %cond, <2 x i32> %a) {
269 ; CHECK-LABEL: @test12avec(
270 ; CHECK-NEXT: [[B:%.*]] = zext <2 x i1> [[COND:%.*]] to <2 x i32>
271 ; CHECK-NEXT: [[C:%.*]] = ashr <2 x i32> [[A:%.*]], [[B]]
272 ; CHECK-NEXT: ret <2 x i32> [[C]]
274 %b = ashr <2 x i32> %a, <i32 1, i32 1>
275 %c = select <2 x i1> %cond, <2 x i32> %b, <2 x i32> %a
279 define i32 @test12b(i1 %cond, i32 %a) {
280 ; CHECK-LABEL: @test12b(
281 ; CHECK-NEXT: [[NOT_COND:%.*]] = xor i1 [[COND:%.*]], true
282 ; CHECK-NEXT: [[B:%.*]] = zext i1 [[NOT_COND]] to i32
283 ; CHECK-NEXT: [[D:%.*]] = ashr i32 [[A:%.*]], [[B]]
284 ; CHECK-NEXT: ret i32 [[D]]
287 %d = select i1 %cond, i32 %a, i32 %b
291 define <2 x i32> @test12bvec(<2 x i1> %cond, <2 x i32> %a) {
292 ; CHECK-LABEL: @test12bvec(
293 ; CHECK-NEXT: [[NOT_COND:%.*]] = xor <2 x i1> [[COND:%.*]], <i1 true, i1 true>
294 ; CHECK-NEXT: [[B:%.*]] = zext <2 x i1> [[NOT_COND]] to <2 x i32>
295 ; CHECK-NEXT: [[D:%.*]] = ashr <2 x i32> [[A:%.*]], [[B]]
296 ; CHECK-NEXT: ret <2 x i32> [[D]]
298 %b = ashr <2 x i32> %a, <i32 1, i32 1>
299 %d = select <2 x i1> %cond, <2 x i32> %a, <2 x i32> %b
303 define i32 @test13(i32 %a, i32 %b) {
304 ; CHECK-LABEL: @test13(
305 ; CHECK-NEXT: ret i32 [[B:%.*]]
307 %C = icmp eq i32 %a, %b
308 %V = select i1 %C, i32 %a, i32 %b
312 define i32 @test13a(i32 %a, i32 %b) {
313 ; CHECK-LABEL: @test13a(
314 ; CHECK-NEXT: ret i32 [[A:%.*]]
316 %C = icmp ne i32 %a, %b
317 %V = select i1 %C, i32 %a, i32 %b
321 define i32 @test13b(i32 %a, i32 %b) {
322 ; CHECK-LABEL: @test13b(
323 ; CHECK-NEXT: ret i32 [[A:%.*]]
325 %C = icmp eq i32 %a, %b
326 %V = select i1 %C, i32 %b, i32 %a
330 define i1 @test14a(i1 %C, i32 %X) {
331 ; CHECK-LABEL: @test14a(
332 ; CHECK-NEXT: [[R1:%.*]] = icmp slt i32 [[X:%.*]], 1
333 ; CHECK-NEXT: [[NOT_C:%.*]] = xor i1 [[C:%.*]], true
334 ; CHECK-NEXT: [[R:%.*]] = or i1 [[R1]], [[NOT_C]]
335 ; CHECK-NEXT: ret i1 [[R]]
337 %V = select i1 %C, i32 %X, i32 0
339 %R = icmp slt i32 %V, 1
343 define i1 @test14b(i1 %C, i32 %X) {
344 ; CHECK-LABEL: @test14b(
345 ; CHECK-NEXT: [[R1:%.*]] = icmp slt i32 [[X:%.*]], 1
346 ; CHECK-NEXT: [[R:%.*]] = or i1 [[R1]], [[C:%.*]]
347 ; CHECK-NEXT: ret i1 [[R]]
349 %V = select i1 %C, i32 0, i32 %X
351 %R = icmp slt i32 %V, 1
355 define i32 @test16(i1 %C, i32* %P) {
356 ; CHECK-LABEL: @test16(
357 ; CHECK-NEXT: [[V:%.*]] = load i32, i32* [[P:%.*]], align 4
358 ; CHECK-NEXT: ret i32 [[V]]
360 %P2 = select i1 %C, i32* %P, i32* null
361 %V = load i32, i32* %P2
365 ;; It may be legal to load from a null address in a non-zero address space
366 define i32 @test16_neg(i1 %C, i32 addrspace(1)* %P) {
367 ; CHECK-LABEL: @test16_neg(
368 ; CHECK-NEXT: [[P2:%.*]] = select i1 [[C:%.*]], i32 addrspace(1)* [[P:%.*]], i32 addrspace(1)* null
369 ; CHECK-NEXT: [[V:%.*]] = load i32, i32 addrspace(1)* [[P2]], align 4
370 ; CHECK-NEXT: ret i32 [[V]]
372 %P2 = select i1 %C, i32 addrspace(1)* %P, i32 addrspace(1)* null
373 %V = load i32, i32 addrspace(1)* %P2
377 define i32 @test16_neg2(i1 %C, i32 addrspace(1)* %P) {
378 ; CHECK-LABEL: @test16_neg2(
379 ; CHECK-NEXT: [[P2:%.*]] = select i1 [[C:%.*]], i32 addrspace(1)* null, i32 addrspace(1)* [[P:%.*]]
380 ; CHECK-NEXT: [[V:%.*]] = load i32, i32 addrspace(1)* [[P2]], align 4
381 ; CHECK-NEXT: ret i32 [[V]]
383 %P2 = select i1 %C, i32 addrspace(1)* null, i32 addrspace(1)* %P
384 %V = load i32, i32 addrspace(1)* %P2
388 ;; It may be legal to load from a null address with null pointer valid attribute.
389 define i32 @test16_no_null_opt(i1 %C, i32* %P) #0 {
390 ; CHECK-LABEL: @test16_no_null_opt(
391 ; CHECK-NEXT: [[P2:%.*]] = select i1 [[C:%.*]], i32* [[P:%.*]], i32* null
392 ; CHECK-NEXT: [[V:%.*]] = load i32, i32* [[P2]], align 4
393 ; CHECK-NEXT: ret i32 [[V]]
395 %P2 = select i1 %C, i32* %P, i32* null
396 %V = load i32, i32* %P2
400 define i32 @test16_no_null_opt_2(i1 %C, i32* %P) #0 {
401 ; CHECK-LABEL: @test16_no_null_opt_2(
402 ; CHECK-NEXT: [[P2:%.*]] = select i1 [[C:%.*]], i32* null, i32* [[P:%.*]]
403 ; CHECK-NEXT: [[V:%.*]] = load i32, i32* [[P2]], align 4
404 ; CHECK-NEXT: ret i32 [[V]]
406 %P2 = select i1 %C, i32* null, i32* %P
407 %V = load i32, i32* %P2
411 attributes #0 = { "null-pointer-is-valid"="true" }
413 define i1 @test17(i32* %X, i1 %C) {
414 ; CHECK-LABEL: @test17(
415 ; CHECK-NEXT: [[RV1:%.*]] = icmp eq i32* [[X:%.*]], null
416 ; CHECK-NEXT: [[NOT_C:%.*]] = xor i1 [[C:%.*]], true
417 ; CHECK-NEXT: [[RV:%.*]] = or i1 [[RV1]], [[NOT_C]]
418 ; CHECK-NEXT: ret i1 [[RV]]
420 %R = select i1 %C, i32* %X, i32* null
421 %RV = icmp eq i32* %R, null
425 define i32 @test18(i32 %X, i32 %Y, i1 %C) {
426 ; CHECK-LABEL: @test18(
427 ; CHECK-NEXT: [[V:%.*]] = sdiv i32 [[Y:%.*]], [[X:%.*]]
428 ; CHECK-NEXT: ret i32 [[V]]
430 %R = select i1 %C, i32 %X, i32 0
435 define i32 @test19(i32 %x) {
436 ; CHECK-LABEL: @test19(
437 ; CHECK-NEXT: [[X_LOBIT:%.*]] = ashr i32 [[X:%.*]], 31
438 ; CHECK-NEXT: ret i32 [[X_LOBIT]]
440 %tmp = icmp ugt i32 %x, 2147483647
441 %retval = select i1 %tmp, i32 -1, i32 0
445 define i32 @test20(i32 %x) {
446 ; CHECK-LABEL: @test20(
447 ; CHECK-NEXT: [[X_LOBIT:%.*]] = ashr i32 [[X:%.*]], 31
448 ; CHECK-NEXT: ret i32 [[X_LOBIT]]
450 %tmp = icmp slt i32 %x, 0
451 %retval = select i1 %tmp, i32 -1, i32 0
455 define i64 @test21(i32 %x) {
456 ; CHECK-LABEL: @test21(
457 ; CHECK-NEXT: [[X_LOBIT:%.*]] = ashr i32 [[X:%.*]], 31
458 ; CHECK-NEXT: [[TMP1:%.*]] = sext i32 [[X_LOBIT]] to i64
459 ; CHECK-NEXT: ret i64 [[TMP1]]
461 %tmp = icmp slt i32 %x, 0
462 %retval = select i1 %tmp, i64 -1, i64 0
466 define i16 @test22(i32 %x) {
467 ; CHECK-LABEL: @test22(
468 ; CHECK-NEXT: [[X_LOBIT:%.*]] = ashr i32 [[X:%.*]], 31
469 ; CHECK-NEXT: [[TMP1:%.*]] = trunc i32 [[X_LOBIT]] to i16
470 ; CHECK-NEXT: ret i16 [[TMP1]]
472 %tmp = icmp slt i32 %x, 0
473 %retval = select i1 %tmp, i16 -1, i16 0
477 define i32 @test25(i1 %c) {
478 ; CHECK-LABEL: @test25(
480 ; CHECK-NEXT: br i1 [[C:%.*]], label [[JUMP:%.*]], label [[RET:%.*]]
482 ; CHECK-NEXT: br label [[RET]]
484 ; CHECK-NEXT: [[A:%.*]] = phi i32 [ 10, [[JUMP]] ], [ 20, [[ENTRY:%.*]] ]
485 ; CHECK-NEXT: ret i32 [[A]]
488 br i1 %c, label %jump, label %ret
492 %a = phi i1 [true, %jump], [false, %entry]
493 %b = select i1 %a, i32 10, i32 20
497 define i32 @test26(i1 %cond) {
498 ; CHECK-LABEL: @test26(
500 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[JUMP:%.*]], label [[RET:%.*]]
502 ; CHECK-NEXT: br label [[RET]]
504 ; CHECK-NEXT: [[A:%.*]] = phi i32 [ 20, [[ENTRY:%.*]] ], [ 10, [[JUMP]] ]
505 ; CHECK-NEXT: ret i32 [[A]]
508 br i1 %cond, label %jump, label %ret
510 %c = or i1 false, false
513 %a = phi i1 [true, %entry], [%c, %jump]
514 %b = select i1 %a, i32 20, i32 10
518 define i32 @test27(i1 %c, i32 %A, i32 %B) {
519 ; CHECK-LABEL: @test27(
521 ; CHECK-NEXT: br i1 [[C:%.*]], label [[JUMP:%.*]], label [[RET:%.*]]
523 ; CHECK-NEXT: br label [[RET]]
525 ; CHECK-NEXT: [[P:%.*]] = phi i32 [ [[A:%.*]], [[JUMP]] ], [ [[B:%.*]], [[ENTRY:%.*]] ]
526 ; CHECK-NEXT: ret i32 [[P]]
529 br i1 %c, label %jump, label %ret
533 %p = phi i1 [true, %jump], [false, %entry]
534 %s = select i1 %p, i32 %A, i32 %B
538 define i32 @test28(i1 %cond, i32 %A, i32 %B) {
539 ; CHECK-LABEL: @test28(
541 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[JUMP:%.*]], label [[RET:%.*]]
543 ; CHECK-NEXT: br label [[RET]]
545 ; CHECK-NEXT: [[P:%.*]] = phi i32 [ [[A:%.*]], [[JUMP]] ], [ [[B:%.*]], [[ENTRY:%.*]] ]
546 ; CHECK-NEXT: ret i32 [[P]]
549 br i1 %cond, label %jump, label %ret
553 %c = phi i32 [%A, %jump], [%B, %entry]
554 %p = phi i1 [true, %jump], [false, %entry]
555 %s = select i1 %p, i32 %A, i32 %c
559 define i32 @test29(i1 %cond, i32 %A, i32 %B) {
560 ; CHECK-LABEL: @test29(
562 ; CHECK-NEXT: br i1 [[COND:%.*]], label [[JUMP:%.*]], label [[RET:%.*]]
564 ; CHECK-NEXT: br label [[RET]]
566 ; CHECK-NEXT: [[P:%.*]] = phi i32 [ [[A:%.*]], [[JUMP]] ], [ [[B:%.*]], [[ENTRY:%.*]] ]
567 ; CHECK-NEXT: br label [[NEXT:%.*]]
569 ; CHECK-NEXT: ret i32 [[P]]
572 br i1 %cond, label %jump, label %ret
576 %c = phi i32 [%A, %jump], [%B, %entry]
577 %p = phi i1 [true, %jump], [false, %entry]
581 %s = select i1 %p, i32 %A, i32 %c
585 ; SMAX(SMAX(x, y), x) -> SMAX(x, y)
586 define i32 @test30(i32 %x, i32 %y) {
587 ; CHECK-LABEL: @test30(
588 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X:%.*]], [[Y:%.*]]
589 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[Y]]
590 ; CHECK-NEXT: ret i32 [[COND]]
592 %cmp = icmp sgt i32 %x, %y
593 %cond = select i1 %cmp, i32 %x, i32 %y
594 %cmp5 = icmp sgt i32 %cond, %x
595 %retval = select i1 %cmp5, i32 %cond, i32 %x
599 ; UMAX(UMAX(x, y), x) -> UMAX(x, y)
600 define i32 @test31(i32 %x, i32 %y) {
601 ; CHECK-LABEL: @test31(
602 ; CHECK-NEXT: [[CMP:%.*]] = icmp ugt i32 [[X:%.*]], [[Y:%.*]]
603 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[X]], i32 [[Y]]
604 ; CHECK-NEXT: ret i32 [[COND]]
606 %cmp = icmp ugt i32 %x, %y
607 %cond = select i1 %cmp, i32 %x, i32 %y
608 %cmp5 = icmp ugt i32 %cond, %x
609 %retval = select i1 %cmp5, i32 %cond, i32 %x
613 ; SMIN(SMIN(x, y), x) -> SMIN(x, y)
614 define i32 @test32(i32 %x, i32 %y) {
615 ; CHECK-LABEL: @test32(
616 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[X:%.*]], [[Y:%.*]]
617 ; CHECK-NEXT: [[COND:%.*]] = select i1 [[CMP]], i32 [[Y]], i32 [[X]]
618 ; CHECK-NEXT: ret i32 [[COND]]
620 %cmp = icmp sgt i32 %x, %y
621 %cond = select i1 %cmp, i32 %y, i32 %x
622 %cmp5 = icmp sgt i32 %cond, %x
623 %retval = select i1 %cmp5, i32 %x, i32 %cond
627 ; MAX(MIN(x, y), x) -> x
628 define i32 @test33(i32 %x, i32 %y) {
629 ; CHECK-LABEL: @test33(
630 ; CHECK-NEXT: ret i32 [[X:%.*]]
632 %cmp = icmp sgt i32 %x, %y
633 %cond = select i1 %cmp, i32 %y, i32 %x
634 %cmp5 = icmp sgt i32 %cond, %x
635 %retval = select i1 %cmp5, i32 %cond, i32 %x
639 ; MIN(MAX(x, y), x) -> x
640 define i32 @test34(i32 %x, i32 %y) {
641 ; CHECK-LABEL: @test34(
642 ; CHECK-NEXT: ret i32 [[X:%.*]]
644 %cmp = icmp sgt i32 %x, %y
645 %cond = select i1 %cmp, i32 %x, i32 %y
646 %cmp5 = icmp sgt i32 %cond, %x
647 %retval = select i1 %cmp5, i32 %x, i32 %cond
651 define i1 @test38(i1 %cond) {
652 ; CHECK-LABEL: @test38(
653 ; CHECK-NEXT: ret i1 false
657 %ptr = select i1 %cond, i32* %zero, i32* %one
658 %isnull = icmp eq i32* %ptr, null
662 define i1 @test39(i1 %cond, double %x) {
663 ; CHECK-LABEL: @test39(
664 ; CHECK-NEXT: ret i1 true
666 %s = select i1 %cond, double %x, double 0x7FF0000000000000 ; RHS = +infty
667 %cmp = fcmp ule double %x, %s
671 define i1 @test40(i1 %cond) {
672 ; CHECK-LABEL: @test40(
673 ; CHECK-NEXT: ret i1 false
678 %s = select i1 %cond, i32* %a, i32* %b
679 %r = icmp eq i32* %s, %c
683 define i32 @test41(i1 %cond, i32 %x, i32 %y) {
684 ; CHECK-LABEL: @test41(
685 ; CHECK-NEXT: [[R:%.*]] = and i32 [[X:%.*]], [[Y:%.*]]
686 ; CHECK-NEXT: ret i32 [[R]]
689 %s = select i1 %cond, i32 %y, i32 %z
694 define i32 @test42(i32 %x, i32 %y) {
695 ; CHECK-LABEL: @test42(
696 ; CHECK-NEXT: [[COND:%.*]] = icmp eq i32 [[X:%.*]], 0
697 ; CHECK-NEXT: [[TMP1:%.*]] = zext i1 [[COND]] to i32
698 ; CHECK-NEXT: [[C:%.*]] = sub i32 [[Y:%.*]], [[TMP1]]
699 ; CHECK-NEXT: ret i32 [[C]]
702 %cond = icmp eq i32 %x, 0
703 %c = select i1 %cond, i32 %b, i32 %y
707 define <2 x i32> @test42vec(<2 x i32> %x, <2 x i32> %y) {
708 ; CHECK-LABEL: @test42vec(
709 ; CHECK-NEXT: [[COND:%.*]] = icmp eq <2 x i32> [[X:%.*]], zeroinitializer
710 ; CHECK-NEXT: [[TMP1:%.*]] = zext <2 x i1> [[COND]] to <2 x i32>
711 ; CHECK-NEXT: [[C:%.*]] = sub <2 x i32> [[Y:%.*]], [[TMP1]]
712 ; CHECK-NEXT: ret <2 x i32> [[C]]
714 %b = add <2 x i32> %y, <i32 -1, i32 -1>
715 %cond = icmp eq <2 x i32> %x, zeroinitializer
716 %c = select <2 x i1> %cond, <2 x i32> %b, <2 x i32> %y
722 ; This select instruction can't be eliminated because trying to do so would
723 ; change the number of vector elements. This used to assert.
724 define i48 @test51(<3 x i1> %icmp, <3 x i16> %tmp) {
725 ; CHECK-LABEL: @test51(
726 ; CHECK-NEXT: [[SELECT:%.*]] = select <3 x i1> [[ICMP:%.*]], <3 x i16> zeroinitializer, <3 x i16> [[TMP:%.*]]
727 ; CHECK-NEXT: [[TMP2:%.*]] = bitcast <3 x i16> [[SELECT]] to i48
728 ; CHECK-NEXT: ret i48 [[TMP2]]
730 %select = select <3 x i1> %icmp, <3 x i16> zeroinitializer, <3 x i16> %tmp
731 %tmp2 = bitcast <3 x i16> %select to i48
735 ; Allow select promotion even if there are multiple uses of bitcasted ops.
736 ; Hoisting the selects allows later pattern matching to see that these are min/max ops.
738 define void @min_max_bitcast(<4 x float> %a, <4 x float> %b, <4 x i32>* %ptr1, <4 x i32>* %ptr2) {
739 ; CHECK-LABEL: @min_max_bitcast(
740 ; CHECK-NEXT: [[CMP:%.*]] = fcmp olt <4 x float> [[A:%.*]], [[B:%.*]]
741 ; CHECK-NEXT: [[SEL1_V:%.*]] = select <4 x i1> [[CMP]], <4 x float> [[A]], <4 x float> [[B]]
742 ; CHECK-NEXT: [[SEL2_V:%.*]] = select <4 x i1> [[CMP]], <4 x float> [[B]], <4 x float> [[A]]
743 ; CHECK-NEXT: [[TMP1:%.*]] = bitcast <4 x i32>* [[PTR1:%.*]] to <4 x float>*
744 ; CHECK-NEXT: store <4 x float> [[SEL1_V]], <4 x float>* [[TMP1]], align 16
745 ; CHECK-NEXT: [[TMP2:%.*]] = bitcast <4 x i32>* [[PTR2:%.*]] to <4 x float>*
746 ; CHECK-NEXT: store <4 x float> [[SEL2_V]], <4 x float>* [[TMP2]], align 16
747 ; CHECK-NEXT: ret void
749 %cmp = fcmp olt <4 x float> %a, %b
750 %bc1 = bitcast <4 x float> %a to <4 x i32>
751 %bc2 = bitcast <4 x float> %b to <4 x i32>
752 %sel1 = select <4 x i1> %cmp, <4 x i32> %bc1, <4 x i32> %bc2
753 %sel2 = select <4 x i1> %cmp, <4 x i32> %bc2, <4 x i32> %bc1
754 store <4 x i32> %sel1, <4 x i32>* %ptr1
755 store <4 x i32> %sel2, <4 x i32>* %ptr2
759 ; To avoid potential backend problems, we don't do the same transform for other casts.
761 define void @truncs_before_selects(<4 x float> %f1, <4 x float> %f2, <4 x i64> %a, <4 x i64> %b, <4 x i32>* %ptr1, <4 x i32>* %ptr2) {
762 ; CHECK-LABEL: @truncs_before_selects(
763 ; CHECK-NEXT: [[CMP:%.*]] = fcmp olt <4 x float> [[F1:%.*]], [[F2:%.*]]
764 ; CHECK-NEXT: [[BC1:%.*]] = trunc <4 x i64> [[A:%.*]] to <4 x i32>
765 ; CHECK-NEXT: [[BC2:%.*]] = trunc <4 x i64> [[B:%.*]] to <4 x i32>
766 ; CHECK-NEXT: [[SEL1:%.*]] = select <4 x i1> [[CMP]], <4 x i32> [[BC1]], <4 x i32> [[BC2]]
767 ; CHECK-NEXT: [[SEL2:%.*]] = select <4 x i1> [[CMP]], <4 x i32> [[BC2]], <4 x i32> [[BC1]]
768 ; CHECK-NEXT: store <4 x i32> [[SEL1]], <4 x i32>* [[PTR1:%.*]], align 16
769 ; CHECK-NEXT: store <4 x i32> [[SEL2]], <4 x i32>* [[PTR2:%.*]], align 16
770 ; CHECK-NEXT: ret void
772 %cmp = fcmp olt <4 x float> %f1, %f2
773 %bc1 = trunc <4 x i64> %a to <4 x i32>
774 %bc2 = trunc <4 x i64> %b to <4 x i32>
775 %sel1 = select <4 x i1> %cmp, <4 x i32> %bc1, <4 x i32> %bc2
776 %sel2 = select <4 x i1> %cmp, <4 x i32> %bc2, <4 x i32> %bc1
777 store <4 x i32> %sel1, <4 x i32>* %ptr1, align 16
778 store <4 x i32> %sel2, <4 x i32>* %ptr2, align 16
784 define i32 @test52(i32 %n, i32 %m) {
785 ; CHECK-LABEL: @test52(
786 ; CHECK-NEXT: [[CMP:%.*]] = icmp sgt i32 [[N:%.*]], [[M:%.*]]
787 ; CHECK-NEXT: [[STOREMERGE:%.*]] = select i1 [[CMP]], i32 1, i32 6
788 ; CHECK-NEXT: ret i32 [[STOREMERGE]]
790 %cmp = icmp sgt i32 %n, %m
791 %. = select i1 %cmp, i32 1, i32 3
792 %add = add nsw i32 %., 3
793 %storemerge = select i1 %cmp, i32 %., i32 %add
799 define i32 @test53(i32 %x) {
800 ; CHECK-LABEL: @test53(
801 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], 2
802 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[AND]], [[X]]
803 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i32 2, i32 1
804 ; CHECK-NEXT: ret i32 [[SEL]]
807 %cmp = icmp eq i32 %and, %x
808 %sel = select i1 %cmp, i32 2, i32 1
812 define i32 @test54(i32 %X, i32 %Y) {
813 ; CHECK-LABEL: @test54(
814 ; CHECK-NEXT: [[B:%.*]] = icmp ne i32 [[X:%.*]], 0
815 ; CHECK-NEXT: [[C:%.*]] = zext i1 [[B]] to i32
816 ; CHECK-NEXT: ret i32 [[C]]
818 %A = ashr exact i32 %X, %Y
819 %B = icmp eq i32 %A, 0
820 %C = select i1 %B, i32 %A, i32 1
824 define i1 @test55(i1 %X, i32 %Y, i32 %Z) {
825 ; CHECK-LABEL: @test55(
826 ; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[Y:%.*]], 0
827 ; CHECK-NEXT: ret i1 [[C]]
829 %A = ashr exact i32 %Y, %Z
830 %B = select i1 %X, i32 %Y, i32 %A
831 %C = icmp eq i32 %B, 0
835 define i32 @test56(i16 %x) {
836 ; CHECK-LABEL: @test56(
837 ; CHECK-NEXT: [[CONV:%.*]] = zext i16 [[X:%.*]] to i32
838 ; CHECK-NEXT: ret i32 [[CONV]]
840 %tobool = icmp eq i16 %x, 0
841 %conv = zext i16 %x to i32
842 %cond = select i1 %tobool, i32 0, i32 %conv
846 define i32 @test57(i32 %x, i32 %y) {
847 ; CHECK-LABEL: @test57(
848 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], [[Y:%.*]]
849 ; CHECK-NEXT: ret i32 [[AND]]
851 %and = and i32 %x, %y
852 %tobool = icmp eq i32 %x, 0
853 %.and = select i1 %tobool, i32 0, i32 %and
857 define i32 @test58(i16 %x) {
858 ; CHECK-LABEL: @test58(
859 ; CHECK-NEXT: [[CONV:%.*]] = zext i16 [[X:%.*]] to i32
860 ; CHECK-NEXT: ret i32 [[CONV]]
862 %tobool = icmp ne i16 %x, 1
863 %conv = zext i16 %x to i32
864 %cond = select i1 %tobool, i32 %conv, i32 1
868 define i32 @test59(i32 %x, i32 %y) {
869 ; CHECK-LABEL: @test59(
870 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X:%.*]], [[Y:%.*]]
871 ; CHECK-NEXT: ret i32 [[AND]]
873 %and = and i32 %x, %y
874 %tobool = icmp ne i32 %x, %y
875 %.and = select i1 %tobool, i32 %and, i32 %y
879 define i1 @test60(i32 %x, i1* %y) {
880 ; CHECK-LABEL: @test60(
881 ; CHECK-NEXT: [[CMP:%.*]] = icmp eq i32 [[X:%.*]], 0
882 ; CHECK-NEXT: [[LOAD:%.*]] = load i1, i1* [[Y:%.*]], align 1
883 ; CHECK-NEXT: [[CMP1:%.*]] = icmp slt i32 [[X]], 1
884 ; CHECK-NEXT: [[SEL:%.*]] = select i1 [[CMP]], i1 [[LOAD]], i1 [[CMP1]]
885 ; CHECK-NEXT: ret i1 [[SEL]]
887 %cmp = icmp eq i32 %x, 0
888 %load = load i1, i1* %y, align 1
889 %cmp1 = icmp slt i32 %x, 1
890 %sel = select i1 %cmp, i1 %load, i1 %cmp1
894 @glbl = constant i32 10
895 define i32 @test61(i32* %ptr) {
896 ; CHECK-LABEL: @test61(
897 ; CHECK-NEXT: ret i32 10
899 %A = load i32, i32* %ptr
900 %B = icmp eq i32* %ptr, @glbl
901 %C = select i1 %B, i32 %A, i32 10
906 define void @test64(i32 %p, i16 %b) noreturn {
907 ; CHECK-LABEL: @test64(
909 ; CHECK-NEXT: br i1 undef, label [[LOR_RHS:%.*]], label [[LOR_END:%.*]]
911 ; CHECK-NEXT: br label [[LOR_END]]
913 ; CHECK-NEXT: br i1 true, label [[COND_END17:%.*]], label [[COND_FALSE16:%.*]]
914 ; CHECK: cond.false16:
915 ; CHECK-NEXT: br label [[COND_END17]]
917 ; CHECK-NEXT: br label [[WHILE_BODY:%.*]]
919 ; CHECK-NEXT: br label [[WHILE_BODY]]
922 %p.addr.0.insert.mask = and i32 %p, -65536
923 %conv2 = and i32 %p, 65535
924 br i1 undef, label %lor.rhs, label %lor.end
927 %p.addr.0.extract.trunc = trunc i32 %p.addr.0.insert.mask to i16
928 %phitmp = zext i16 %p.addr.0.extract.trunc to i32
932 %t.1 = phi i32 [ 0, %entry ], [ %phitmp, %lor.rhs ]
933 %conv6 = zext i16 %b to i32
934 %div = udiv i32 %conv6, %t.1
935 %tobool8 = icmp eq i32 %div, 0
936 %cmp = icmp eq i32 %t.1, 0
937 %cmp12 = icmp ult i32 %conv2, 2
938 %cmp.sink = select i1 %tobool8, i1 %cmp12, i1 %cmp
939 br i1 %cmp.sink, label %cond.end17, label %cond.false16
951 @under_aligned = external global i32, align 1
953 ; The load here must not be speculated around the select. One side of the
954 ; select is trivially dereferenceable but may have a lower alignment than the
956 define i32 @test76(i1 %flag, i32* %x) {
957 ; CHECK-LABEL: @test76(
958 ; CHECK-NEXT: store i32 0, i32* [[X:%.*]], align 4
959 ; CHECK-NEXT: [[P:%.*]] = select i1 [[FLAG:%.*]], i32* @under_aligned, i32* [[X]]
960 ; CHECK-NEXT: [[V:%.*]] = load i32, i32* [[P]], align 4
961 ; CHECK-NEXT: ret i32 [[V]]
964 %p = select i1 %flag, i32* @under_aligned, i32* %x
965 %v = load i32, i32* %p
969 declare void @scribble_on_i32(i32*)
971 ; The load here must not be speculated around the select. One side of the
972 ; select is trivially dereferenceable but may have a lower alignment than the
975 define i32 @test77(i1 %flag, i32* %x) {
976 ; CHECK-LABEL: @test77(
977 ; CHECK-NEXT: [[UNDER_ALIGNED:%.*]] = alloca i32, align 1
978 ; CHECK-NEXT: call void @scribble_on_i32(i32* nonnull [[UNDER_ALIGNED]])
979 ; CHECK-NEXT: store i32 0, i32* [[X:%.*]], align 4
980 ; CHECK-NEXT: [[P:%.*]] = select i1 [[FLAG:%.*]], i32* [[UNDER_ALIGNED]], i32* [[X]]
981 ; CHECK-NEXT: [[V:%.*]] = load i32, i32* [[P]], align 4
982 ; CHECK-NEXT: ret i32 [[V]]
984 %under_aligned = alloca i32, align 1
985 call void @scribble_on_i32(i32* %under_aligned)
987 %p = select i1 %flag, i32* %under_aligned, i32* %x
988 %v = load i32, i32* %p
992 define i32 @test78(i1 %flag, i32* %x, i32* %y, i32* %z) {
993 ; Test that we can speculate the loads around the select even when we can't
994 ; fold the load completely away.
995 ; CHECK-LABEL: @test78(
997 ; CHECK-NEXT: store i32 0, i32* [[X:%.*]], align 4
998 ; CHECK-NEXT: store i32 0, i32* [[Y:%.*]], align 4
999 ; CHECK-NEXT: store i32 42, i32* [[Z:%.*]], align 4
1000 ; CHECK-NEXT: [[X_VAL:%.*]] = load i32, i32* [[X]], align 4
1001 ; CHECK-NEXT: [[Y_VAL:%.*]] = load i32, i32* [[Y]], align 4
1002 ; CHECK-NEXT: [[V:%.*]] = select i1 [[FLAG:%.*]], i32 [[X_VAL]], i32 [[Y_VAL]]
1003 ; CHECK-NEXT: ret i32 [[V]]
1006 store i32 0, i32* %x
1007 store i32 0, i32* %y
1008 ; Block forwarding by storing to %z which could alias either %x or %y.
1009 store i32 42, i32* %z
1010 %p = select i1 %flag, i32* %x, i32* %y
1011 %v = load i32, i32* %p
1015 ; Test that we can speculate the loads around the select even when we can't
1016 ; fold the load completely away.
1017 define i32 @test78_deref(i1 %flag, i32* dereferenceable(4) %x, i32* dereferenceable(4) %y, i32* %z) {
1018 ; CHECK-LABEL: @test78_deref(
1019 ; CHECK-NEXT: [[X_VAL:%.*]] = load i32, i32* [[X:%.*]], align 4
1020 ; CHECK-NEXT: [[Y_VAL:%.*]] = load i32, i32* [[Y:%.*]], align 4
1021 ; CHECK-NEXT: [[V:%.*]] = select i1 [[FLAG:%.*]], i32 [[X_VAL]], i32 [[Y_VAL]]
1022 ; CHECK-NEXT: ret i32 [[V]]
1024 %p = select i1 %flag, i32* %x, i32* %y
1025 %v = load i32, i32* %p
1029 ; The same as @test78 but we can't speculate the load because it can trap
1031 define i32 @test78_neg(i1 %flag, i32* %x, i32* %y, i32* %z) {
1032 ; CHECK-LABEL: @test78_neg(
1033 ; CHECK-NEXT: store i32 0, i32* [[X:%.*]], align 4
1034 ; CHECK-NEXT: store i32 0, i32* [[Y:%.*]], align 4
1035 ; CHECK-NEXT: store i32 42, i32* [[Z:%.*]], align 4
1036 ; CHECK-NEXT: [[P:%.*]] = select i1 [[FLAG:%.*]], i32* [[X]], i32* [[Y]]
1037 ; CHECK-NEXT: [[V:%.*]] = load i32, i32* [[P]], align 16
1038 ; CHECK-NEXT: ret i32 [[V]]
1040 store i32 0, i32* %x
1041 store i32 0, i32* %y
1042 ; Block forwarding by storing to %z which could alias either %x or %y.
1043 store i32 42, i32* %z
1044 %p = select i1 %flag, i32* %x, i32* %y
1045 %v = load i32, i32* %p, align 16
1049 ; The same as @test78_deref but we can't speculate the load because
1050 ; one of the arguments is not sufficiently dereferenceable.
1051 define i32 @test78_deref_neg(i1 %flag, i32* dereferenceable(2) %x, i32* dereferenceable(4) %y, i32* %z) {
1052 ; CHECK-LABEL: @test78_deref_neg(
1053 ; CHECK-NEXT: [[P:%.*]] = select i1 [[FLAG:%.*]], i32* [[X:%.*]], i32* [[Y:%.*]]
1054 ; CHECK-NEXT: [[V:%.*]] = load i32, i32* [[P]], align 4
1055 ; CHECK-NEXT: ret i32 [[V]]
1057 %p = select i1 %flag, i32* %x, i32* %y
1058 %v = load i32, i32* %p
1062 ; Test that we can speculate the loads around the select even when we can't
1063 ; fold the load completely away.
1064 define float @test79(i1 %flag, float* %x, i32* %y, i32* %z) {
1065 ; CHECK-LABEL: @test79(
1066 ; CHECK-NEXT: [[X1:%.*]] = bitcast float* [[X:%.*]] to i32*
1067 ; CHECK-NEXT: [[Y1:%.*]] = bitcast i32* [[Y:%.*]] to float*
1068 ; CHECK-NEXT: store i32 0, i32* [[X1]], align 4
1069 ; CHECK-NEXT: store i32 0, i32* [[Y]], align 4
1070 ; CHECK-NEXT: store i32 42, i32* [[Z:%.*]], align 4
1071 ; CHECK-NEXT: [[X_VAL:%.*]] = load float, float* [[X]], align 4
1072 ; CHECK-NEXT: [[Y1_VAL:%.*]] = load float, float* [[Y1]], align 4
1073 ; CHECK-NEXT: [[V:%.*]] = select i1 [[FLAG:%.*]], float [[X_VAL]], float [[Y1_VAL]]
1074 ; CHECK-NEXT: ret float [[V]]
1076 %x1 = bitcast float* %x to i32*
1077 %y1 = bitcast i32* %y to float*
1078 store i32 0, i32* %x1
1079 store i32 0, i32* %y
1080 ; Block forwarding by storing to %z which could alias either %x or %y.
1081 store i32 42, i32* %z
1082 %p = select i1 %flag, float* %x, float* %y1
1083 %v = load float, float* %p
1087 ; Test that when we speculate the loads around the select they fold throug
1088 ; load->load folding and load->store folding.
1089 define i32 @test80(i1 %flag) {
1090 ; CHECK-LABEL: @test80(
1091 ; CHECK-NEXT: [[X:%.*]] = alloca i32, align 4
1092 ; CHECK-NEXT: [[Y:%.*]] = alloca i32, align 4
1093 ; CHECK-NEXT: call void @scribble_on_i32(i32* nonnull [[X]])
1094 ; CHECK-NEXT: call void @scribble_on_i32(i32* nonnull [[Y]])
1095 ; CHECK-NEXT: [[TMP:%.*]] = load i32, i32* [[X]], align 4
1096 ; CHECK-NEXT: store i32 [[TMP]], i32* [[Y]], align 4
1097 ; CHECK-NEXT: ret i32 [[TMP]]
1101 call void @scribble_on_i32(i32* %x)
1102 call void @scribble_on_i32(i32* %y)
1103 %tmp = load i32, i32* %x
1104 store i32 %tmp, i32* %y
1105 %p = select i1 %flag, i32* %x, i32* %y
1106 %v = load i32, i32* %p
1110 ; Test that we can speculate the load around the select even though they use
1111 ; differently typed pointers.
1112 define float @test81(i1 %flag) {
1113 ; CHECK-LABEL: @test81(
1114 ; CHECK-NEXT: [[X:%.*]] = alloca i32, align 4
1115 ; CHECK-NEXT: [[Y:%.*]] = alloca i32, align 4
1116 ; CHECK-NEXT: call void @scribble_on_i32(i32* nonnull [[X]])
1117 ; CHECK-NEXT: call void @scribble_on_i32(i32* nonnull [[Y]])
1118 ; CHECK-NEXT: [[TMP:%.*]] = load i32, i32* [[X]], align 4
1119 ; CHECK-NEXT: store i32 [[TMP]], i32* [[Y]], align 4
1120 ; CHECK-NEXT: [[V:%.*]] = bitcast i32 [[TMP]] to float
1121 ; CHECK-NEXT: ret float [[V]]
1125 %x1 = bitcast float* %x to i32*
1126 %y1 = bitcast i32* %y to float*
1127 call void @scribble_on_i32(i32* %x1)
1128 call void @scribble_on_i32(i32* %y)
1129 %tmp = load i32, i32* %x1
1130 store i32 %tmp, i32* %y
1131 %p = select i1 %flag, float* %x, float* %y1
1132 %v = load float, float* %p
1136 ; Test that we can speculate the load around the select even though they use
1137 ; differently typed pointers.
1138 define i32 @test82(i1 %flag) {
1139 ; CHECK-LABEL: @test82(
1140 ; CHECK-NEXT: [[X:%.*]] = alloca float, align 4
1141 ; CHECK-NEXT: [[Y:%.*]] = alloca i32, align 4
1142 ; CHECK-NEXT: [[X1:%.*]] = bitcast float* [[X]] to i32*
1143 ; CHECK-NEXT: [[Y1:%.*]] = bitcast i32* [[Y]] to float*
1144 ; CHECK-NEXT: call void @scribble_on_i32(i32* nonnull [[X1]])
1145 ; CHECK-NEXT: call void @scribble_on_i32(i32* nonnull [[Y]])
1146 ; CHECK-NEXT: [[TMP:%.*]] = load float, float* [[X]], align 4
1147 ; CHECK-NEXT: store float [[TMP]], float* [[Y1]], align 4
1148 ; CHECK-NEXT: [[V:%.*]] = bitcast float [[TMP]] to i32
1149 ; CHECK-NEXT: ret i32 [[V]]
1153 %x1 = bitcast float* %x to i32*
1154 %y1 = bitcast i32* %y to float*
1155 call void @scribble_on_i32(i32* %x1)
1156 call void @scribble_on_i32(i32* %y)
1157 %tmp = load float, float* %x
1158 store float %tmp, float* %y1
1159 %p = select i1 %flag, i32* %x1, i32* %y
1160 %v = load i32, i32* %p
1164 declare void @scribble_on_i64(i64*)
1165 declare void @scribble_on_i128(i128*)
1167 ; Test that we can speculate the load around the select even though they use
1168 ; differently typed pointers and requires inttoptr casts.
1169 define i8* @test83(i1 %flag) {
1170 ; CHECK-LABEL: @test83(
1171 ; CHECK-NEXT: [[X:%.*]] = alloca i8*, align 8
1172 ; CHECK-NEXT: [[Y:%.*]] = alloca i8*, align 8
1173 ; CHECK-NEXT: [[TMPCAST:%.*]] = bitcast i8** [[Y]] to i64*
1174 ; CHECK-NEXT: [[X1:%.*]] = bitcast i8** [[X]] to i64*
1175 ; CHECK-NEXT: call void @scribble_on_i64(i64* nonnull [[X1]])
1176 ; CHECK-NEXT: call void @scribble_on_i64(i64* nonnull [[TMPCAST]])
1177 ; CHECK-NEXT: [[TMP:%.*]] = load i64, i64* [[X1]], align 8
1178 ; CHECK-NEXT: store i64 [[TMP]], i64* [[TMPCAST]], align 8
1179 ; CHECK-NEXT: [[V:%.*]] = inttoptr i64 [[TMP]] to i8*
1180 ; CHECK-NEXT: ret i8* [[V]]
1184 %x1 = bitcast i8** %x to i64*
1185 %y1 = bitcast i64* %y to i8**
1186 call void @scribble_on_i64(i64* %x1)
1187 call void @scribble_on_i64(i64* %y)
1188 %tmp = load i64, i64* %x1
1189 store i64 %tmp, i64* %y
1190 %p = select i1 %flag, i8** %x, i8** %y1
1191 %v = load i8*, i8** %p
1195 ; Test that we can speculate the load around the select even though they use
1196 ; differently typed pointers and requires a ptrtoint cast.
1197 define i64 @test84(i1 %flag) {
1198 ; CHECK-LABEL: @test84(
1199 ; CHECK-NEXT: [[X:%.*]] = alloca i8*, align 8
1200 ; CHECK-NEXT: [[Y:%.*]] = alloca i8*, align 8
1201 ; CHECK-NEXT: [[TMPCAST:%.*]] = bitcast i8** [[Y]] to i64*
1202 ; CHECK-NEXT: [[X1:%.*]] = bitcast i8** [[X]] to i64*
1203 ; CHECK-NEXT: call void @scribble_on_i64(i64* nonnull [[X1]])
1204 ; CHECK-NEXT: call void @scribble_on_i64(i64* nonnull [[TMPCAST]])
1205 ; CHECK-NEXT: [[TMP:%.*]] = load i8*, i8** [[X]], align 8
1206 ; CHECK-NEXT: store i8* [[TMP]], i8** [[Y]], align 8
1207 ; CHECK-NEXT: [[V:%.*]] = ptrtoint i8* [[TMP]] to i64
1208 ; CHECK-NEXT: ret i64 [[V]]
1212 %x1 = bitcast i8** %x to i64*
1213 %y1 = bitcast i64* %y to i8**
1214 call void @scribble_on_i64(i64* %x1)
1215 call void @scribble_on_i64(i64* %y)
1216 %tmp = load i8*, i8** %x
1217 store i8* %tmp, i8** %y1
1218 %p = select i1 %flag, i64* %x1, i64* %y
1219 %v = load i64, i64* %p
1223 ; Test that we can't speculate the load around the select. The load of the
1224 ; pointer doesn't load all of the stored integer bits. We could fix this, but it
1225 ; would require endianness checks and other nastiness.
1226 define i8* @test85(i1 %flag) {
1227 ; CHECK-LABEL: @test85(
1228 ; CHECK-NEXT: [[X1:%.*]] = alloca [2 x i8*], align 8
1229 ; CHECK-NEXT: [[Y:%.*]] = alloca i128, align 8
1230 ; CHECK-NEXT: [[X1_SUB:%.*]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[X1]], i64 0, i64 0
1231 ; CHECK-NEXT: [[X2:%.*]] = bitcast [2 x i8*]* [[X1]] to i128*
1232 ; CHECK-NEXT: [[Y1:%.*]] = bitcast i128* [[Y]] to i8**
1233 ; CHECK-NEXT: call void @scribble_on_i128(i128* nonnull [[X2]])
1234 ; CHECK-NEXT: call void @scribble_on_i128(i128* nonnull [[Y]])
1235 ; CHECK-NEXT: [[TMP:%.*]] = load i128, i128* [[X2]], align 8
1236 ; CHECK-NEXT: store i128 [[TMP]], i128* [[Y]], align 8
1237 ; CHECK-NEXT: [[X1_SUB_VAL:%.*]] = load i8*, i8** [[X1_SUB]], align 8
1238 ; CHECK-NEXT: [[Y1_VAL:%.*]] = load i8*, i8** [[Y1]], align 8
1239 ; CHECK-NEXT: [[V:%.*]] = select i1 [[FLAG:%.*]], i8* [[X1_SUB_VAL]], i8* [[Y1_VAL]]
1240 ; CHECK-NEXT: ret i8* [[V]]
1242 %x = alloca [2 x i8*]
1244 %x1 = bitcast [2 x i8*]* %x to i8**
1245 %x2 = bitcast i8** %x1 to i128*
1246 %y1 = bitcast i128* %y to i8**
1247 call void @scribble_on_i128(i128* %x2)
1248 call void @scribble_on_i128(i128* %y)
1249 %tmp = load i128, i128* %x2
1250 store i128 %tmp, i128* %y
1251 %p = select i1 %flag, i8** %x1, i8** %y1
1252 %v = load i8*, i8** %p
1256 ; Test that we can't speculate the load around the select when the integer size
1257 ; is larger than the pointer size. The store of the pointer doesn't store to all
1258 ; the bits of the integer.
1259 define i128 @test86(i1 %flag) {
1260 ; CHECK-LABEL: @test86(
1261 ; CHECK-NEXT: [[X1:%.*]] = alloca [2 x i8*], align 8
1262 ; CHECK-NEXT: [[Y:%.*]] = alloca i128, align 8
1263 ; CHECK-NEXT: [[X1_SUB:%.*]] = getelementptr inbounds [2 x i8*], [2 x i8*]* [[X1]], i64 0, i64 0
1264 ; CHECK-NEXT: [[X2:%.*]] = bitcast [2 x i8*]* [[X1]] to i128*
1265 ; CHECK-NEXT: [[Y1:%.*]] = bitcast i128* [[Y]] to i8**
1266 ; CHECK-NEXT: call void @scribble_on_i128(i128* nonnull [[X2]])
1267 ; CHECK-NEXT: call void @scribble_on_i128(i128* nonnull [[Y]])
1268 ; CHECK-NEXT: [[TMP:%.*]] = load i8*, i8** [[X1_SUB]], align 8
1269 ; CHECK-NEXT: store i8* [[TMP]], i8** [[Y1]], align 8
1270 ; CHECK-NEXT: [[X2_VAL:%.*]] = load i128, i128* [[X2]], align 8
1271 ; CHECK-NEXT: [[Y_VAL:%.*]] = load i128, i128* [[Y]], align 8
1272 ; CHECK-NEXT: [[V:%.*]] = select i1 [[FLAG:%.*]], i128 [[X2_VAL]], i128 [[Y_VAL]]
1273 ; CHECK-NEXT: ret i128 [[V]]
1275 %x = alloca [2 x i8*]
1277 %x1 = bitcast [2 x i8*]* %x to i8**
1278 %x2 = bitcast i8** %x1 to i128*
1279 %y1 = bitcast i128* %y to i8**
1280 call void @scribble_on_i128(i128* %x2)
1281 call void @scribble_on_i128(i128* %y)
1282 %tmp = load i8*, i8** %x1
1283 store i8* %tmp, i8** %y1
1284 %p = select i1 %flag, i128* %x2, i128* %y
1285 %v = load i128, i128* %p
1289 define i32 @test_select_select0(i32 %a, i32 %r0, i32 %r1, i32 %v1, i32 %v2) {
1290 ; CHECK-LABEL: @test_select_select0(
1291 ; CHECK-NEXT: [[C0:%.*]] = icmp slt i32 [[A:%.*]], [[V1:%.*]]
1292 ; CHECK-NEXT: [[S0:%.*]] = select i1 [[C0]], i32 [[R1:%.*]], i32 [[R0:%.*]]
1293 ; CHECK-NEXT: [[C1:%.*]] = icmp slt i32 [[A]], [[V2:%.*]]
1294 ; CHECK-NEXT: [[S1:%.*]] = select i1 [[C1]], i32 [[S0]], i32 [[R1]]
1295 ; CHECK-NEXT: ret i32 [[S1]]
1297 %c0 = icmp sge i32 %a, %v1
1298 %s0 = select i1 %c0, i32 %r0, i32 %r1
1299 %c1 = icmp slt i32 %a, %v2
1300 %s1 = select i1 %c1, i32 %s0, i32 %r1
1304 define i32 @test_select_select1(i32 %a, i32 %r0, i32 %r1, i32 %v1, i32 %v2) {
1305 ; CHECK-LABEL: @test_select_select1(
1306 ; CHECK-NEXT: [[C0:%.*]] = icmp slt i32 [[A:%.*]], [[V1:%.*]]
1307 ; CHECK-NEXT: [[S0:%.*]] = select i1 [[C0]], i32 [[R1:%.*]], i32 [[R0:%.*]]
1308 ; CHECK-NEXT: [[C1:%.*]] = icmp slt i32 [[A]], [[V2:%.*]]
1309 ; CHECK-NEXT: [[S1:%.*]] = select i1 [[C1]], i32 [[R0]], i32 [[S0]]
1310 ; CHECK-NEXT: ret i32 [[S1]]
1312 %c0 = icmp sge i32 %a, %v1
1313 %s0 = select i1 %c0, i32 %r0, i32 %r1
1314 %c1 = icmp slt i32 %a, %v2
1315 %s1 = select i1 %c1, i32 %r0, i32 %s0
1319 define i32 @PR23757(i32 %x) {
1320 ; CHECK-LABEL: @PR23757(
1321 ; CHECK-NEXT: [[ADD:%.*]] = add i32 [[X:%.*]], 1
1322 ; CHECK-NEXT: ret i32 [[ADD]]
1324 %cmp = icmp eq i32 %x, 2147483647
1325 %add = add nsw i32 %x, 1
1326 %sel = select i1 %cmp, i32 -2147483648, i32 %add
1330 define i32 @PR23757_swapped(i32 %x) {
1331 ; CHECK-LABEL: @PR23757_swapped(
1332 ; CHECK-NEXT: ret i32 -2147483648
1334 %cmp = icmp eq i32 %x, 2147483647
1335 %add = add nsw i32 %x, 1
1336 %sel = select i1 %cmp, i32 %add, i32 -2147483648
1340 define i32 @PR23757_ne(i32 %x, i1* %p) {
1341 ; CHECK-LABEL: @PR23757_ne(
1342 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[X:%.*]], 2147483647
1343 ; CHECK-NEXT: store i1 [[CMP]], i1* [[P:%.*]], align 1
1344 ; CHECK-NEXT: ret i32 -2147483648
1346 %cmp = icmp ne i32 %x, 2147483647
1347 store i1 %cmp, i1* %p ; thwart predicate canonicalization
1348 %add = add nsw i32 %x, 1
1349 %sel = select i1 %cmp, i32 -2147483648, i32 %add
1353 define i32 @PR23757_ne_swapped(i32 %x, i1* %p) {
1354 ; CHECK-LABEL: @PR23757_ne_swapped(
1355 ; CHECK-NEXT: [[CMP:%.*]] = icmp ne i32 [[X:%.*]], 2147483647
1356 ; CHECK-NEXT: store i1 [[CMP]], i1* [[P:%.*]], align 1
1357 ; CHECK-NEXT: [[ADD:%.*]] = add i32 [[X]], 1
1358 ; CHECK-NEXT: ret i32 [[ADD]]
1360 %cmp = icmp ne i32 %x, 2147483647
1361 store i1 %cmp, i1* %p ; thwart predicate canonicalization
1362 %add = add nsw i32 %x, 1
1363 %sel = select i1 %cmp, i32 %add, i32 -2147483648
1367 ; max(max(~a, -1), -1) --> ~min(a, 0)
1369 define i32 @PR27137(i32 %a) {
1370 ; CHECK-LABEL: @PR27137(
1371 ; CHECK-NEXT: [[TMP1:%.*]] = icmp slt i32 [[A:%.*]], 0
1372 ; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[TMP1]], i32 [[A]], i32 0
1373 ; CHECK-NEXT: [[S1:%.*]] = xor i32 [[TMP2]], -1
1374 ; CHECK-NEXT: ret i32 [[S1]]
1376 %not_a = xor i32 %a, -1
1377 %c0 = icmp slt i32 %a, 0
1378 %s0 = select i1 %c0, i32 %not_a, i32 -1
1379 %c1 = icmp sgt i32 %s0, -1
1380 %s1 = select i1 %c1, i32 %s0, i32 -1
1384 define i32 @select_icmp_slt0_xor(i32 %x) {
1385 ; CHECK-LABEL: @select_icmp_slt0_xor(
1386 ; CHECK-NEXT: [[TMP1:%.*]] = or i32 [[X:%.*]], -2147483648
1387 ; CHECK-NEXT: ret i32 [[TMP1]]
1389 %cmp = icmp slt i32 %x, zeroinitializer
1390 %xor = xor i32 %x, 2147483648
1391 %x.xor = select i1 %cmp, i32 %x, i32 %xor
1395 define <2 x i32> @select_icmp_slt0_xor_vec(<2 x i32> %x) {
1396 ; CHECK-LABEL: @select_icmp_slt0_xor_vec(
1397 ; CHECK-NEXT: [[TMP1:%.*]] = or <2 x i32> [[X:%.*]], <i32 -2147483648, i32 -2147483648>
1398 ; CHECK-NEXT: ret <2 x i32> [[TMP1]]
1400 %cmp = icmp slt <2 x i32> %x, zeroinitializer
1401 %xor = xor <2 x i32> %x, <i32 2147483648, i32 2147483648>
1402 %x.xor = select <2 x i1> %cmp, <2 x i32> %x, <2 x i32> %xor
1403 ret <2 x i32> %x.xor
1406 define <4 x i32> @canonicalize_to_shuffle(<4 x i32> %a, <4 x i32> %b) {
1407 ; CHECK-LABEL: @canonicalize_to_shuffle(
1408 ; CHECK-NEXT: [[SEL:%.*]] = shufflevector <4 x i32> [[A:%.*]], <4 x i32> [[B:%.*]], <4 x i32> <i32 0, i32 5, i32 6, i32 3>
1409 ; CHECK-NEXT: ret <4 x i32> [[SEL]]
1411 %sel = select <4 x i1> <i1 true, i1 false, i1 false, i1 true>, <4 x i32> %a, <4 x i32> %b
1415 ; Undef elements of the select condition may not be translated into undef elements of a shuffle mask
1416 ; because undef in a shuffle mask means we can return anything, not just one of the selected values.
1417 ; https://bugs.llvm.org/show_bug.cgi?id=32486
1419 define <4 x i32> @undef_elts_in_condition(<4 x i32> %a, <4 x i32> %b) {
1420 ; CHECK-LABEL: @undef_elts_in_condition(
1421 ; CHECK-NEXT: [[SEL:%.*]] = select <4 x i1> <i1 true, i1 undef, i1 false, i1 undef>, <4 x i32> [[A:%.*]], <4 x i32> [[B:%.*]]
1422 ; CHECK-NEXT: ret <4 x i32> [[SEL]]
1424 %sel = select <4 x i1> <i1 true, i1 undef, i1 false, i1 undef>, <4 x i32> %a, <4 x i32> %b
1428 ; Don't die or try if the condition mask is a constant expression or contains a constant expression.
1432 define <4 x i32> @cannot_canonicalize_to_shuffle1(<4 x i32> %a, <4 x i32> %b) {
1433 ; CHECK-LABEL: @cannot_canonicalize_to_shuffle1(
1434 ; CHECK-NEXT: [[SEL:%.*]] = select <4 x i1> bitcast (i4 ptrtoint (i32* @g to i4) to <4 x i1>), <4 x i32> [[A:%.*]], <4 x i32> [[B:%.*]]
1435 ; CHECK-NEXT: ret <4 x i32> [[SEL]]
1437 %sel = select <4 x i1> bitcast (i4 ptrtoint (i32* @g to i4) to <4 x i1>), <4 x i32> %a, <4 x i32> %b
1441 define <4 x i32> @cannot_canonicalize_to_shuffle2(<4 x i32> %a, <4 x i32> %b) {
1442 ; CHECK-LABEL: @cannot_canonicalize_to_shuffle2(
1443 ; CHECK-NEXT: [[SEL:%.*]] = select <4 x i1> <i1 true, i1 undef, i1 false, i1 icmp sle (i16 ptrtoint (i32* @g to i16), i16 4)>, <4 x i32> [[A:%.*]], <4 x i32> [[B:%.*]]
1444 ; CHECK-NEXT: ret <4 x i32> [[SEL]]
1446 %sel = select <4 x i1> <i1 true, i1 undef, i1 false, i1 icmp sle (i16 ptrtoint (i32* @g to i16), i16 4)>, <4 x i32> %a, <4 x i32> %b
1450 declare void @llvm.assume(i1)
1452 define i8 @assume_cond_true(i1 %cond, i8 %x, i8 %y) {
1453 ; CHECK-LABEL: @assume_cond_true(
1454 ; CHECK-NEXT: call void @llvm.assume(i1 [[COND:%.*]])
1455 ; CHECK-NEXT: ret i8 [[X:%.*]]
1457 call void @llvm.assume(i1 %cond)
1458 %sel = select i1 %cond, i8 %x, i8 %y
1462 ; computeKnownBitsFromAssume() understands the 'not' of an assumed condition.
1464 define i8 @assume_cond_false(i1 %cond, i8 %x, i8 %y) {
1465 ; CHECK-LABEL: @assume_cond_false(
1466 ; CHECK-NEXT: [[NOTCOND:%.*]] = xor i1 [[COND:%.*]], true
1467 ; CHECK-NEXT: call void @llvm.assume(i1 [[NOTCOND]])
1468 ; CHECK-NEXT: ret i8 [[Y:%.*]]
1470 %notcond = xor i1 %cond, true
1471 call void @llvm.assume(i1 %notcond)
1472 %sel = select i1 %cond, i8 %x, i8 %y
1476 ; Test case to make sure we don't consider an all ones float values for converting the select into a sext.
1477 define <4 x float> @PR33721(<4 x float> %w) {
1478 ; CHECK-LABEL: @PR33721(
1479 ; CHECK-NEXT: entry:
1480 ; CHECK-NEXT: [[TMP0:%.*]] = fcmp ole <4 x float> [[W:%.*]], zeroinitializer
1481 ; CHECK-NEXT: [[TMP1:%.*]] = select <4 x i1> [[TMP0]], <4 x float> <float 0xFFFFFFFFE0000000, float 0xFFFFFFFFE0000000, float 0xFFFFFFFFE0000000, float 0xFFFFFFFFE0000000>, <4 x float> zeroinitializer
1482 ; CHECK-NEXT: ret <4 x float> [[TMP1]]
1485 %0 = fcmp ole <4 x float> %w, zeroinitializer
1486 %1 = select <4 x i1> %0, <4 x float> <float 0xFFFFFFFFE0000000, float 0xFFFFFFFFE0000000, float 0xFFFFFFFFE0000000, float 0xFFFFFFFFE0000000>, <4 x float> zeroinitializer
1490 ; select(C, binop(select(C, X, Y), W), Z) -> select(C, binop(X, W), Z)
1491 define i8 @test87(i1 %cond, i8 %w, i8 %x, i8 %y, i8 %z) {
1492 ; CHECK-LABEL: @test87(
1493 ; CHECK-NEXT: [[B:%.*]] = add i8 [[X:%.*]], [[W:%.*]]
1494 ; CHECK-NEXT: [[C:%.*]] = select i1 [[COND:%.*]], i8 [[B]], i8 [[Z:%.*]]
1495 ; CHECK-NEXT: ret i8 [[C]]
1497 %a = select i1 %cond, i8 %x, i8 %y
1499 %c = select i1 %cond, i8 %b, i8 %z
1503 ; select(C, binop(select(C, X, Y), W), Z) -> select(C, Z, binop(Y, W))
1504 define i8 @test88(i1 %cond, i8 %w, i8 %x, i8 %y, i8 %z) {
1505 ; CHECK-LABEL: @test88(
1506 ; CHECK-NEXT: [[B:%.*]] = sub i8 [[Y:%.*]], [[W:%.*]]
1507 ; CHECK-NEXT: [[C:%.*]] = select i1 [[COND:%.*]], i8 [[Z:%.*]], i8 [[B]]
1508 ; CHECK-NEXT: ret i8 [[C]]
1510 %a = select i1 %cond, i8 %x, i8 %y
1512 %c = select i1 %cond, i8 %z, i8 %b
1516 ; select(C, Z, binop(W, select(C, X, Y))) -> select(C, binop(X, W), Z)
1517 define i8 @test89(i1 %cond, i8 %w, i8 %x, i8 %y, i8 %z) {
1518 ; CHECK-LABEL: @test89(
1519 ; CHECK-NEXT: [[B:%.*]] = and i8 [[X:%.*]], [[W:%.*]]
1520 ; CHECK-NEXT: [[C:%.*]] = select i1 [[COND:%.*]], i8 [[B]], i8 [[Z:%.*]]
1521 ; CHECK-NEXT: ret i8 [[C]]
1523 %a = select i1 %cond, i8 %x, i8 %y
1525 %c = select i1 %cond, i8 %b, i8 %z
1529 ; select(C, Z, binop(W, select(C, X, Y))) -> select(C, Z, binop(W, Y))
1530 define i8 @test90(i1 %cond, i8 %w, i8 %x, i8 %y, i8 %z) {
1531 ; CHECK-LABEL: @test90(
1532 ; CHECK-NEXT: [[B:%.*]] = or i8 [[Y:%.*]], [[W:%.*]]
1533 ; CHECK-NEXT: [[C:%.*]] = select i1 [[COND:%.*]], i8 [[Z:%.*]], i8 [[B]]
1534 ; CHECK-NEXT: ret i8 [[C]]
1536 %a = select i1 %cond, i8 %x, i8 %y
1538 %c = select i1 %cond, i8 %z, i8 %b
1542 define i32 @test_shl_zext_bool(i1 %t) {
1543 ; CHECK-LABEL: @test_shl_zext_bool(
1544 ; CHECK-NEXT: [[R:%.*]] = select i1 [[T:%.*]], i32 4, i32 0
1545 ; CHECK-NEXT: ret i32 [[R]]
1547 %r = select i1 %t, i32 4, i32 0
1551 define <2 x i32> @test_shl_zext_bool_splat(<2 x i1> %t) {
1552 ; CHECK-LABEL: @test_shl_zext_bool_splat(
1553 ; CHECK-NEXT: [[R:%.*]] = select <2 x i1> [[T:%.*]], <2 x i32> <i32 8, i32 8>, <2 x i32> zeroinitializer
1554 ; CHECK-NEXT: ret <2 x i32> [[R]]
1556 %r = select <2 x i1> %t, <2 x i32> <i32 8, i32 8>, <2 x i32> zeroinitializer
1560 define <2 x i32> @test_shl_zext_bool_vec(<2 x i1> %t) {
1561 ; CHECK-LABEL: @test_shl_zext_bool_vec(
1562 ; CHECK-NEXT: [[R:%.*]] = select <2 x i1> [[T:%.*]], <2 x i32> <i32 4, i32 8>, <2 x i32> zeroinitializer
1563 ; CHECK-NEXT: ret <2 x i32> [[R]]
1565 %r = select <2 x i1> %t, <2 x i32> <i32 4, i32 8>, <2 x i32> zeroinitializer