1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
4 define <4 x i32> @lshr_non_splat_vector(<4 x i32> %A) {
5 ; CHECK-LABEL: @lshr_non_splat_vector(
6 ; CHECK-NEXT: [[B:%.*]] = lshr <4 x i32> [[A:%.*]], <i32 32, i32 1, i32 2, i32 3>
7 ; CHECK-NEXT: ret <4 x i32> [[B]]
9 %B = lshr <4 x i32> %A, <i32 32, i32 1, i32 2, i32 3>
13 define <4 x i32> @shl_non_splat_vector(<4 x i32> %A) {
14 ; CHECK-LABEL: @shl_non_splat_vector(
15 ; CHECK-NEXT: [[B:%.*]] = shl <4 x i32> [[A:%.*]], <i32 32, i32 1, i32 2, i32 3>
16 ; CHECK-NEXT: ret <4 x i32> [[B]]
18 %B = shl <4 x i32> %A, <i32 32, i32 1, i32 2, i32 3>
22 define i32 @test6(i32 %A) {
23 ; CHECK-LABEL: @test6(
24 ; CHECK-NEXT: [[C:%.*]] = mul i32 [[A:%.*]], 6
25 ; CHECK-NEXT: ret i32 [[C]]
27 %B = shl i32 %A, 1 ;; convert to an mul instruction
32 define i32 @test6a(i32 %A) {
33 ; CHECK-LABEL: @test6a(
34 ; CHECK-NEXT: [[C:%.*]] = mul i32 [[A:%.*]], 6
35 ; CHECK-NEXT: ret i32 [[C]]
38 %C = shl i32 %B, 1 ;; convert to an mul instruction
42 ;; (A << 5) << 3 === A << 8 == 0
43 define i8 @test8(i8 %A) {
44 ; CHECK-LABEL: @test8(
45 ; CHECK-NEXT: ret i8 0
52 ;; (A << 7) >> 7 === A & 1
53 define i8 @test9(i8 %A) {
54 ; CHECK-LABEL: @test9(
55 ; CHECK-NEXT: [[B:%.*]] = and i8 [[A:%.*]], 1
56 ; CHECK-NEXT: ret i8 [[B]]
63 ;; (A >> 7) << 7 === A & 128
65 define i8 @test10(i8 %A) {
66 ; CHECK-LABEL: @test10(
67 ; CHECK-NEXT: [[B:%.*]] = and i8 [[A:%.*]], -128
68 ; CHECK-NEXT: ret i8 [[B]]
75 ;; Allow the simplification when the lshr shift is exact.
76 define i8 @test10a(i8 %A) {
77 ; CHECK-LABEL: @test10a(
78 ; CHECK-NEXT: ret i8 [[A:%.*]]
80 %B = lshr exact i8 %A, 7
85 ;; (A >> 3) << 4 === (A & 0x1F) << 1
86 define i8 @test11(i8 %x) {
87 ; CHECK-LABEL: @test11(
88 ; CHECK-NEXT: [[TMP1:%.*]] = mul i8 [[X:%.*]], 6
89 ; CHECK-NEXT: [[C:%.*]] = and i8 [[TMP1]], -16
90 ; CHECK-NEXT: ret i8 [[C]]
98 ;; Allow the simplification in InstCombine when the lshr shift is exact.
99 define i8 @test11a(i8 %A) {
100 ; CHECK-LABEL: @test11a(
101 ; CHECK-NEXT: [[C:%.*]] = mul i8 [[A:%.*]], 6
102 ; CHECK-NEXT: ret i8 [[C]]
105 %B = lshr exact i8 %a, 3
110 ;; (A >> 8) << 8 === A & -256
111 define i32 @test12(i32 %A) {
112 ; CHECK-LABEL: @test12(
113 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[A:%.*]], -256
114 ; CHECK-NEXT: ret i32 [[TMP1]]
121 ;; ((A >>s 6) << 6 === (A & FFFFFFC0)
122 define i8 @shishi(i8 %x) {
123 ; CHECK-LABEL: @shishi(
124 ; CHECK-NEXT: [[A:%.*]] = ashr i8 [[X:%.*]], 6
125 ; CHECK-NEXT: [[B:%.*]] = and i8 [[X]], -64
126 ; CHECK-NEXT: [[EXTRA_USE_OF_A:%.*]] = mul nsw i8 [[A]], 5
127 ; CHECK-NEXT: [[R:%.*]] = sdiv i8 [[EXTRA_USE_OF_A]], [[B]]
128 ; CHECK-NEXT: ret i8 [[R]]
132 %extra_use_of_a = mul i8 %a, 5
133 %r = sdiv i8 %extra_use_of_a, %b
137 ;; (A >> 3) << 4 === (A & -8) * 2
138 define i8 @test13(i8 %x) {
139 ; CHECK-LABEL: @test13(
140 ; CHECK-NEXT: [[TMP1:%.*]] = mul i8 [[X:%.*]], 6
141 ; CHECK-NEXT: [[C:%.*]] = and i8 [[TMP1]], -16
142 ; CHECK-NEXT: ret i8 [[C]]
150 define i8 @test13a(i8 %A) {
151 ; CHECK-LABEL: @test13a(
152 ; CHECK-NEXT: [[C:%.*]] = mul i8 [[A:%.*]], 6
153 ; CHECK-NEXT: ret i8 [[C]]
156 %B = ashr exact i8 %a, 3
161 ;; D = ((B | 1234) << 4) === ((B << 4)|(1234 << 4)
162 define i32 @test14(i32 %A) {
163 ; CHECK-LABEL: @test14(
164 ; CHECK-NEXT: [[B:%.*]] = and i32 [[A:%.*]], -19760
165 ; CHECK-NEXT: [[C:%.*]] = or i32 [[B]], 19744
166 ; CHECK-NEXT: ret i32 [[C]]
174 ;; D = ((B | 1234) << 4) === ((B << 4)|(1234 << 4)
175 define i32 @test14a(i32 %A) {
176 ; CHECK-LABEL: @test14a(
177 ; CHECK-NEXT: [[C:%.*]] = and i32 [[A:%.*]], 77
178 ; CHECK-NEXT: ret i32 [[C]]
181 %C = and i32 %B, 1234
186 define i32 @test15(i1 %C) {
187 ; CHECK-LABEL: @test15(
188 ; CHECK-NEXT: [[A:%.*]] = select i1 [[C:%.*]], i32 12, i32 4
189 ; CHECK-NEXT: ret i32 [[A]]
191 %A = select i1 %C, i32 3, i32 1
196 define i32 @test15a(i1 %C) {
197 ; CHECK-LABEL: @test15a(
198 ; CHECK-NEXT: [[V:%.*]] = select i1 [[C:%.*]], i32 512, i32 128
199 ; CHECK-NEXT: ret i32 [[V]]
201 %A = select i1 %C, i8 3, i8 1
202 %shift.upgrd.4 = zext i8 %A to i32
203 %V = shl i32 64, %shift.upgrd.4
207 define i1 @test16(i32 %X) {
208 ; CHECK-LABEL: @test16(
209 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], 16
210 ; CHECK-NEXT: [[I_7:%.*]] = icmp ne i32 [[TMP1]], 0
211 ; CHECK-NEXT: ret i1 [[I_7]]
213 %i.3 = ashr i32 %X, 4
214 %i.6 = and i32 %i.3, 1
215 %i.7 = icmp ne i32 %i.6, 0
219 define i1 @test17(i32 %A) {
220 ; CHECK-LABEL: @test17(
221 ; CHECK-NEXT: [[B_MASK:%.*]] = and i32 [[A:%.*]], -8
222 ; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[B_MASK]], 9872
223 ; CHECK-NEXT: ret i1 [[C]]
226 %C = icmp eq i32 %B, 1234
230 define <2 x i1> @test17vec(<2 x i32> %A) {
231 ; CHECK-LABEL: @test17vec(
232 ; CHECK-NEXT: [[B_MASK:%.*]] = and <2 x i32> [[A:%.*]], <i32 -8, i32 -8>
233 ; CHECK-NEXT: [[C:%.*]] = icmp eq <2 x i32> [[B_MASK]], <i32 9872, i32 9872>
234 ; CHECK-NEXT: ret <2 x i1> [[C]]
236 %B = lshr <2 x i32> %A, <i32 3, i32 3>
237 %C = icmp eq <2 x i32> %B, <i32 1234, i32 1234>
241 define i1 @test18(i8 %A) {
242 ; CHECK-LABEL: @test18(
243 ; CHECK-NEXT: ret i1 false
247 %C = icmp eq i8 %B, 123
251 define i1 @test19(i32 %A) {
252 ; CHECK-LABEL: @test19(
253 ; CHECK-NEXT: [[C:%.*]] = icmp ult i32 [[A:%.*]], 4
254 ; CHECK-NEXT: ret i1 [[C]]
258 %C = icmp eq i32 %B, 0
262 define <2 x i1> @test19vec(<2 x i32> %A) {
263 ; CHECK-LABEL: @test19vec(
264 ; CHECK-NEXT: [[C:%.*]] = icmp ult <2 x i32> [[A:%.*]], <i32 4, i32 4>
265 ; CHECK-NEXT: ret <2 x i1> [[C]]
267 %B = ashr <2 x i32> %A, <i32 2, i32 2>
268 %C = icmp eq <2 x i32> %B, zeroinitializer
273 define i1 @test19a(i32 %A) {
274 ; CHECK-LABEL: @test19a(
275 ; CHECK-NEXT: [[C:%.*]] = icmp ugt i32 [[A:%.*]], -5
276 ; CHECK-NEXT: ret i1 [[C]]
279 %C = icmp eq i32 %B, -1
283 define <2 x i1> @test19a_vec(<2 x i32> %A) {
284 ; CHECK-LABEL: @test19a_vec(
285 ; CHECK-NEXT: [[C:%.*]] = icmp ugt <2 x i32> [[A:%.*]], <i32 -5, i32 -5>
286 ; CHECK-NEXT: ret <2 x i1> [[C]]
288 %B = ashr <2 x i32> %A, <i32 2, i32 2>
289 %C = icmp eq <2 x i32> %B, <i32 -1, i32 -1>
293 define i1 @test20(i8 %A) {
294 ; CHECK-LABEL: @test20(
295 ; CHECK-NEXT: ret i1 false
299 %C = icmp eq i8 %B, 123
303 define i1 @test21(i8 %A) {
304 ; CHECK-LABEL: @test21(
305 ; CHECK-NEXT: [[B_MASK:%.*]] = and i8 [[A:%.*]], 15
306 ; CHECK-NEXT: [[C:%.*]] = icmp eq i8 [[B_MASK]], 8
307 ; CHECK-NEXT: ret i1 [[C]]
310 %C = icmp eq i8 %B, -128
314 define i1 @test22(i8 %A) {
315 ; CHECK-LABEL: @test22(
316 ; CHECK-NEXT: [[B_MASK:%.*]] = and i8 [[A:%.*]], 15
317 ; CHECK-NEXT: [[C:%.*]] = icmp eq i8 [[B_MASK]], 0
318 ; CHECK-NEXT: ret i1 [[C]]
321 %C = icmp eq i8 %B, 0
325 define i8 @test23(i32 %A) {
326 ; CHECK-LABEL: @test23(
327 ; CHECK-NEXT: [[D:%.*]] = trunc i32 [[A:%.*]] to i8
328 ; CHECK-NEXT: ret i8 [[D]]
333 %D = trunc i32 %C to i8
337 define i8 @test24(i8 %X) {
338 ; CHECK-LABEL: @test24(
339 ; CHECK-NEXT: [[Z:%.*]] = and i8 [[X:%.*]], 3
340 ; CHECK-NEXT: ret i8 [[Z]]
348 define i32 @test25(i32 %i.2, i32 %AA) {
349 ; CHECK-LABEL: @test25(
350 ; CHECK-NEXT: [[I_3:%.*]] = and i32 [[I_2:%.*]], -131072
351 ; CHECK-NEXT: [[X2:%.*]] = add i32 [[I_3]], [[AA:%.*]]
352 ; CHECK-NEXT: [[I_6:%.*]] = and i32 [[X2]], -131072
353 ; CHECK-NEXT: ret i32 [[I_6]]
355 %x = lshr i32 %AA, 17
356 %i.3 = lshr i32 %i.2, 17
357 %i.5 = add i32 %i.3, %x
358 %i.6 = shl i32 %i.5, 17
362 define <2 x i32> @test25_vector(<2 x i32> %i.2, <2 x i32> %AA) {
363 ; CHECK-LABEL: @test25_vector(
364 ; CHECK-NEXT: [[I_3:%.*]] = and <2 x i32> [[I_2:%.*]], <i32 -131072, i32 -131072>
365 ; CHECK-NEXT: [[X2:%.*]] = add <2 x i32> [[I_3]], [[AA:%.*]]
366 ; CHECK-NEXT: [[I_6:%.*]] = and <2 x i32> [[X2]], <i32 -131072, i32 -131072>
367 ; CHECK-NEXT: ret <2 x i32> [[I_6]]
369 %x = lshr <2 x i32> %AA, <i32 17, i32 17>
370 %i.3 = lshr <2 x i32> %i.2, <i32 17, i32 17>
371 %i.5 = add <2 x i32> %i.3, %x
372 %i.6 = shl <2 x i32> %i.5, <i32 17, i32 17>
376 ;; handle casts between shifts.
377 define i32 @test26(i32 %A) {
378 ; CHECK-LABEL: @test26(
379 ; CHECK-NEXT: [[B:%.*]] = and i32 [[A:%.*]], -2
380 ; CHECK-NEXT: ret i32 [[B]]
383 %C = bitcast i32 %B to i32
389 define i1 @test27(i32 %x) nounwind {
390 ; CHECK-LABEL: @test27(
391 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], 8
392 ; CHECK-NEXT: [[Z:%.*]] = icmp ne i32 [[TMP1]], 0
393 ; CHECK-NEXT: ret i1 [[Z]]
396 %z = trunc i32 %y to i1
400 define i1 @test28(i8 %x) {
401 ; CHECK-LABEL: @test28(
402 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[X:%.*]], 0
403 ; CHECK-NEXT: ret i1 [[CMP]]
406 %cmp = icmp ne i8 %shr, 0
410 define <2 x i1> @test28vec(<2 x i8> %x) {
411 ; CHECK-LABEL: @test28vec(
412 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i8> [[X:%.*]], zeroinitializer
413 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
415 %shr = lshr <2 x i8> %x, <i8 7, i8 7>
416 %cmp = icmp ne <2 x i8> %shr, zeroinitializer
420 define i8 @test28a(i8 %x, i8 %y) {
421 ; CHECK-LABEL: @test28a(
423 ; CHECK-NEXT: [[I1:%.*]] = lshr i8 [[X:%.*]], 7
424 ; CHECK-NEXT: [[COND1_NOT:%.*]] = icmp sgt i8 [[X]], -1
425 ; CHECK-NEXT: br i1 [[COND1_NOT]], label [[BB2:%.*]], label [[BB1:%.*]]
427 ; CHECK-NEXT: ret i8 [[I1]]
429 ; CHECK-NEXT: [[I2:%.*]] = add i8 [[I1]], [[Y:%.*]]
430 ; CHECK-NEXT: ret i8 [[I2]]
433 ; This shouldn't be transformed.
435 %cond1 = icmp ne i8 %i1, 0
436 br i1 %cond1, label %bb1, label %bb2
444 define i32 @test29(i64 %d18) {
445 ; CHECK-LABEL: @test29(
447 ; CHECK-NEXT: [[I916:%.*]] = lshr i64 [[D18:%.*]], 63
448 ; CHECK-NEXT: [[I10:%.*]] = trunc i64 [[I916]] to i32
449 ; CHECK-NEXT: ret i32 [[I10]]
452 %i916 = lshr i64 %d18, 32
453 %i917 = trunc i64 %i916 to i32
454 %i10 = lshr i32 %i917, 31
458 define <2 x i32> @test29_uniform(<2 x i64> %d18) {
459 ; CHECK-LABEL: @test29_uniform(
461 ; CHECK-NEXT: [[I916:%.*]] = lshr <2 x i64> [[D18:%.*]], <i64 63, i64 63>
462 ; CHECK-NEXT: [[I10:%.*]] = trunc <2 x i64> [[I916]] to <2 x i32>
463 ; CHECK-NEXT: ret <2 x i32> [[I10]]
466 %i916 = lshr <2 x i64> %d18, <i64 32, i64 32>
467 %i917 = trunc <2 x i64> %i916 to <2 x i32>
468 %i10 = lshr <2 x i32> %i917, <i32 31, i32 31>
472 define <2 x i32> @test29_nonuniform(<2 x i64> %d18) {
473 ; CHECK-LABEL: @test29_nonuniform(
475 ; CHECK-NEXT: [[I916:%.*]] = lshr <2 x i64> [[D18:%.*]], <i64 32, i64 15>
476 ; CHECK-NEXT: [[I917:%.*]] = trunc <2 x i64> [[I916]] to <2 x i32>
477 ; CHECK-NEXT: [[I10:%.*]] = lshr <2 x i32> [[I917]], <i32 31, i32 22>
478 ; CHECK-NEXT: ret <2 x i32> [[I10]]
481 %i916 = lshr <2 x i64> %d18, <i64 32, i64 15>
482 %i917 = trunc <2 x i64> %i916 to <2 x i32>
483 %i10 = lshr <2 x i32> %i917, <i32 31, i32 22>
487 define <2 x i32> @test29_undef(<2 x i64> %d18) {
488 ; CHECK-LABEL: @test29_undef(
490 ; CHECK-NEXT: [[I916:%.*]] = lshr <2 x i64> [[D18:%.*]], <i64 32, i64 undef>
491 ; CHECK-NEXT: [[I917:%.*]] = trunc <2 x i64> [[I916]] to <2 x i32>
492 ; CHECK-NEXT: [[I10:%.*]] = lshr <2 x i32> [[I917]], <i32 31, i32 undef>
493 ; CHECK-NEXT: ret <2 x i32> [[I10]]
496 %i916 = lshr <2 x i64> %d18, <i64 32, i64 undef>
497 %i917 = trunc <2 x i64> %i916 to <2 x i32>
498 %i10 = lshr <2 x i32> %i917, <i32 31, i32 undef>
502 define i32 @test30(i32 %A, i32 %B, i32 %C) {
503 ; CHECK-LABEL: @test30(
504 ; CHECK-NEXT: [[X1:%.*]] = and i32 [[A:%.*]], [[B:%.*]]
505 ; CHECK-NEXT: [[Z:%.*]] = shl i32 [[X1]], [[C:%.*]]
506 ; CHECK-NEXT: ret i32 [[Z]]
514 define i32 @test31(i32 %A, i32 %B, i32 %C) {
515 ; CHECK-LABEL: @test31(
516 ; CHECK-NEXT: [[X1:%.*]] = or i32 [[A:%.*]], [[B:%.*]]
517 ; CHECK-NEXT: [[Z:%.*]] = lshr i32 [[X1]], [[C:%.*]]
518 ; CHECK-NEXT: ret i32 [[Z]]
526 define i32 @test32(i32 %A, i32 %B, i32 %C) {
527 ; CHECK-LABEL: @test32(
528 ; CHECK-NEXT: [[X1:%.*]] = xor i32 [[A:%.*]], [[B:%.*]]
529 ; CHECK-NEXT: [[Z:%.*]] = ashr i32 [[X1]], [[C:%.*]]
530 ; CHECK-NEXT: ret i32 [[Z]]
538 define i1 @test33(i32 %X) {
539 ; CHECK-LABEL: @test33(
540 ; CHECK-NEXT: [[I1_MASK:%.*]] = and i32 [[X:%.*]], 16777216
541 ; CHECK-NEXT: [[I2:%.*]] = icmp ne i32 [[I1_MASK]], 0
542 ; CHECK-NEXT: ret i1 [[I2]]
545 %i2 = icmp slt i32 %i1, 0
549 define <2 x i1> @test33vec(<2 x i32> %X) {
550 ; CHECK-LABEL: @test33vec(
551 ; CHECK-NEXT: [[I1_MASK:%.*]] = and <2 x i32> [[X:%.*]], <i32 16777216, i32 16777216>
552 ; CHECK-NEXT: [[I2:%.*]] = icmp ne <2 x i32> [[I1_MASK]], zeroinitializer
553 ; CHECK-NEXT: ret <2 x i1> [[I2]]
555 %i1 = shl <2 x i32> %X, <i32 7, i32 7>
556 %i2 = icmp slt <2 x i32> %i1, zeroinitializer
560 define i1 @test34(i32 %X) {
561 ; CHECK-LABEL: @test34(
562 ; CHECK-NEXT: ret i1 false
565 %i2 = icmp slt i32 %i1, 0
569 define i1 @test35(i32 %X) {
570 ; CHECK-LABEL: @test35(
571 ; CHECK-NEXT: [[I2:%.*]] = icmp slt i32 [[X:%.*]], 0
572 ; CHECK-NEXT: ret i1 [[I2]]
575 %i2 = icmp slt i32 %i1, 0
579 define <2 x i1> @test35vec(<2 x i32> %X) {
580 ; CHECK-LABEL: @test35vec(
581 ; CHECK-NEXT: [[I2:%.*]] = icmp slt <2 x i32> [[X:%.*]], zeroinitializer
582 ; CHECK-NEXT: ret <2 x i1> [[I2]]
584 %i1 = ashr <2 x i32> %X, <i32 7, i32 7>
585 %i2 = icmp slt <2 x i32> %i1, zeroinitializer
589 define i128 @test36(i128 %A, i128 %B) {
590 ; CHECK-LABEL: @test36(
591 ; CHECK-NEXT: [[I231:%.*]] = or i128 [[B:%.*]], [[A:%.*]]
592 ; CHECK-NEXT: [[INS:%.*]] = and i128 [[I231]], 18446744073709551615
593 ; CHECK-NEXT: ret i128 [[INS]]
595 %i27 = shl i128 %A, 64
596 %i23 = shl i128 %B, 64
597 %ins = or i128 %i23, %i27
598 %i45 = lshr i128 %ins, 64
602 define i64 @test37(i128 %A, i32 %B) {
603 ; CHECK-LABEL: @test37(
604 ; CHECK-NEXT: [[I22:%.*]] = zext i32 [[B:%.*]] to i128
605 ; CHECK-NEXT: [[I23:%.*]] = shl nuw nsw i128 [[I22]], 32
606 ; CHECK-NEXT: [[INS:%.*]] = or i128 [[I23]], [[A:%.*]]
607 ; CHECK-NEXT: [[I46:%.*]] = trunc i128 [[INS]] to i64
608 ; CHECK-NEXT: ret i64 [[I46]]
610 %i27 = shl i128 %A, 64
611 %i22 = zext i32 %B to i128
612 %i23 = shl i128 %i22, 96
613 %ins = or i128 %i23, %i27
614 %i45 = lshr i128 %ins, 64
615 %i46 = trunc i128 %i45 to i64
619 define <2 x i32> @shl_nuw_nsw_splat_vec(<2 x i8> %x) {
620 ; CHECK-LABEL: @shl_nuw_nsw_splat_vec(
621 ; CHECK-NEXT: [[T2:%.*]] = zext <2 x i8> [[X:%.*]] to <2 x i32>
622 ; CHECK-NEXT: [[T3:%.*]] = shl nuw nsw <2 x i32> [[T2]], <i32 17, i32 17>
623 ; CHECK-NEXT: ret <2 x i32> [[T3]]
625 %t2 = zext <2 x i8> %x to <2 x i32>
626 %t3 = shl <2 x i32> %t2, <i32 17, i32 17>
630 define i32 @test38(i32 %x) nounwind readnone {
631 ; CHECK-LABEL: @test38(
632 ; CHECK-NEXT: [[REM1:%.*]] = and i32 [[X:%.*]], 31
633 ; CHECK-NEXT: [[SHL:%.*]] = shl i32 1, [[REM1]]
634 ; CHECK-NEXT: ret i32 [[SHL]]
636 %rem = srem i32 %x, 32
637 %shl = shl i32 1, %rem
641 define <2 x i32> @test38_uniform(<2 x i32> %x) nounwind readnone {
642 ; CHECK-LABEL: @test38_uniform(
643 ; CHECK-NEXT: [[REM1:%.*]] = and <2 x i32> [[X:%.*]], <i32 31, i32 31>
644 ; CHECK-NEXT: [[SHL:%.*]] = shl <2 x i32> <i32 1, i32 1>, [[REM1]]
645 ; CHECK-NEXT: ret <2 x i32> [[SHL]]
647 %rem = srem <2 x i32> %x, <i32 32, i32 32>
648 %shl = shl <2 x i32> <i32 1, i32 1>, %rem
652 define <3 x i32> @test38_nonuniform(<3 x i32> %x) nounwind readnone {
653 ; CHECK-LABEL: @test38_nonuniform(
654 ; CHECK-NEXT: [[REM1:%.*]] = and <3 x i32> [[X:%.*]], <i32 31, i32 15, i32 0>
655 ; CHECK-NEXT: [[SHL:%.*]] = shl <3 x i32> <i32 1, i32 1, i32 1>, [[REM1]]
656 ; CHECK-NEXT: ret <3 x i32> [[SHL]]
658 %rem = srem <3 x i32> %x, <i32 32, i32 16, i32 1>
659 %shl = shl <3 x i32> <i32 1, i32 1, i32 1>, %rem
663 define <2 x i32> @test38_undef(<2 x i32> %x) nounwind readnone {
664 ; CHECK-LABEL: @test38_undef(
665 ; CHECK-NEXT: ret <2 x i32> poison
667 %rem = srem <2 x i32> %x, <i32 32, i32 undef>
668 %shl = shl <2 x i32> <i32 1, i32 1>, %rem
672 ; <rdar://problem/8756731>
673 define i8 @test39(i32 %a0) {
674 ; CHECK-LABEL: @test39(
676 ; CHECK-NEXT: [[I4:%.*]] = trunc i32 [[A0:%.*]] to i8
677 ; CHECK-NEXT: [[I5:%.*]] = shl i8 [[I4]], 5
678 ; CHECK-NEXT: [[I49:%.*]] = shl i8 [[I4]], 6
679 ; CHECK-NEXT: [[I50:%.*]] = and i8 [[I49]], 64
680 ; CHECK-NEXT: [[I51:%.*]] = xor i8 [[I50]], [[I5]]
681 ; CHECK-NEXT: [[TMP0:%.*]] = shl i8 [[I4]], 2
682 ; CHECK-NEXT: [[I54:%.*]] = and i8 [[TMP0]], 16
683 ; CHECK-NEXT: [[I551:%.*]] = or i8 [[I54]], [[I51]]
684 ; CHECK-NEXT: ret i8 [[I551]]
687 %i4 = trunc i32 %a0 to i8
689 %i48 = and i8 %i5, 32
690 %i49 = lshr i8 %i48, 5
691 %i50 = mul i8 %i49, 64
692 %i51 = xor i8 %i50, %i5
693 %i52 = and i8 %i51, -128
694 %i53 = lshr i8 %i52, 7
695 %i54 = mul i8 %i53, 16
696 %i55 = xor i8 %i54, %i51
701 define i32 @test40(i32 %a, i32 %b) nounwind {
702 ; CHECK-LABEL: @test40(
703 ; CHECK-NEXT: [[TMP1:%.*]] = add i32 [[B:%.*]], 2
704 ; CHECK-NEXT: [[DIV:%.*]] = lshr i32 [[A:%.*]], [[TMP1]]
705 ; CHECK-NEXT: ret i32 [[DIV]]
707 %shl1 = shl i32 1, %b
708 %shl2 = shl i32 %shl1, 2
709 %div = udiv i32 %a, %shl2
713 define i32 @test41(i32 %a, i32 %b) nounwind {
714 ; CHECK-LABEL: @test41(
715 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 8, [[B:%.*]]
716 ; CHECK-NEXT: ret i32 [[TMP1]]
723 define i32 @test42(i32 %a, i32 %b) nounwind {
724 ; CHECK-LABEL: @test42(
725 ; CHECK-NEXT: [[DIV:%.*]] = lshr exact i32 4096, [[B:%.*]]
726 ; CHECK-NEXT: [[DIV2:%.*]] = udiv i32 [[A:%.*]], [[DIV]]
727 ; CHECK-NEXT: ret i32 [[DIV2]]
729 %div = lshr i32 4096, %b ; must be exact otherwise we'd divide by zero
730 %div2 = udiv i32 %a, %div
734 define <2 x i32> @test42vec(<2 x i32> %a, <2 x i32> %b) {
735 ; CHECK-LABEL: @test42vec(
736 ; CHECK-NEXT: [[DIV:%.*]] = lshr exact <2 x i32> <i32 4096, i32 4096>, [[B:%.*]]
737 ; CHECK-NEXT: [[DIV2:%.*]] = udiv <2 x i32> [[A:%.*]], [[DIV]]
738 ; CHECK-NEXT: ret <2 x i32> [[DIV2]]
740 %div = lshr <2 x i32> <i32 4096, i32 4096>, %b ; must be exact otherwise we'd divide by zero
741 %div2 = udiv <2 x i32> %a, %div
745 define i32 @test43(i32 %a, i32 %b) nounwind {
746 ; CHECK-LABEL: @test43(
747 ; CHECK-NEXT: [[TMP1:%.*]] = add i32 [[B:%.*]], 12
748 ; CHECK-NEXT: [[DIV2:%.*]] = lshr i32 [[A:%.*]], [[TMP1]]
749 ; CHECK-NEXT: ret i32 [[DIV2]]
751 %div = shl i32 4096, %b ; must be exact otherwise we'd divide by zero
752 %div2 = udiv i32 %a, %div
756 define i32 @test44(i32 %a) nounwind {
757 ; CHECK-LABEL: @test44(
758 ; CHECK-NEXT: [[Y:%.*]] = shl i32 [[A:%.*]], 5
759 ; CHECK-NEXT: ret i32 [[Y]]
761 %y = shl nuw i32 %a, 1
766 define i32 @test45(i32 %a) nounwind {
767 ; CHECK-LABEL: @test45(
768 ; CHECK-NEXT: [[Y:%.*]] = lshr i32 [[A:%.*]], 5
769 ; CHECK-NEXT: ret i32 [[Y]]
771 %y = lshr exact i32 %a, 1
776 ; (X >>?exact C1) << C2 --> X >>?exact (C1-C2)
778 define i32 @test46(i32 %a) {
779 ; CHECK-LABEL: @test46(
780 ; CHECK-NEXT: [[Z:%.*]] = ashr exact i32 [[A:%.*]], 2
781 ; CHECK-NEXT: ret i32 [[Z]]
783 %y = ashr exact i32 %a, 3
788 ; (X >>?exact C1) << C2 --> X >>?exact (C1-C2)
790 define <2 x i32> @test46_splat_vec(<2 x i32> %a) {
791 ; CHECK-LABEL: @test46_splat_vec(
792 ; CHECK-NEXT: [[Z:%.*]] = ashr exact <2 x i32> [[A:%.*]], <i32 2, i32 2>
793 ; CHECK-NEXT: ret <2 x i32> [[Z]]
795 %y = ashr exact <2 x i32> %a, <i32 3, i32 3>
796 %z = shl <2 x i32> %y, <i32 1, i32 1>
800 ; (X >>?exact C1) << C2 --> X >>?exact (C1-C2)
802 define i8 @test47(i8 %a) {
803 ; CHECK-LABEL: @test47(
804 ; CHECK-NEXT: [[Z:%.*]] = lshr exact i8 [[A:%.*]], 2
805 ; CHECK-NEXT: ret i8 [[Z]]
807 %y = lshr exact i8 %a, 3
812 ; (X >>?exact C1) << C2 --> X >>?exact (C1-C2)
814 define <2 x i8> @test47_splat_vec(<2 x i8> %a) {
815 ; CHECK-LABEL: @test47_splat_vec(
816 ; CHECK-NEXT: [[Z:%.*]] = lshr exact <2 x i8> [[A:%.*]], <i8 2, i8 2>
817 ; CHECK-NEXT: ret <2 x i8> [[Z]]
819 %y = lshr exact <2 x i8> %a, <i8 3, i8 3>
820 %z = shl <2 x i8> %y, <i8 1, i8 1>
824 ; (X >>u,exact C1) << C2 --> X << (C2-C1) when C2 > C1
826 define i32 @test48(i32 %x) {
827 ; CHECK-LABEL: @test48(
828 ; CHECK-NEXT: [[B:%.*]] = shl i32 [[X:%.*]], 2
829 ; CHECK-NEXT: ret i32 [[B]]
831 %A = lshr exact i32 %x, 1
836 ; Verify that wrap flags are preserved from the original 'shl'.
838 define i32 @test48_nuw_nsw(i32 %x) {
839 ; CHECK-LABEL: @test48_nuw_nsw(
840 ; CHECK-NEXT: [[B:%.*]] = shl nuw nsw i32 [[X:%.*]], 2
841 ; CHECK-NEXT: ret i32 [[B]]
843 %A = lshr exact i32 %x, 1
844 %B = shl nuw nsw i32 %A, 3
848 ; (X >>u,exact C1) << C2 --> X << (C2-C1) when splatted C2 > C1
850 define <2 x i32> @test48_splat_vec(<2 x i32> %x) {
851 ; CHECK-LABEL: @test48_splat_vec(
852 ; CHECK-NEXT: [[B:%.*]] = shl nuw nsw <2 x i32> [[X:%.*]], <i32 2, i32 2>
853 ; CHECK-NEXT: ret <2 x i32> [[B]]
855 %A = lshr exact <2 x i32> %x, <i32 1, i32 1>
856 %B = shl nsw nuw <2 x i32> %A, <i32 3, i32 3>
860 ; (X >>s,exact C1) << C2 --> X << (C2-C1) when C2 > C1
862 define i32 @test49(i32 %x) {
863 ; CHECK-LABEL: @test49(
864 ; CHECK-NEXT: [[B:%.*]] = shl i32 [[X:%.*]], 2
865 ; CHECK-NEXT: ret i32 [[B]]
867 %A = ashr exact i32 %x, 1
872 ; Verify that wrap flags are preserved from the original 'shl'.
874 define i32 @test49_nuw_nsw(i32 %x) {
875 ; CHECK-LABEL: @test49_nuw_nsw(
876 ; CHECK-NEXT: [[B:%.*]] = shl nuw nsw i32 [[X:%.*]], 2
877 ; CHECK-NEXT: ret i32 [[B]]
879 %A = ashr exact i32 %x, 1
880 %B = shl nuw nsw i32 %A, 3
884 ; (X >>s,exact C1) << C2 --> X << (C2-C1) when splatted C2 > C1
886 define <2 x i32> @test49_splat_vec(<2 x i32> %x) {
887 ; CHECK-LABEL: @test49_splat_vec(
888 ; CHECK-NEXT: [[B:%.*]] = shl nuw nsw <2 x i32> [[X:%.*]], <i32 2, i32 2>
889 ; CHECK-NEXT: ret <2 x i32> [[B]]
891 %A = ashr exact <2 x i32> %x, <i32 1, i32 1>
892 %B = shl nsw nuw <2 x i32> %A, <i32 3, i32 3>
896 ; (X <<nsw C1) >>s C2 --> X >>s (C2-C1)
898 define i32 @test50(i32 %x) {
899 ; CHECK-LABEL: @test50(
900 ; CHECK-NEXT: [[B:%.*]] = ashr i32 [[X:%.*]], 2
901 ; CHECK-NEXT: ret i32 [[B]]
903 %A = shl nsw i32 %x, 1
908 ; (X <<nsw C1) >>s C2 --> X >>s (C2-C1)
909 ; Also, check that exact is propagated.
911 define <2 x i32> @test50_splat_vec(<2 x i32> %x) {
912 ; CHECK-LABEL: @test50_splat_vec(
913 ; CHECK-NEXT: [[B:%.*]] = ashr exact <2 x i32> [[X:%.*]], <i32 2, i32 2>
914 ; CHECK-NEXT: ret <2 x i32> [[B]]
916 %A = shl nsw <2 x i32> %x, <i32 1, i32 1>
917 %B = ashr exact <2 x i32> %A, <i32 3, i32 3>
921 ; (X <<nuw C1) >>u C2 --> X >>u (C2-C1)
923 define i32 @test51(i32 %x) {
924 ; CHECK-LABEL: @test51(
925 ; CHECK-NEXT: [[B:%.*]] = lshr i32 [[X:%.*]], 2
926 ; CHECK-NEXT: ret i32 [[B]]
928 %A = shl nuw i32 %x, 1
933 ; (X <<nuw C1) >>u C2 --> X >>u (C2-C1) with splats
934 ; Also, check that exact is propagated.
936 define <2 x i32> @test51_splat_vec(<2 x i32> %x) {
937 ; CHECK-LABEL: @test51_splat_vec(
938 ; CHECK-NEXT: [[B:%.*]] = lshr exact <2 x i32> [[X:%.*]], <i32 2, i32 2>
939 ; CHECK-NEXT: ret <2 x i32> [[B]]
941 %A = shl nuw <2 x i32> %x, <i32 1, i32 1>
942 %B = lshr exact <2 x i32> %A, <i32 3, i32 3>
946 ; (X << C1) >>u C2 --> X >>u (C2-C1) & (-1 >> C2)
947 ; Also, check that exact is propagated.
949 define i32 @test51_no_nuw(i32 %x) {
950 ; CHECK-LABEL: @test51_no_nuw(
951 ; CHECK-NEXT: [[TMP1:%.*]] = lshr exact i32 [[X:%.*]], 2
952 ; CHECK-NEXT: [[B:%.*]] = and i32 [[TMP1]], 536870911
953 ; CHECK-NEXT: ret i32 [[B]]
956 %B = lshr exact i32 %A, 3
960 ; (X << C1) >>u C2 --> X >>u (C2-C1) & (-1 >> C2)
962 define <2 x i32> @test51_no_nuw_splat_vec(<2 x i32> %x) {
963 ; CHECK-LABEL: @test51_no_nuw_splat_vec(
964 ; CHECK-NEXT: [[TMP1:%.*]] = lshr <2 x i32> [[X:%.*]], <i32 2, i32 2>
965 ; CHECK-NEXT: [[B:%.*]] = and <2 x i32> [[TMP1]], <i32 536870911, i32 536870911>
966 ; CHECK-NEXT: ret <2 x i32> [[B]]
968 %A = shl <2 x i32> %x, <i32 1, i32 1>
969 %B = lshr <2 x i32> %A, <i32 3, i32 3>
973 ; (X <<nsw C1) >>s C2 --> X <<nsw (C1 - C2)
975 define i32 @test52(i32 %x) {
976 ; CHECK-LABEL: @test52(
977 ; CHECK-NEXT: [[B:%.*]] = shl nsw i32 [[X:%.*]], 2
978 ; CHECK-NEXT: ret i32 [[B]]
980 %A = shl nsw i32 %x, 3
985 ; (X <<nsw C1) >>s C2 --> X <<nsw (C1 - C2)
987 define <2 x i32> @test52_splat_vec(<2 x i32> %x) {
988 ; CHECK-LABEL: @test52_splat_vec(
989 ; CHECK-NEXT: [[B:%.*]] = shl nsw <2 x i32> [[X:%.*]], <i32 2, i32 2>
990 ; CHECK-NEXT: ret <2 x i32> [[B]]
992 %A = shl nsw <2 x i32> %x, <i32 3, i32 3>
993 %B = ashr <2 x i32> %A, <i32 1, i32 1>
997 ; (X <<nuw C1) >>u C2 --> X <<nuw (C1 - C2)
999 define i32 @test53(i32 %x) {
1000 ; CHECK-LABEL: @test53(
1001 ; CHECK-NEXT: [[B:%.*]] = shl nuw i32 [[X:%.*]], 2
1002 ; CHECK-NEXT: ret i32 [[B]]
1004 %A = shl nuw i32 %x, 3
1009 ; (X <<nuw C1) >>u C2 --> X <<nuw (C1 - C2)
1011 define <2 x i32> @test53_splat_vec(<2 x i32> %x) {
1012 ; CHECK-LABEL: @test53_splat_vec(
1013 ; CHECK-NEXT: [[B:%.*]] = shl nuw <2 x i32> [[X:%.*]], <i32 2, i32 2>
1014 ; CHECK-NEXT: ret <2 x i32> [[B]]
1016 %A = shl nuw <2 x i32> %x, <i32 3, i32 3>
1017 %B = lshr <2 x i32> %A, <i32 1, i32 1>
1021 ; (X << C1) >>u C2 --> X << (C1 - C2) & (-1 >> C2)
1023 define i8 @test53_no_nuw(i8 %x) {
1024 ; CHECK-LABEL: @test53_no_nuw(
1025 ; CHECK-NEXT: [[TMP1:%.*]] = shl i8 [[X:%.*]], 2
1026 ; CHECK-NEXT: [[B:%.*]] = and i8 [[TMP1]], 124
1027 ; CHECK-NEXT: ret i8 [[B]]
1034 ; (X << C1) >>u C2 --> X << (C1 - C2) & (-1 >> C2)
1036 define <2 x i8> @test53_no_nuw_splat_vec(<2 x i8> %x) {
1037 ; CHECK-LABEL: @test53_no_nuw_splat_vec(
1038 ; CHECK-NEXT: [[TMP1:%.*]] = shl <2 x i8> [[X:%.*]], <i8 2, i8 2>
1039 ; CHECK-NEXT: [[B:%.*]] = and <2 x i8> [[TMP1]], <i8 124, i8 124>
1040 ; CHECK-NEXT: ret <2 x i8> [[B]]
1042 %A = shl <2 x i8> %x, <i8 3, i8 3>
1043 %B = lshr <2 x i8> %A, <i8 1, i8 1>
1047 define i32 @test54(i32 %x) {
1048 ; CHECK-LABEL: @test54(
1049 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 3
1050 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[TMP1]], 16
1051 ; CHECK-NEXT: ret i32 [[AND]]
1053 %shr2 = lshr i32 %x, 1
1054 %shl = shl i32 %shr2, 4
1055 %and = and i32 %shl, 16
1059 define <2 x i32> @test54_splat_vec(<2 x i32> %x) {
1060 ; CHECK-LABEL: @test54_splat_vec(
1061 ; CHECK-NEXT: [[TMP1:%.*]] = shl <2 x i32> [[X:%.*]], <i32 3, i32 3>
1062 ; CHECK-NEXT: [[AND:%.*]] = and <2 x i32> [[TMP1]], <i32 16, i32 16>
1063 ; CHECK-NEXT: ret <2 x i32> [[AND]]
1065 %shr2 = lshr <2 x i32> %x, <i32 1, i32 1>
1066 %shl = shl <2 x i32> %shr2, <i32 4, i32 4>
1067 %and = and <2 x i32> %shl, <i32 16, i32 16>
1071 define i32 @test55(i32 %x) {
1072 ; CHECK-LABEL: @test55(
1073 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 3
1074 ; CHECK-NEXT: [[OR:%.*]] = or i32 [[TMP1]], 8
1075 ; CHECK-NEXT: ret i32 [[OR]]
1077 %shr2 = lshr i32 %x, 1
1078 %shl = shl i32 %shr2, 4
1079 %or = or i32 %shl, 8
1083 define i32 @test56(i32 %x) {
1084 ; CHECK-LABEL: @test56(
1085 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 3
1086 ; CHECK-NEXT: [[SHL:%.*]] = and i32 [[TMP1]], -16
1087 ; CHECK-NEXT: [[OR:%.*]] = or i32 [[SHL]], 7
1088 ; CHECK-NEXT: ret i32 [[OR]]
1090 %shr2 = lshr i32 %x, 1
1091 %shl = shl i32 %shr2, 4
1092 %or = or i32 %shl, 7
1096 define i32 @test57(i32 %x) {
1097 ; CHECK-LABEL: @test57(
1098 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 3
1099 ; CHECK-NEXT: [[SHL:%.*]] = and i32 [[TMP1]], -16
1100 ; CHECK-NEXT: [[OR:%.*]] = or i32 [[SHL]], 7
1101 ; CHECK-NEXT: ret i32 [[OR]]
1103 %shr = ashr i32 %x, 1
1104 %shl = shl i32 %shr, 4
1105 %or = or i32 %shl, 7
1109 define i32 @test58(i32 %x) {
1110 ; CHECK-LABEL: @test58(
1111 ; CHECK-NEXT: [[TMP1:%.*]] = ashr i32 [[X:%.*]], 3
1112 ; CHECK-NEXT: [[OR:%.*]] = or i32 [[TMP1]], 1
1113 ; CHECK-NEXT: ret i32 [[OR]]
1115 %shr = ashr i32 %x, 4
1116 %shl = shl i32 %shr, 1
1117 %or = or i32 %shl, 1
1121 define <2 x i32> @test58_splat_vec(<2 x i32> %x) {
1122 ; CHECK-LABEL: @test58_splat_vec(
1123 ; CHECK-NEXT: [[TMP1:%.*]] = ashr <2 x i32> [[X:%.*]], <i32 3, i32 3>
1124 ; CHECK-NEXT: [[OR:%.*]] = or <2 x i32> [[TMP1]], <i32 1, i32 1>
1125 ; CHECK-NEXT: ret <2 x i32> [[OR]]
1127 %shr = ashr <2 x i32> %x, <i32 4, i32 4>
1128 %shl = shl <2 x i32> %shr, <i32 1, i32 1>
1129 %or = or <2 x i32> %shl, <i32 1, i32 1>
1133 define i32 @test59(i32 %x) {
1134 ; CHECK-LABEL: @test59(
1135 ; CHECK-NEXT: [[TMP1:%.*]] = ashr i32 [[X:%.*]], 3
1136 ; CHECK-NEXT: [[SHL:%.*]] = and i32 [[TMP1]], -4
1137 ; CHECK-NEXT: [[OR:%.*]] = or i32 [[SHL]], 2
1138 ; CHECK-NEXT: ret i32 [[OR]]
1140 %shr = ashr i32 %x, 4
1141 %shl = shl i32 %shr, 1
1142 %or = or i32 %shl, 2
1146 ; propagate "exact" trait
1147 define i32 @test60(i32 %x) {
1148 ; CHECK-LABEL: @test60(
1149 ; CHECK-NEXT: [[SHL:%.*]] = ashr exact i32 [[X:%.*]], 3
1150 ; CHECK-NEXT: [[OR:%.*]] = or i32 [[SHL]], 1
1151 ; CHECK-NEXT: ret i32 [[OR]]
1153 %shr = ashr exact i32 %x, 4
1154 %shl = shl i32 %shr, 1
1155 %or = or i32 %shl, 1
1160 define void @test61(i128 %arg) {
1161 ; CHECK-LABEL: @test61(
1163 ; CHECK-NEXT: br i1 undef, label [[BB1:%.*]], label [[BB12:%.*]]
1165 ; CHECK-NEXT: br label [[BB2:%.*]]
1167 ; CHECK-NEXT: br i1 undef, label [[BB3:%.*]], label [[BB7:%.*]]
1169 ; CHECK-NEXT: br label [[BB8:%.*]]
1171 ; CHECK-NEXT: br i1 undef, label [[BB8]], label [[BB2]]
1173 ; CHECK-NEXT: br i1 undef, label [[BB11:%.*]], label [[BB12]]
1175 ; CHECK-NEXT: br i1 undef, label [[BB1]], label [[BB12]]
1177 ; CHECK-NEXT: ret void
1180 br i1 undef, label %bb1, label %bb12
1182 bb1: ; preds = %bb11, %bb
1185 bb2: ; preds = %bb7, %bb1
1186 br i1 undef, label %bb3, label %bb7
1189 %i = lshr i128 %arg, 36893488147419103232
1190 %i4 = shl i128 %i, 0
1191 %i5 = or i128 %i4, undef
1192 %i6 = trunc i128 %i5 to i16
1196 br i1 undef, label %bb8, label %bb2
1198 bb8: ; preds = %bb7, %bb3
1199 %i9 = phi i16 [ %i6, %bb3 ], [ undef, %bb7 ]
1200 %i10 = icmp eq i16 %i9, 0
1201 br i1 %i10, label %bb11, label %bb12
1203 bb11: ; preds = %bb8
1204 br i1 undef, label %bb1, label %bb12
1206 bb12: ; preds = %bb11, %bb8, %bb
1210 define i32 @test62(i32 %a) {
1211 ; CHECK-LABEL: @test62(
1212 ; CHECK-NEXT: ret i32 poison
1214 %b = ashr i32 %a, 32 ; shift all bits out
1218 define <4 x i32> @test62_splat_vector(<4 x i32> %a) {
1219 ; CHECK-LABEL: @test62_splat_vector(
1220 ; CHECK-NEXT: ret <4 x i32> poison
1222 %b = ashr <4 x i32> %a, <i32 32, i32 32, i32 32, i32 32> ; shift all bits out
1226 define <4 x i32> @test62_non_splat_vector(<4 x i32> %a) {
1227 ; CHECK-LABEL: @test62_non_splat_vector(
1228 ; CHECK-NEXT: [[B:%.*]] = ashr <4 x i32> [[A:%.*]], <i32 32, i32 0, i32 1, i32 2>
1229 ; CHECK-NEXT: ret <4 x i32> [[B]]
1231 %b = ashr <4 x i32> %a, <i32 32, i32 0, i32 1, i32 2> ; shift all bits out
1235 define <2 x i65> @test_63(<2 x i64> %t) {
1236 ; CHECK-LABEL: @test_63(
1237 ; CHECK-NEXT: [[A:%.*]] = zext <2 x i64> [[T:%.*]] to <2 x i65>
1238 ; CHECK-NEXT: [[SEXT:%.*]] = shl <2 x i65> [[A]], <i65 33, i65 33>
1239 ; CHECK-NEXT: [[B:%.*]] = ashr exact <2 x i65> [[SEXT]], <i65 33, i65 33>
1240 ; CHECK-NEXT: ret <2 x i65> [[B]]
1242 %a = zext <2 x i64> %t to <2 x i65>
1243 %sext = shl <2 x i65> %a, <i65 33, i65 33>
1244 %b = ashr <2 x i65> %sext, <i65 33, i65 33>
1248 define i32 @test_shl_zext_bool(i1 %t) {
1249 ; CHECK-LABEL: @test_shl_zext_bool(
1250 ; CHECK-NEXT: [[SHL:%.*]] = select i1 [[T:%.*]], i32 4, i32 0
1251 ; CHECK-NEXT: ret i32 [[SHL]]
1253 %ext = zext i1 %t to i32
1254 %shl = shl i32 %ext, 2
1258 define <2 x i32> @test_shl_zext_bool_splat(<2 x i1> %t) {
1259 ; CHECK-LABEL: @test_shl_zext_bool_splat(
1260 ; CHECK-NEXT: [[SHL:%.*]] = select <2 x i1> [[T:%.*]], <2 x i32> <i32 8, i32 8>, <2 x i32> zeroinitializer
1261 ; CHECK-NEXT: ret <2 x i32> [[SHL]]
1263 %ext = zext <2 x i1> %t to <2 x i32>
1264 %shl = shl <2 x i32> %ext, <i32 3, i32 3>
1268 define <2 x i32> @test_shl_zext_bool_vec(<2 x i1> %t) {
1269 ; CHECK-LABEL: @test_shl_zext_bool_vec(
1270 ; CHECK-NEXT: [[SHL:%.*]] = select <2 x i1> [[T:%.*]], <2 x i32> <i32 4, i32 8>, <2 x i32> zeroinitializer
1271 ; CHECK-NEXT: ret <2 x i32> [[SHL]]
1273 %ext = zext <2 x i1> %t to <2 x i32>
1274 %shl = shl <2 x i32> %ext, <i32 2, i32 3>
1278 define i32 @test_shl_zext_bool_not_constant(i1 %cmp, i32 %shamt) {
1279 ; CHECK-LABEL: @test_shl_zext_bool_not_constant(
1280 ; CHECK-NEXT: [[CONV3:%.*]] = zext i1 [[CMP:%.*]] to i32
1281 ; CHECK-NEXT: [[SHL:%.*]] = shl i32 [[CONV3]], [[SHAMT:%.*]]
1282 ; CHECK-NEXT: ret i32 [[SHL]]
1284 %conv3 = zext i1 %cmp to i32
1285 %shl = shl i32 %conv3, %shamt
1289 define i64 @shl_zext(i32 %t) {
1290 ; CHECK-LABEL: @shl_zext(
1291 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[T:%.*]], 8
1292 ; CHECK-NEXT: [[SHL:%.*]] = zext i32 [[TMP1]] to i64
1293 ; CHECK-NEXT: ret i64 [[SHL]]
1295 %and = and i32 %t, 16777215
1296 %ext = zext i32 %and to i64
1297 %shl = shl i64 %ext, 8
1301 declare void @use(i64)
1303 define i64 @shl_zext_extra_use(i32 %t) {
1304 ; CHECK-LABEL: @shl_zext_extra_use(
1305 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[T:%.*]], 16777215
1306 ; CHECK-NEXT: [[EXT:%.*]] = zext i32 [[AND]] to i64
1307 ; CHECK-NEXT: call void @use(i64 [[EXT]])
1308 ; CHECK-NEXT: [[SHL:%.*]] = shl nuw nsw i64 [[EXT]], 8
1309 ; CHECK-NEXT: ret i64 [[SHL]]
1311 %and = and i32 %t, 16777215
1312 %ext = zext i32 %and to i64
1313 call void @use(i64 %ext)
1314 %shl = shl i64 %ext, 8
1319 define <2 x i64> @shl_zext_splat_vec(<2 x i32> %t) {
1320 ; CHECK-LABEL: @shl_zext_splat_vec(
1321 ; CHECK-NEXT: [[TMP1:%.*]] = shl <2 x i32> [[T:%.*]], <i32 8, i32 8>
1322 ; CHECK-NEXT: [[SHL:%.*]] = zext <2 x i32> [[TMP1]] to <2 x i64>
1323 ; CHECK-NEXT: ret <2 x i64> [[SHL]]
1325 %and = and <2 x i32> %t, <i32 16777215, i32 16777215>
1326 %ext = zext <2 x i32> %and to <2 x i64>
1327 %shl = shl <2 x i64> %ext, <i64 8, i64 8>
1331 define i64 @shl_zext_mul(i32 %t) {
1332 ; CHECK-LABEL: @shl_zext_mul(
1333 ; CHECK-NEXT: [[MUL:%.*]] = mul i32 [[T:%.*]], 16777215
1334 ; CHECK-NEXT: [[EXT:%.*]] = zext i32 [[MUL]] to i64
1335 ; CHECK-NEXT: [[SHL:%.*]] = shl nuw i64 [[EXT]], 32
1336 ; CHECK-NEXT: ret i64 [[SHL]]
1338 %mul = mul i32 %t, 16777215
1339 %ext = zext i32 %mul to i64
1340 %shl = shl i64 %ext, 32
1344 define <3 x i17> @shl_zext_mul_splat(<3 x i5> %t) {
1345 ; CHECK-LABEL: @shl_zext_mul_splat(
1346 ; CHECK-NEXT: [[MUL:%.*]] = mul <3 x i5> [[T:%.*]], <i5 13, i5 13, i5 13>
1347 ; CHECK-NEXT: [[EXT:%.*]] = zext <3 x i5> [[MUL]] to <3 x i17>
1348 ; CHECK-NEXT: [[SHL:%.*]] = shl nuw <3 x i17> [[EXT]], <i17 12, i17 12, i17 12>
1349 ; CHECK-NEXT: ret <3 x i17> [[SHL]]
1351 %mul = mul <3 x i5> %t, <i5 13, i5 13, i5 13>
1352 %ext = zext <3 x i5> %mul to <3 x i17>
1353 %shl = shl <3 x i17> %ext, <i17 12, i17 12, i17 12>
1357 define i64 @shl_zext_mul_low_shift_amount(i32 %t) {
1358 ; CHECK-LABEL: @shl_zext_mul_low_shift_amount(
1359 ; CHECK-NEXT: [[MUL:%.*]] = mul i32 [[T:%.*]], 16777215
1360 ; CHECK-NEXT: [[EXT:%.*]] = zext i32 [[MUL]] to i64
1361 ; CHECK-NEXT: [[SHL:%.*]] = shl nuw nsw i64 [[EXT]], 31
1362 ; CHECK-NEXT: ret i64 [[SHL]]
1364 %mul = mul i32 %t, 16777215
1365 %ext = zext i32 %mul to i64
1366 %shl = shl i64 %ext, 31
1370 define i64 @shl_zext_mul_extra_use1(i32 %t) {
1371 ; CHECK-LABEL: @shl_zext_mul_extra_use1(
1372 ; CHECK-NEXT: [[MUL:%.*]] = mul i32 [[T:%.*]], 16777215
1373 ; CHECK-NEXT: [[EXT:%.*]] = zext i32 [[MUL]] to i64
1374 ; CHECK-NEXT: call void @use(i64 [[EXT]])
1375 ; CHECK-NEXT: [[SHL:%.*]] = shl nuw i64 [[EXT]], 32
1376 ; CHECK-NEXT: ret i64 [[SHL]]
1378 %mul = mul i32 %t, 16777215
1379 %ext = zext i32 %mul to i64
1380 call void @use(i64 %ext)
1381 %shl = shl i64 %ext, 32
1385 declare void @use_i32(i32)
1387 define i64 @shl_zext_mul_extra_use2(i32 %t) {
1388 ; CHECK-LABEL: @shl_zext_mul_extra_use2(
1389 ; CHECK-NEXT: [[MUL:%.*]] = mul i32 [[T:%.*]], 16777215
1390 ; CHECK-NEXT: call void @use_i32(i32 [[MUL]])
1391 ; CHECK-NEXT: [[EXT:%.*]] = zext i32 [[MUL]] to i64
1392 ; CHECK-NEXT: [[SHL:%.*]] = shl nuw i64 [[EXT]], 32
1393 ; CHECK-NEXT: ret i64 [[SHL]]
1395 %mul = mul i32 %t, 16777215
1396 call void @use_i32(i32 %mul)
1397 %ext = zext i32 %mul to i64
1398 %shl = shl i64 %ext, 32
1402 define <2 x i8> @ashr_demanded_bits_splat(<2 x i8> %x) {
1403 ; CHECK-LABEL: @ashr_demanded_bits_splat(
1404 ; CHECK-NEXT: [[SHR:%.*]] = ashr <2 x i8> [[X:%.*]], <i8 7, i8 7>
1405 ; CHECK-NEXT: ret <2 x i8> [[SHR]]
1407 %and = and <2 x i8> %x, <i8 128, i8 128>
1408 %shr = ashr <2 x i8> %and, <i8 7, i8 7>
1412 define <2 x i8> @lshr_demanded_bits_splat(<2 x i8> %x) {
1413 ; CHECK-LABEL: @lshr_demanded_bits_splat(
1414 ; CHECK-NEXT: [[SHR:%.*]] = lshr <2 x i8> [[X:%.*]], <i8 7, i8 7>
1415 ; CHECK-NEXT: ret <2 x i8> [[SHR]]
1417 %and = and <2 x i8> %x, <i8 128, i8 128>
1418 %shr = lshr <2 x i8> %and, <i8 7, i8 7>
1422 ; Make sure known bits works correctly with non power of 2 bit widths.
1423 define i7 @test65(i7 %a, i7 %b) {
1424 ; CHECK-LABEL: @test65(
1425 ; CHECK-NEXT: ret i7 0
1427 %shiftamt = and i7 %b, 6 ; this ensures the shift amount is even and less than the bit width.
1428 %x = lshr i7 42, %shiftamt ; 42 has a zero in every even numbered bit and a one in every odd bit.
1429 %y = and i7 %x, 1 ; this extracts the lsb which should be 0 because we shifted an even number of bits and all even bits of the shift input are 0.
1433 define i32 @shl_select_add_true(i32 %x, i1 %cond) {
1434 ; CHECK-LABEL: @shl_select_add_true(
1435 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 1
1436 ; CHECK-NEXT: [[TMP2:%.*]] = add i32 [[TMP1]], 14
1437 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
1438 ; CHECK-NEXT: ret i32 [[TMP3]]
1441 %2 = select i1 %cond, i32 %1, i32 %x
1446 define i32 @shl_select_add_false(i32 %x, i1 %cond) {
1447 ; CHECK-LABEL: @shl_select_add_false(
1448 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 1
1449 ; CHECK-NEXT: [[TMP2:%.*]] = add i32 [[TMP1]], 14
1450 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP1]], i32 [[TMP2]]
1451 ; CHECK-NEXT: ret i32 [[TMP3]]
1454 %2 = select i1 %cond, i32 %x, i32 %1
1459 define i32 @shl_select_and_true(i32 %x, i1 %cond) {
1460 ; CHECK-LABEL: @shl_select_and_true(
1461 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 1
1462 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], 14
1463 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
1464 ; CHECK-NEXT: ret i32 [[TMP3]]
1467 %2 = select i1 %cond, i32 %1, i32 %x
1472 define i32 @shl_select_and_false(i32 %x, i1 %cond) {
1473 ; CHECK-LABEL: @shl_select_and_false(
1474 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 1
1475 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], 14
1476 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP1]], i32 [[TMP2]]
1477 ; CHECK-NEXT: ret i32 [[TMP3]]
1480 %2 = select i1 %cond, i32 %x, i32 %1
1485 define i32 @lshr_select_and_true(i32 %x, i1 %cond) {
1486 ; CHECK-LABEL: @lshr_select_and_true(
1487 ; CHECK-NEXT: [[TMP1:%.*]] = lshr i32 [[X:%.*]], 1
1488 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], 3
1489 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
1490 ; CHECK-NEXT: ret i32 [[TMP3]]
1493 %2 = select i1 %cond, i32 %1, i32 %x
1498 define i32 @lshr_select_and_false(i32 %x, i1 %cond) {
1499 ; CHECK-LABEL: @lshr_select_and_false(
1500 ; CHECK-NEXT: [[TMP1:%.*]] = lshr i32 [[X:%.*]], 1
1501 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], 3
1502 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP1]], i32 [[TMP2]]
1503 ; CHECK-NEXT: ret i32 [[TMP3]]
1506 %2 = select i1 %cond, i32 %x, i32 %1
1511 define i32 @ashr_select_and_true(i32 %x, i1 %cond) {
1512 ; CHECK-LABEL: @ashr_select_and_true(
1513 ; CHECK-NEXT: [[TMP1:%.*]] = ashr i32 [[X:%.*]], 1
1514 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], -1073741821
1515 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
1516 ; CHECK-NEXT: ret i32 [[TMP3]]
1518 %1 = and i32 %x, 2147483655
1519 %2 = select i1 %cond, i32 %1, i32 %x
1524 define i32 @ashr_select_and_false(i32 %x, i1 %cond) {
1525 ; CHECK-LABEL: @ashr_select_and_false(
1526 ; CHECK-NEXT: [[TMP1:%.*]] = ashr i32 [[X:%.*]], 1
1527 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], -1073741821
1528 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP1]], i32 [[TMP2]]
1529 ; CHECK-NEXT: ret i32 [[TMP3]]
1531 %1 = and i32 %x, 2147483655
1532 %2 = select i1 %cond, i32 %x, i32 %1
1537 define i32 @shl_select_or_true(i32 %x, i1 %cond) {
1538 ; CHECK-LABEL: @shl_select_or_true(
1539 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 1
1540 ; CHECK-NEXT: [[TMP2:%.*]] = or i32 [[TMP1]], 14
1541 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
1542 ; CHECK-NEXT: ret i32 [[TMP3]]
1545 %2 = select i1 %cond, i32 %1, i32 %x
1550 define i32 @shl_select_or_false(i32 %x, i1 %cond) {
1551 ; CHECK-LABEL: @shl_select_or_false(
1552 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 1
1553 ; CHECK-NEXT: [[TMP2:%.*]] = or i32 [[TMP1]], 14
1554 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP1]], i32 [[TMP2]]
1555 ; CHECK-NEXT: ret i32 [[TMP3]]
1558 %2 = select i1 %cond, i32 %x, i32 %1
1563 define i32 @lshr_select_or_true(i32 %x, i1 %cond) {
1564 ; CHECK-LABEL: @lshr_select_or_true(
1565 ; CHECK-NEXT: [[TMP1:%.*]] = lshr i32 [[X:%.*]], 1
1566 ; CHECK-NEXT: [[TMP2:%.*]] = or i32 [[TMP1]], 3
1567 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
1568 ; CHECK-NEXT: ret i32 [[TMP3]]
1571 %2 = select i1 %cond, i32 %1, i32 %x
1576 define i32 @lshr_select_or_false(i32 %x, i1 %cond) {
1577 ; CHECK-LABEL: @lshr_select_or_false(
1578 ; CHECK-NEXT: [[TMP1:%.*]] = lshr i32 [[X:%.*]], 1
1579 ; CHECK-NEXT: [[TMP2:%.*]] = or i32 [[TMP1]], 3
1580 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP1]], i32 [[TMP2]]
1581 ; CHECK-NEXT: ret i32 [[TMP3]]
1584 %2 = select i1 %cond, i32 %x, i32 %1
1589 define i32 @ashr_select_or_true(i32 %x, i1 %cond) {
1590 ; CHECK-LABEL: @ashr_select_or_true(
1591 ; CHECK-NEXT: [[TMP1:%.*]] = ashr i32 [[X:%.*]], 1
1592 ; CHECK-NEXT: [[TMP2:%.*]] = or i32 [[TMP1]], 3
1593 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
1594 ; CHECK-NEXT: ret i32 [[TMP3]]
1597 %2 = select i1 %cond, i32 %1, i32 %x
1602 define i32 @ashr_select_or_false(i32 %x, i1 %cond) {
1603 ; CHECK-LABEL: @ashr_select_or_false(
1604 ; CHECK-NEXT: [[TMP1:%.*]] = ashr i32 [[X:%.*]], 1
1605 ; CHECK-NEXT: [[TMP2:%.*]] = or i32 [[TMP1]], 3
1606 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP1]], i32 [[TMP2]]
1607 ; CHECK-NEXT: ret i32 [[TMP3]]
1610 %2 = select i1 %cond, i32 %x, i32 %1
1615 define i32 @shl_select_xor_true(i32 %x, i1 %cond) {
1616 ; CHECK-LABEL: @shl_select_xor_true(
1617 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 1
1618 ; CHECK-NEXT: [[TMP2:%.*]] = xor i32 [[TMP1]], 14
1619 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
1620 ; CHECK-NEXT: ret i32 [[TMP3]]
1623 %2 = select i1 %cond, i32 %1, i32 %x
1628 define i32 @shl_select_xor_false(i32 %x, i1 %cond) {
1629 ; CHECK-LABEL: @shl_select_xor_false(
1630 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 1
1631 ; CHECK-NEXT: [[TMP2:%.*]] = xor i32 [[TMP1]], 14
1632 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP1]], i32 [[TMP2]]
1633 ; CHECK-NEXT: ret i32 [[TMP3]]
1636 %2 = select i1 %cond, i32 %x, i32 %1
1641 define i32 @lshr_select_xor_true(i32 %x, i1 %cond) {
1642 ; CHECK-LABEL: @lshr_select_xor_true(
1643 ; CHECK-NEXT: [[TMP1:%.*]] = lshr i32 [[X:%.*]], 1
1644 ; CHECK-NEXT: [[TMP2:%.*]] = xor i32 [[TMP1]], 3
1645 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
1646 ; CHECK-NEXT: ret i32 [[TMP3]]
1649 %2 = select i1 %cond, i32 %1, i32 %x
1654 define i32 @lshr_select_xor_false(i32 %x, i1 %cond) {
1655 ; CHECK-LABEL: @lshr_select_xor_false(
1656 ; CHECK-NEXT: [[TMP1:%.*]] = lshr i32 [[X:%.*]], 1
1657 ; CHECK-NEXT: [[TMP2:%.*]] = xor i32 [[TMP1]], 3
1658 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP1]], i32 [[TMP2]]
1659 ; CHECK-NEXT: ret i32 [[TMP3]]
1662 %2 = select i1 %cond, i32 %x, i32 %1
1667 define i32 @ashr_select_xor_true(i32 %x, i1 %cond) {
1668 ; CHECK-LABEL: @ashr_select_xor_true(
1669 ; CHECK-NEXT: [[TMP1:%.*]] = ashr i32 [[X:%.*]], 1
1670 ; CHECK-NEXT: [[TMP2:%.*]] = xor i32 [[TMP1]], 3
1671 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
1672 ; CHECK-NEXT: ret i32 [[TMP3]]
1675 %2 = select i1 %cond, i32 %1, i32 %x
1680 define i32 @ashr_select_xor_false(i32 %x, i1 %cond) {
1681 ; CHECK-LABEL: @ashr_select_xor_false(
1682 ; CHECK-NEXT: [[TMP1:%.*]] = ashr i32 [[X:%.*]], 1
1683 ; CHECK-NEXT: [[TMP2:%.*]] = xor i32 [[TMP1]], 3
1684 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP1]], i32 [[TMP2]]
1685 ; CHECK-NEXT: ret i32 [[TMP3]]
1688 %2 = select i1 %cond, i32 %x, i32 %1
1694 ; https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=4871
1695 define i177 @lshr_out_of_range(i177 %Y, i177** %A2) {
1696 ; CHECK-LABEL: @lshr_out_of_range(
1697 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ne i177 [[Y:%.*]], -1
1698 ; CHECK-NEXT: [[B4:%.*]] = sext i1 [[TMP1]] to i177
1699 ; CHECK-NEXT: [[C8:%.*]] = icmp ult i177 [[B4]], [[Y]]
1700 ; CHECK-NEXT: [[TMP2:%.*]] = sext i1 [[C8]] to i64
1701 ; CHECK-NEXT: [[G18:%.*]] = getelementptr i177*, i177** [[A2:%.*]], i64 [[TMP2]]
1702 ; CHECK-NEXT: store i177** [[G18]], i177*** undef, align 8
1703 ; CHECK-NEXT: ret i177 0
1705 %B5 = udiv i177 %Y, -1
1706 %B4 = add i177 %B5, -1
1707 %B2 = add i177 %B4, -1
1708 %B6 = mul i177 %B5, %B2
1709 %B3 = add i177 %B2, %B2
1710 %B10 = sub i177 %B5, %B3
1711 %B12 = lshr i177 %Y, %B6
1712 %C8 = icmp ugt i177 %B12, %B4
1713 %G18 = getelementptr i177*, i177** %A2, i1 %C8
1714 store i177** %G18, i177*** undef
1715 %B1 = udiv i177 %B10, %B6
1720 ; https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=26716
1721 define i177 @lshr_out_of_range2(i177 %Y, i177** %A2) {
1722 ; CHECK-LABEL: @lshr_out_of_range2(
1723 ; CHECK-NEXT: ret i177 0
1725 %B5 = udiv i177 %Y, -1
1726 %B = sdiv i177 %B5, -1
1727 %B4 = add i177 %B5, %B
1728 %B2 = add i177 %B4, -1
1729 %B6 = mul i177 %B5, %B2
1730 %B12 = lshr i177 %Y, %B6
1731 %C8 = icmp ugt i177 %B12, %B4
1732 %G18 = getelementptr i177*, i177** %A2, i1 %C8
1733 store i177** %G18, i177*** undef, align 8
1734 %B1 = udiv i177 %B5, %B6
1739 ; https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=5032
1740 define void @ashr_out_of_range(i177* %A) {
1741 ; CHECK-LABEL: @ashr_out_of_range(
1742 ; CHECK-NEXT: [[L:%.*]] = load i177, i177* [[A:%.*]], align 4
1743 ; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i177 [[L]], -1
1744 ; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[TMP1]], i64 -1, i64 -2
1745 ; CHECK-NEXT: [[G11:%.*]] = getelementptr i177, i177* [[A]], i64 [[TMP2]]
1746 ; CHECK-NEXT: [[L7:%.*]] = load i177, i177* [[G11]], align 4
1747 ; CHECK-NEXT: [[B36:%.*]] = select i1 [[TMP1]], i177 0, i177 [[L7]]
1748 ; CHECK-NEXT: [[C17:%.*]] = icmp sgt i177 [[B36]], [[L7]]
1749 ; CHECK-NEXT: [[TMP3:%.*]] = sext i1 [[C17]] to i64
1750 ; CHECK-NEXT: [[G62:%.*]] = getelementptr i177, i177* [[G11]], i64 [[TMP3]]
1751 ; CHECK-NEXT: [[TMP4:%.*]] = icmp eq i177 [[L7]], -1
1752 ; CHECK-NEXT: [[B28:%.*]] = select i1 [[TMP4]], i177 0, i177 [[L7]]
1753 ; CHECK-NEXT: store i177 [[B28]], i177* [[G62]], align 4
1754 ; CHECK-NEXT: ret void
1756 %L = load i177, i177* %A
1757 %B5 = udiv i177 %L, -1
1758 %B4 = add i177 %B5, -1
1759 %B2 = add i177 %B4, -1
1760 %G11 = getelementptr i177, i177* %A, i177 %B2
1761 %L7 = load i177, i177* %G11
1762 %B6 = mul i177 %B5, %B2
1763 %B24 = ashr i177 %L7, %B6
1764 %B36 = and i177 %L7, %B4
1765 %C17 = icmp sgt i177 %B36, %B24
1766 %G62 = getelementptr i177, i177* %G11, i1 %C17
1767 %B28 = urem i177 %B24, %B6
1768 store i177 %B28, i177* %G62
1773 ; https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=26135
1774 define void @ashr_out_of_range_1(i177* %A) {
1775 ; CHECK-LABEL: @ashr_out_of_range_1(
1776 ; CHECK-NEXT: [[L:%.*]] = load i177, i177* [[A:%.*]], align 4
1777 ; CHECK-NEXT: [[B24_LOBIT:%.*]] = ashr i177 [[L]], 175
1778 ; CHECK-NEXT: [[TMP1:%.*]] = trunc i177 [[B24_LOBIT]] to i64
1779 ; CHECK-NEXT: [[G62_IDX:%.*]] = add i64 [[TMP1]], -1
1780 ; CHECK-NEXT: [[G62:%.*]] = getelementptr i177, i177* [[A]], i64 [[G62_IDX]]
1781 ; CHECK-NEXT: store i177 0, i177* [[G62]], align 4
1782 ; CHECK-NEXT: ret void
1784 %L = load i177, i177* %A, align 4
1785 %B5 = udiv i177 %L, -1
1786 %B4 = add i177 %B5, -1
1787 %B = and i177 %B4, %L
1788 %B2 = add i177 %B, -1
1789 %G11 = getelementptr i177, i177* %A, i177 %B2
1790 %B6 = mul i177 %B5, %B2
1791 %B24 = ashr i177 %L, %B6
1792 %C17 = icmp sgt i177 %B, %B24
1793 %G62 = getelementptr i177, i177* %G11, i1 %C17
1794 %B28 = urem i177 %B24, %B6
1795 store i177 %B28, i177* %G62, align 4
1799 define i8 @lshr_mask_demand(i8 %x) {
1800 ; CHECK-LABEL: @lshr_mask_demand(
1801 ; CHECK-NEXT: [[S:%.*]] = lshr i8 63, [[X:%.*]]
1802 ; CHECK-NEXT: [[R:%.*]] = and i8 [[S]], 32
1803 ; CHECK-NEXT: ret i8 [[R]]
1805 %s = lshr i8 63, %x ; 0b00111111
1806 %r = and i8 %s, 224 ; 0b11100000
1810 define i8 @shl_mask_demand(i8 %x) {
1811 ; CHECK-LABEL: @shl_mask_demand(
1812 ; CHECK-NEXT: [[S:%.*]] = shl i8 12, [[X:%.*]]
1813 ; CHECK-NEXT: [[R:%.*]] = and i8 [[S]], 4
1814 ; CHECK-NEXT: ret i8 [[R]]
1816 %s = shl i8 12, %x ; 0b00001100
1817 %r = and i8 %s, 7 ; 0b00000111