1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -passes='instcombine<no-verify-fixpoint>' -S | FileCheck %s
4 ; The fuzzer-generated @ashr_out_of_range test case does not reach a fixpoint,
5 ; because a logical and it not relaxed to a bitwise and in one iteration.
8 declare void @use_i32(i32)
10 declare i32 @llvm.cttz.i32(i32, i1 immarg)
11 declare <2 x i8> @llvm.cttz.v2i8(<2 x i8>, i1 immarg)
13 define <4 x i32> @lshr_non_splat_vector(<4 x i32> %A) {
14 ; CHECK-LABEL: @lshr_non_splat_vector(
15 ; CHECK-NEXT: [[B:%.*]] = lshr <4 x i32> [[A:%.*]], <i32 32, i32 1, i32 2, i32 3>
16 ; CHECK-NEXT: ret <4 x i32> [[B]]
18 %B = lshr <4 x i32> %A, <i32 32, i32 1, i32 2, i32 3>
22 define <4 x i32> @shl_non_splat_vector(<4 x i32> %A) {
23 ; CHECK-LABEL: @shl_non_splat_vector(
24 ; CHECK-NEXT: [[B:%.*]] = shl <4 x i32> [[A:%.*]], <i32 32, i32 1, i32 2, i32 3>
25 ; CHECK-NEXT: ret <4 x i32> [[B]]
27 %B = shl <4 x i32> %A, <i32 32, i32 1, i32 2, i32 3>
31 define i32 @test6(i32 %A) {
32 ; CHECK-LABEL: @test6(
33 ; CHECK-NEXT: [[C:%.*]] = mul i32 [[A:%.*]], 6
34 ; CHECK-NEXT: ret i32 [[C]]
36 %B = shl i32 %A, 1 ;; convert to an mul instruction
41 define i32 @test6a(i32 %A) {
42 ; CHECK-LABEL: @test6a(
43 ; CHECK-NEXT: [[C:%.*]] = mul i32 [[A:%.*]], 6
44 ; CHECK-NEXT: ret i32 [[C]]
47 %C = shl i32 %B, 1 ;; convert to an mul instruction
51 ;; (A << 5) << 3 === A << 8 == 0
52 define i8 @test8(i8 %A) {
53 ; CHECK-LABEL: @test8(
54 ; CHECK-NEXT: ret i8 0
61 ;; (A << 7) >> 7 === A & 1
62 define i8 @test9(i8 %A) {
63 ; CHECK-LABEL: @test9(
64 ; CHECK-NEXT: [[B:%.*]] = and i8 [[A:%.*]], 1
65 ; CHECK-NEXT: ret i8 [[B]]
72 ;; (A >> 7) << 7 === A & 128
74 define i8 @test10(i8 %A) {
75 ; CHECK-LABEL: @test10(
76 ; CHECK-NEXT: [[B:%.*]] = and i8 [[A:%.*]], -128
77 ; CHECK-NEXT: ret i8 [[B]]
84 ;; Allow the simplification when the lshr shift is exact.
85 define i8 @test10a(i8 %A) {
86 ; CHECK-LABEL: @test10a(
87 ; CHECK-NEXT: ret i8 [[A:%.*]]
89 %B = lshr exact i8 %A, 7
94 ;; (A >> 3) << 4 === (A & 0x1F) << 1
95 define i8 @test11(i8 %x) {
96 ; CHECK-LABEL: @test11(
97 ; CHECK-NEXT: [[TMP1:%.*]] = mul i8 [[X:%.*]], 6
98 ; CHECK-NEXT: [[C:%.*]] = and i8 [[TMP1]], -16
99 ; CHECK-NEXT: ret i8 [[C]]
107 ;; Allow the simplification in InstCombine when the lshr shift is exact.
108 define i8 @test11a(i8 %A) {
109 ; CHECK-LABEL: @test11a(
110 ; CHECK-NEXT: [[C:%.*]] = mul i8 [[A:%.*]], 6
111 ; CHECK-NEXT: ret i8 [[C]]
114 %B = lshr exact i8 %a, 3
119 ;; (A >> 8) << 8 === A & -256
120 define i32 @test12(i32 %A) {
121 ; CHECK-LABEL: @test12(
122 ; CHECK-NEXT: [[B:%.*]] = and i32 [[A:%.*]], -256
123 ; CHECK-NEXT: ret i32 [[B]]
130 ;; ((A >>s 6) << 6 === (A & FFFFFFC0)
131 define i8 @shishi(i8 %x) {
132 ; CHECK-LABEL: @shishi(
133 ; CHECK-NEXT: [[A:%.*]] = ashr i8 [[X:%.*]], 6
134 ; CHECK-NEXT: [[B:%.*]] = and i8 [[X]], -64
135 ; CHECK-NEXT: [[EXTRA_USE_OF_A:%.*]] = mul nsw i8 [[A]], 5
136 ; CHECK-NEXT: [[R:%.*]] = sdiv i8 [[EXTRA_USE_OF_A]], [[B]]
137 ; CHECK-NEXT: ret i8 [[R]]
141 %extra_use_of_a = mul i8 %a, 5
142 %r = sdiv i8 %extra_use_of_a, %b
146 ;; (A >> 3) << 4 === (A & -8) * 2
147 define i8 @test13(i8 %x) {
148 ; CHECK-LABEL: @test13(
149 ; CHECK-NEXT: [[TMP1:%.*]] = mul i8 [[X:%.*]], 6
150 ; CHECK-NEXT: [[C:%.*]] = and i8 [[TMP1]], -16
151 ; CHECK-NEXT: ret i8 [[C]]
159 define i8 @test13a(i8 %A) {
160 ; CHECK-LABEL: @test13a(
161 ; CHECK-NEXT: [[C:%.*]] = mul i8 [[A:%.*]], 6
162 ; CHECK-NEXT: ret i8 [[C]]
165 %B = ashr exact i8 %a, 3
170 ;; D = ((B | 1234) << 4) === ((B << 4)|(1234 << 4)
171 define i32 @test14(i32 %A) {
172 ; CHECK-LABEL: @test14(
173 ; CHECK-NEXT: [[B:%.*]] = and i32 [[A:%.*]], -19760
174 ; CHECK-NEXT: [[C:%.*]] = or disjoint i32 [[B]], 19744
175 ; CHECK-NEXT: ret i32 [[C]]
183 ;; D = ((B | 1234) << 4) === ((B << 4)|(1234 << 4)
184 define i32 @test14a(i32 %A) {
185 ; CHECK-LABEL: @test14a(
186 ; CHECK-NEXT: [[C:%.*]] = and i32 [[A:%.*]], 77
187 ; CHECK-NEXT: ret i32 [[C]]
190 %C = and i32 %B, 1234
195 define i32 @test15(i1 %C) {
196 ; CHECK-LABEL: @test15(
197 ; CHECK-NEXT: [[A:%.*]] = select i1 [[C:%.*]], i32 12, i32 4
198 ; CHECK-NEXT: ret i32 [[A]]
200 %A = select i1 %C, i32 3, i32 1
205 define i32 @test15a(i1 %C) {
206 ; CHECK-LABEL: @test15a(
207 ; CHECK-NEXT: [[V:%.*]] = select i1 [[C:%.*]], i32 512, i32 128
208 ; CHECK-NEXT: ret i32 [[V]]
210 %A = select i1 %C, i8 3, i8 1
211 %shift.upgrd.4 = zext i8 %A to i32
212 %V = shl i32 64, %shift.upgrd.4
216 define i1 @test16(i32 %X) {
217 ; CHECK-LABEL: @test16(
218 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], 16
219 ; CHECK-NEXT: [[I_7:%.*]] = icmp ne i32 [[TMP1]], 0
220 ; CHECK-NEXT: ret i1 [[I_7]]
222 %i.3 = ashr i32 %X, 4
223 %i.6 = and i32 %i.3, 1
224 %i.7 = icmp ne i32 %i.6, 0
228 define i1 @test17(i32 %A) {
229 ; CHECK-LABEL: @test17(
230 ; CHECK-NEXT: [[B_MASK:%.*]] = and i32 [[A:%.*]], -8
231 ; CHECK-NEXT: [[C:%.*]] = icmp eq i32 [[B_MASK]], 9872
232 ; CHECK-NEXT: ret i1 [[C]]
235 %C = icmp eq i32 %B, 1234
239 define <2 x i1> @test17vec(<2 x i32> %A) {
240 ; CHECK-LABEL: @test17vec(
241 ; CHECK-NEXT: [[B_MASK:%.*]] = and <2 x i32> [[A:%.*]], <i32 -8, i32 -8>
242 ; CHECK-NEXT: [[C:%.*]] = icmp eq <2 x i32> [[B_MASK]], <i32 9872, i32 9872>
243 ; CHECK-NEXT: ret <2 x i1> [[C]]
245 %B = lshr <2 x i32> %A, <i32 3, i32 3>
246 %C = icmp eq <2 x i32> %B, <i32 1234, i32 1234>
250 define i1 @test18(i8 %A) {
251 ; CHECK-LABEL: @test18(
252 ; CHECK-NEXT: ret i1 false
256 %C = icmp eq i8 %B, 123
260 define i1 @test19(i32 %A) {
261 ; CHECK-LABEL: @test19(
262 ; CHECK-NEXT: [[C:%.*]] = icmp ult i32 [[A:%.*]], 4
263 ; CHECK-NEXT: ret i1 [[C]]
267 %C = icmp eq i32 %B, 0
271 define <2 x i1> @test19vec(<2 x i32> %A) {
272 ; CHECK-LABEL: @test19vec(
273 ; CHECK-NEXT: [[C:%.*]] = icmp ult <2 x i32> [[A:%.*]], <i32 4, i32 4>
274 ; CHECK-NEXT: ret <2 x i1> [[C]]
276 %B = ashr <2 x i32> %A, <i32 2, i32 2>
277 %C = icmp eq <2 x i32> %B, zeroinitializer
282 define i1 @test19a(i32 %A) {
283 ; CHECK-LABEL: @test19a(
284 ; CHECK-NEXT: [[C:%.*]] = icmp ugt i32 [[A:%.*]], -5
285 ; CHECK-NEXT: ret i1 [[C]]
288 %C = icmp eq i32 %B, -1
292 define <2 x i1> @test19a_vec(<2 x i32> %A) {
293 ; CHECK-LABEL: @test19a_vec(
294 ; CHECK-NEXT: [[C:%.*]] = icmp ugt <2 x i32> [[A:%.*]], <i32 -5, i32 -5>
295 ; CHECK-NEXT: ret <2 x i1> [[C]]
297 %B = ashr <2 x i32> %A, <i32 2, i32 2>
298 %C = icmp eq <2 x i32> %B, <i32 -1, i32 -1>
302 define i1 @test20(i8 %A) {
303 ; CHECK-LABEL: @test20(
304 ; CHECK-NEXT: ret i1 false
308 %C = icmp eq i8 %B, 123
312 define i1 @test21(i8 %A) {
313 ; CHECK-LABEL: @test21(
314 ; CHECK-NEXT: [[B_MASK:%.*]] = and i8 [[A:%.*]], 15
315 ; CHECK-NEXT: [[C:%.*]] = icmp eq i8 [[B_MASK]], 8
316 ; CHECK-NEXT: ret i1 [[C]]
319 %C = icmp eq i8 %B, -128
323 define i1 @test22(i8 %A) {
324 ; CHECK-LABEL: @test22(
325 ; CHECK-NEXT: [[B_MASK:%.*]] = and i8 [[A:%.*]], 15
326 ; CHECK-NEXT: [[C:%.*]] = icmp eq i8 [[B_MASK]], 0
327 ; CHECK-NEXT: ret i1 [[C]]
330 %C = icmp eq i8 %B, 0
334 define i8 @test23(i32 %A) {
335 ; CHECK-LABEL: @test23(
336 ; CHECK-NEXT: [[D:%.*]] = trunc i32 [[A:%.*]] to i8
337 ; CHECK-NEXT: ret i8 [[D]]
342 %D = trunc i32 %C to i8
346 define i8 @test24(i8 %X) {
347 ; CHECK-LABEL: @test24(
348 ; CHECK-NEXT: [[Z:%.*]] = and i8 [[X:%.*]], 3
349 ; CHECK-NEXT: ret i8 [[Z]]
357 ;; handle casts between shifts.
358 define i32 @test26(i32 %A) {
359 ; CHECK-LABEL: @test26(
360 ; CHECK-NEXT: [[B:%.*]] = and i32 [[A:%.*]], -2
361 ; CHECK-NEXT: ret i32 [[B]]
364 %C = bitcast i32 %B to i32
369 define i1 @test27(i32 %x) {
370 ; CHECK-LABEL: @test27(
371 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], 8
372 ; CHECK-NEXT: [[Z:%.*]] = icmp ne i32 [[TMP1]], 0
373 ; CHECK-NEXT: ret i1 [[Z]]
376 %z = trunc i32 %y to i1
380 define i1 @test28(i8 %x) {
381 ; CHECK-LABEL: @test28(
382 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt i8 [[X:%.*]], 0
383 ; CHECK-NEXT: ret i1 [[CMP]]
386 %cmp = icmp ne i8 %shr, 0
390 define <2 x i1> @test28vec(<2 x i8> %x) {
391 ; CHECK-LABEL: @test28vec(
392 ; CHECK-NEXT: [[CMP:%.*]] = icmp slt <2 x i8> [[X:%.*]], zeroinitializer
393 ; CHECK-NEXT: ret <2 x i1> [[CMP]]
395 %shr = lshr <2 x i8> %x, <i8 7, i8 7>
396 %cmp = icmp ne <2 x i8> %shr, zeroinitializer
400 define i8 @test28a(i8 %x, i8 %y) {
401 ; CHECK-LABEL: @test28a(
403 ; CHECK-NEXT: [[COND1_NOT:%.*]] = icmp sgt i8 [[X:%.*]], -1
404 ; CHECK-NEXT: br i1 [[COND1_NOT]], label [[BB2:%.*]], label [[BB1:%.*]]
406 ; CHECK-NEXT: ret i8 1
408 ; CHECK-NEXT: ret i8 [[Y:%.*]]
411 ; This shouldn't be transformed.
413 %cond1 = icmp ne i8 %i1, 0
414 br i1 %cond1, label %bb1, label %bb2
422 define i32 @test29(i64 %d18) {
423 ; CHECK-LABEL: @test29(
425 ; CHECK-NEXT: [[SUM_SHIFT:%.*]] = lshr i64 [[D18:%.*]], 63
426 ; CHECK-NEXT: [[I101:%.*]] = trunc nuw nsw i64 [[SUM_SHIFT]] to i32
427 ; CHECK-NEXT: ret i32 [[I101]]
430 %i916 = lshr i64 %d18, 32
431 %i917 = trunc i64 %i916 to i32
432 %i10 = lshr i32 %i917, 31
436 define <2 x i32> @test29_uniform(<2 x i64> %d18) {
437 ; CHECK-LABEL: @test29_uniform(
439 ; CHECK-NEXT: [[SUM_SHIFT:%.*]] = lshr <2 x i64> [[D18:%.*]], <i64 63, i64 63>
440 ; CHECK-NEXT: [[I101:%.*]] = trunc nuw nsw <2 x i64> [[SUM_SHIFT]] to <2 x i32>
441 ; CHECK-NEXT: ret <2 x i32> [[I101]]
444 %i916 = lshr <2 x i64> %d18, <i64 32, i64 32>
445 %i917 = trunc <2 x i64> %i916 to <2 x i32>
446 %i10 = lshr <2 x i32> %i917, <i32 31, i32 31>
450 define <2 x i32> @test29_nonuniform(<2 x i64> %d18) {
451 ; CHECK-LABEL: @test29_nonuniform(
453 ; CHECK-NEXT: [[I916:%.*]] = lshr <2 x i64> [[D18:%.*]], <i64 32, i64 15>
454 ; CHECK-NEXT: [[I917:%.*]] = trunc <2 x i64> [[I916]] to <2 x i32>
455 ; CHECK-NEXT: [[I10:%.*]] = lshr <2 x i32> [[I917]], <i32 31, i32 22>
456 ; CHECK-NEXT: ret <2 x i32> [[I10]]
459 %i916 = lshr <2 x i64> %d18, <i64 32, i64 15>
460 %i917 = trunc <2 x i64> %i916 to <2 x i32>
461 %i10 = lshr <2 x i32> %i917, <i32 31, i32 22>
465 define <2 x i32> @test29_poison(<2 x i64> %d18) {
466 ; CHECK-LABEL: @test29_poison(
468 ; CHECK-NEXT: [[I916:%.*]] = lshr <2 x i64> [[D18:%.*]], <i64 32, i64 poison>
469 ; CHECK-NEXT: [[I917:%.*]] = trunc nuw <2 x i64> [[I916]] to <2 x i32>
470 ; CHECK-NEXT: [[I10:%.*]] = lshr <2 x i32> [[I917]], <i32 31, i32 poison>
471 ; CHECK-NEXT: ret <2 x i32> [[I10]]
474 %i916 = lshr <2 x i64> %d18, <i64 32, i64 poison>
475 %i917 = trunc <2 x i64> %i916 to <2 x i32>
476 %i10 = lshr <2 x i32> %i917, <i32 31, i32 poison>
480 define i32 @test30(i32 %A, i32 %B, i32 %C) {
481 ; CHECK-LABEL: @test30(
482 ; CHECK-NEXT: [[X1:%.*]] = and i32 [[A:%.*]], [[B:%.*]]
483 ; CHECK-NEXT: [[Z:%.*]] = shl i32 [[X1]], [[C:%.*]]
484 ; CHECK-NEXT: ret i32 [[Z]]
492 define i32 @test31(i32 %A, i32 %B, i32 %C) {
493 ; CHECK-LABEL: @test31(
494 ; CHECK-NEXT: [[X1:%.*]] = or i32 [[A:%.*]], [[B:%.*]]
495 ; CHECK-NEXT: [[Z:%.*]] = lshr i32 [[X1]], [[C:%.*]]
496 ; CHECK-NEXT: ret i32 [[Z]]
504 define i32 @test32(i32 %A, i32 %B, i32 %C) {
505 ; CHECK-LABEL: @test32(
506 ; CHECK-NEXT: [[X1:%.*]] = xor i32 [[A:%.*]], [[B:%.*]]
507 ; CHECK-NEXT: [[Z:%.*]] = ashr i32 [[X1]], [[C:%.*]]
508 ; CHECK-NEXT: ret i32 [[Z]]
516 define i1 @test33(i32 %X) {
517 ; CHECK-LABEL: @test33(
518 ; CHECK-NEXT: [[I1_MASK:%.*]] = and i32 [[X:%.*]], 16777216
519 ; CHECK-NEXT: [[I2:%.*]] = icmp ne i32 [[I1_MASK]], 0
520 ; CHECK-NEXT: ret i1 [[I2]]
523 %i2 = icmp slt i32 %i1, 0
527 define <2 x i1> @test33vec(<2 x i32> %X) {
528 ; CHECK-LABEL: @test33vec(
529 ; CHECK-NEXT: [[I1_MASK:%.*]] = and <2 x i32> [[X:%.*]], <i32 16777216, i32 16777216>
530 ; CHECK-NEXT: [[I2:%.*]] = icmp ne <2 x i32> [[I1_MASK]], zeroinitializer
531 ; CHECK-NEXT: ret <2 x i1> [[I2]]
533 %i1 = shl <2 x i32> %X, <i32 7, i32 7>
534 %i2 = icmp slt <2 x i32> %i1, zeroinitializer
538 define i1 @test34(i32 %X) {
539 ; CHECK-LABEL: @test34(
540 ; CHECK-NEXT: ret i1 false
543 %i2 = icmp slt i32 %i1, 0
547 define i1 @test35(i32 %X) {
548 ; CHECK-LABEL: @test35(
549 ; CHECK-NEXT: [[I2:%.*]] = icmp slt i32 [[X:%.*]], 0
550 ; CHECK-NEXT: ret i1 [[I2]]
553 %i2 = icmp slt i32 %i1, 0
557 define <2 x i1> @test35vec(<2 x i32> %X) {
558 ; CHECK-LABEL: @test35vec(
559 ; CHECK-NEXT: [[I2:%.*]] = icmp slt <2 x i32> [[X:%.*]], zeroinitializer
560 ; CHECK-NEXT: ret <2 x i1> [[I2]]
562 %i1 = ashr <2 x i32> %X, <i32 7, i32 7>
563 %i2 = icmp slt <2 x i32> %i1, zeroinitializer
567 define i128 @test36(i128 %A, i128 %B) {
568 ; CHECK-LABEL: @test36(
569 ; CHECK-NEXT: [[I231:%.*]] = or i128 [[B:%.*]], [[A:%.*]]
570 ; CHECK-NEXT: [[INS:%.*]] = and i128 [[I231]], 18446744073709551615
571 ; CHECK-NEXT: ret i128 [[INS]]
573 %i27 = shl i128 %A, 64
574 %i23 = shl i128 %B, 64
575 %ins = or i128 %i23, %i27
576 %i45 = lshr i128 %ins, 64
580 define i64 @test37(i128 %A, i32 %B) {
581 ; CHECK-LABEL: @test37(
582 ; CHECK-NEXT: [[I22:%.*]] = zext i32 [[B:%.*]] to i128
583 ; CHECK-NEXT: [[I23:%.*]] = shl nuw nsw i128 [[I22]], 32
584 ; CHECK-NEXT: [[INS:%.*]] = or i128 [[I23]], [[A:%.*]]
585 ; CHECK-NEXT: [[I46:%.*]] = trunc i128 [[INS]] to i64
586 ; CHECK-NEXT: ret i64 [[I46]]
588 %i27 = shl i128 %A, 64
589 %i22 = zext i32 %B to i128
590 %i23 = shl i128 %i22, 96
591 %ins = or i128 %i23, %i27
592 %i45 = lshr i128 %ins, 64
593 %i46 = trunc i128 %i45 to i64
597 define <2 x i32> @shl_nuw_nsw_splat_vec(<2 x i8> %x) {
598 ; CHECK-LABEL: @shl_nuw_nsw_splat_vec(
599 ; CHECK-NEXT: [[T2:%.*]] = zext <2 x i8> [[X:%.*]] to <2 x i32>
600 ; CHECK-NEXT: [[T3:%.*]] = shl nuw nsw <2 x i32> [[T2]], <i32 17, i32 17>
601 ; CHECK-NEXT: ret <2 x i32> [[T3]]
603 %t2 = zext <2 x i8> %x to <2 x i32>
604 %t3 = shl <2 x i32> %t2, <i32 17, i32 17>
608 define i32 @test38(i32 %x) {
609 ; CHECK-LABEL: @test38(
610 ; CHECK-NEXT: [[REM1:%.*]] = and i32 [[X:%.*]], 31
611 ; CHECK-NEXT: [[SHL:%.*]] = shl nuw i32 1, [[REM1]]
612 ; CHECK-NEXT: ret i32 [[SHL]]
614 %rem = srem i32 %x, 32
615 %shl = shl i32 1, %rem
619 define <2 x i32> @test38_uniform(<2 x i32> %x) {
620 ; CHECK-LABEL: @test38_uniform(
621 ; CHECK-NEXT: [[REM1:%.*]] = and <2 x i32> [[X:%.*]], <i32 31, i32 31>
622 ; CHECK-NEXT: [[SHL:%.*]] = shl nuw <2 x i32> <i32 1, i32 1>, [[REM1]]
623 ; CHECK-NEXT: ret <2 x i32> [[SHL]]
625 %rem = srem <2 x i32> %x, <i32 32, i32 32>
626 %shl = shl <2 x i32> <i32 1, i32 1>, %rem
630 define <3 x i32> @test38_nonuniform(<3 x i32> %x) {
631 ; CHECK-LABEL: @test38_nonuniform(
632 ; CHECK-NEXT: [[REM1:%.*]] = and <3 x i32> [[X:%.*]], <i32 31, i32 15, i32 0>
633 ; CHECK-NEXT: [[SHL:%.*]] = shl nuw <3 x i32> <i32 1, i32 1, i32 1>, [[REM1]]
634 ; CHECK-NEXT: ret <3 x i32> [[SHL]]
636 %rem = srem <3 x i32> %x, <i32 32, i32 16, i32 1>
637 %shl = shl <3 x i32> <i32 1, i32 1, i32 1>, %rem
641 define <2 x i32> @test38_poison(<2 x i32> %x) {
642 ; CHECK-LABEL: @test38_poison(
643 ; CHECK-NEXT: ret <2 x i32> poison
645 %rem = srem <2 x i32> %x, <i32 32, i32 poison>
646 %shl = shl <2 x i32> <i32 1, i32 1>, %rem
650 ; <rdar://problem/8756731>
651 define i8 @test39(i32 %a0) {
652 ; CHECK-LABEL: @test39(
654 ; CHECK-NEXT: [[I4:%.*]] = trunc i32 [[A0:%.*]] to i8
655 ; CHECK-NEXT: [[I5:%.*]] = shl i8 [[I4]], 5
656 ; CHECK-NEXT: [[I49:%.*]] = shl i8 [[I4]], 6
657 ; CHECK-NEXT: [[I50:%.*]] = and i8 [[I49]], 64
658 ; CHECK-NEXT: [[I51:%.*]] = xor i8 [[I50]], [[I5]]
659 ; CHECK-NEXT: [[TMP0:%.*]] = lshr exact i8 [[I5]], 3
660 ; CHECK-NEXT: [[I54:%.*]] = and i8 [[TMP0]], 16
661 ; CHECK-NEXT: [[I55:%.*]] = or disjoint i8 [[I54]], [[I51]]
662 ; CHECK-NEXT: ret i8 [[I55]]
665 %i4 = trunc i32 %a0 to i8
667 %i48 = and i8 %i5, 32
668 %i49 = lshr i8 %i48, 5
669 %i50 = mul i8 %i49, 64
670 %i51 = xor i8 %i50, %i5
671 %i52 = and i8 %i51, -128
672 %i53 = lshr i8 %i52, 7
673 %i54 = mul i8 %i53, 16
674 %i55 = xor i8 %i54, %i51
678 define i32 @test42(i32 %a, i32 %b) {
679 ; CHECK-LABEL: @test42(
680 ; CHECK-NEXT: [[DIV:%.*]] = lshr exact i32 4096, [[B:%.*]]
681 ; CHECK-NEXT: [[DIV2:%.*]] = udiv i32 [[A:%.*]], [[DIV]]
682 ; CHECK-NEXT: ret i32 [[DIV2]]
684 %div = lshr i32 4096, %b ; must be exact otherwise we'd divide by zero
685 %div2 = udiv i32 %a, %div
689 define <2 x i32> @test42vec(<2 x i32> %a, <2 x i32> %b) {
690 ; CHECK-LABEL: @test42vec(
691 ; CHECK-NEXT: [[DIV:%.*]] = lshr exact <2 x i32> <i32 4096, i32 4096>, [[B:%.*]]
692 ; CHECK-NEXT: [[DIV2:%.*]] = udiv <2 x i32> [[A:%.*]], [[DIV]]
693 ; CHECK-NEXT: ret <2 x i32> [[DIV2]]
695 %div = lshr <2 x i32> <i32 4096, i32 4096>, %b ; must be exact otherwise we'd divide by zero
696 %div2 = udiv <2 x i32> %a, %div
700 define i32 @test43(i32 %a, i32 %b) {
701 ; CHECK-LABEL: @test43(
702 ; CHECK-NEXT: [[TMP1:%.*]] = add i32 [[B:%.*]], 12
703 ; CHECK-NEXT: [[DIV21:%.*]] = lshr i32 [[A:%.*]], [[TMP1]]
704 ; CHECK-NEXT: ret i32 [[DIV21]]
706 %div = shl i32 4096, %b ; must be exact otherwise we'd divide by zero
707 %div2 = udiv i32 %a, %div
711 define i32 @test44(i32 %a) {
712 ; CHECK-LABEL: @test44(
713 ; CHECK-NEXT: [[Y:%.*]] = shl i32 [[A:%.*]], 5
714 ; CHECK-NEXT: ret i32 [[Y]]
716 %y = shl nuw i32 %a, 1
721 define i32 @test44_multiuse(i32 %a) {
722 ; CHECK-LABEL: @test44_multiuse(
723 ; CHECK-NEXT: [[Y:%.*]] = shl nuw i32 [[A:%.*]], 1
724 ; CHECK-NEXT: call void @use_i32(i32 [[Y]])
725 ; CHECK-NEXT: [[Z:%.*]] = shl i32 [[A]], 5
726 ; CHECK-NEXT: ret i32 [[Z]]
728 %y = shl nuw i32 %a, 1
729 call void @use_i32(i32 %y)
734 define i32 @test45(i32 %a) {
735 ; CHECK-LABEL: @test45(
736 ; CHECK-NEXT: [[Y:%.*]] = lshr i32 [[A:%.*]], 5
737 ; CHECK-NEXT: ret i32 [[Y]]
739 %y = lshr exact i32 %a, 1
744 define i32 @test45_multiuse(i32 %a) {
745 ; CHECK-LABEL: @test45_multiuse(
746 ; CHECK-NEXT: [[Y:%.*]] = lshr exact i32 [[A:%.*]], 1
747 ; CHECK-NEXT: call void @use_i32(i32 [[Y]])
748 ; CHECK-NEXT: [[Z:%.*]] = lshr i32 [[A]], 5
749 ; CHECK-NEXT: ret i32 [[Z]]
751 %y = lshr exact i32 %a, 1
752 call void @use_i32(i32 %y)
757 ; (X >>?exact C1) << C2 --> X >>?exact (C1-C2)
759 define i32 @test46(i32 %a) {
760 ; CHECK-LABEL: @test46(
761 ; CHECK-NEXT: [[Z:%.*]] = ashr exact i32 [[A:%.*]], 2
762 ; CHECK-NEXT: ret i32 [[Z]]
764 %y = ashr exact i32 %a, 3
769 ; (X >>?exact C1) << C2 --> X >>?exact (C1-C2)
771 define <2 x i32> @test46_splat_vec(<2 x i32> %a) {
772 ; CHECK-LABEL: @test46_splat_vec(
773 ; CHECK-NEXT: [[Z:%.*]] = ashr exact <2 x i32> [[A:%.*]], <i32 2, i32 2>
774 ; CHECK-NEXT: ret <2 x i32> [[Z]]
776 %y = ashr exact <2 x i32> %a, <i32 3, i32 3>
777 %z = shl <2 x i32> %y, <i32 1, i32 1>
781 ; (X >>?exact C1) << C2 --> X >>?exact (C1-C2)
783 define i8 @test47(i8 %a) {
784 ; CHECK-LABEL: @test47(
785 ; CHECK-NEXT: [[Z:%.*]] = lshr exact i8 [[A:%.*]], 2
786 ; CHECK-NEXT: ret i8 [[Z]]
788 %y = lshr exact i8 %a, 3
793 ; (X >>?exact C1) << C2 --> X >>?exact (C1-C2)
795 define <2 x i8> @test47_splat_vec(<2 x i8> %a) {
796 ; CHECK-LABEL: @test47_splat_vec(
797 ; CHECK-NEXT: [[Z:%.*]] = lshr exact <2 x i8> [[A:%.*]], <i8 2, i8 2>
798 ; CHECK-NEXT: ret <2 x i8> [[Z]]
800 %y = lshr exact <2 x i8> %a, <i8 3, i8 3>
801 %z = shl <2 x i8> %y, <i8 1, i8 1>
805 ; (X >>u,exact C1) << C2 --> X << (C2-C1) when C2 > C1
807 define i32 @test48(i32 %x) {
808 ; CHECK-LABEL: @test48(
809 ; CHECK-NEXT: [[B:%.*]] = shl i32 [[X:%.*]], 2
810 ; CHECK-NEXT: ret i32 [[B]]
812 %A = lshr exact i32 %x, 1
817 ; Verify that wrap flags are preserved from the original 'shl'.
819 define i32 @test48_nuw_nsw(i32 %x) {
820 ; CHECK-LABEL: @test48_nuw_nsw(
821 ; CHECK-NEXT: [[B:%.*]] = shl nuw nsw i32 [[X:%.*]], 2
822 ; CHECK-NEXT: ret i32 [[B]]
824 %A = lshr exact i32 %x, 1
825 %B = shl nuw nsw i32 %A, 3
829 ; (X >>u,exact C1) << C2 --> X << (C2-C1) when splatted C2 > C1
831 define <2 x i32> @test48_splat_vec(<2 x i32> %x) {
832 ; CHECK-LABEL: @test48_splat_vec(
833 ; CHECK-NEXT: [[B:%.*]] = shl nuw nsw <2 x i32> [[X:%.*]], <i32 2, i32 2>
834 ; CHECK-NEXT: ret <2 x i32> [[B]]
836 %A = lshr exact <2 x i32> %x, <i32 1, i32 1>
837 %B = shl nsw nuw <2 x i32> %A, <i32 3, i32 3>
841 ; (X >>s,exact C1) << C2 --> X << (C2-C1) when C2 > C1
843 define i32 @test49(i32 %x) {
844 ; CHECK-LABEL: @test49(
845 ; CHECK-NEXT: [[B:%.*]] = shl i32 [[X:%.*]], 2
846 ; CHECK-NEXT: ret i32 [[B]]
848 %A = ashr exact i32 %x, 1
853 ; Verify that wrap flags are preserved from the original 'shl'.
855 define i32 @test49_nuw_nsw(i32 %x) {
856 ; CHECK-LABEL: @test49_nuw_nsw(
857 ; CHECK-NEXT: [[B:%.*]] = shl nuw nsw i32 [[X:%.*]], 2
858 ; CHECK-NEXT: ret i32 [[B]]
860 %A = ashr exact i32 %x, 1
861 %B = shl nuw nsw i32 %A, 3
865 ; (X >>s,exact C1) << C2 --> X << (C2-C1) when splatted C2 > C1
867 define <2 x i32> @test49_splat_vec(<2 x i32> %x) {
868 ; CHECK-LABEL: @test49_splat_vec(
869 ; CHECK-NEXT: [[B:%.*]] = shl nuw nsw <2 x i32> [[X:%.*]], <i32 2, i32 2>
870 ; CHECK-NEXT: ret <2 x i32> [[B]]
872 %A = ashr exact <2 x i32> %x, <i32 1, i32 1>
873 %B = shl nsw nuw <2 x i32> %A, <i32 3, i32 3>
877 ; (X <<nsw C1) >>s C2 --> X >>s (C2-C1)
879 define i32 @test50(i32 %x) {
880 ; CHECK-LABEL: @test50(
881 ; CHECK-NEXT: [[B:%.*]] = ashr i32 [[X:%.*]], 2
882 ; CHECK-NEXT: ret i32 [[B]]
884 %A = shl nsw i32 %x, 1
889 ; (X <<nsw C1) >>s C2 --> X >>s (C2-C1)
890 ; Also, check that exact is propagated.
892 define <2 x i32> @test50_splat_vec(<2 x i32> %x) {
893 ; CHECK-LABEL: @test50_splat_vec(
894 ; CHECK-NEXT: [[B:%.*]] = ashr exact <2 x i32> [[X:%.*]], <i32 2, i32 2>
895 ; CHECK-NEXT: ret <2 x i32> [[B]]
897 %A = shl nsw <2 x i32> %x, <i32 1, i32 1>
898 %B = ashr exact <2 x i32> %A, <i32 3, i32 3>
902 ; (X <<nuw C1) >>u C2 --> X >>u (C2-C1)
904 define i32 @test51(i32 %x) {
905 ; CHECK-LABEL: @test51(
906 ; CHECK-NEXT: [[B:%.*]] = lshr i32 [[X:%.*]], 2
907 ; CHECK-NEXT: ret i32 [[B]]
909 %A = shl nuw i32 %x, 1
914 ; (X <<nuw C1) >>u C2 --> X >>u (C2-C1) with splats
915 ; Also, check that exact is propagated.
917 define <2 x i32> @test51_splat_vec(<2 x i32> %x) {
918 ; CHECK-LABEL: @test51_splat_vec(
919 ; CHECK-NEXT: [[B:%.*]] = lshr exact <2 x i32> [[X:%.*]], <i32 2, i32 2>
920 ; CHECK-NEXT: ret <2 x i32> [[B]]
922 %A = shl nuw <2 x i32> %x, <i32 1, i32 1>
923 %B = lshr exact <2 x i32> %A, <i32 3, i32 3>
927 ; (X << C1) >>u C2 --> X >>u (C2-C1) & (-1 >> C2)
928 ; Also, check that exact is propagated.
930 define i32 @test51_no_nuw(i32 %x) {
931 ; CHECK-LABEL: @test51_no_nuw(
932 ; CHECK-NEXT: [[TMP1:%.*]] = lshr exact i32 [[X:%.*]], 2
933 ; CHECK-NEXT: [[B:%.*]] = and i32 [[TMP1]], 536870911
934 ; CHECK-NEXT: ret i32 [[B]]
937 %B = lshr exact i32 %A, 3
941 ; (X << C1) >>u C2 --> X >>u (C2-C1) & (-1 >> C2)
943 define <2 x i32> @test51_no_nuw_splat_vec(<2 x i32> %x) {
944 ; CHECK-LABEL: @test51_no_nuw_splat_vec(
945 ; CHECK-NEXT: [[TMP1:%.*]] = lshr <2 x i32> [[X:%.*]], <i32 2, i32 2>
946 ; CHECK-NEXT: [[B:%.*]] = and <2 x i32> [[TMP1]], <i32 536870911, i32 536870911>
947 ; CHECK-NEXT: ret <2 x i32> [[B]]
949 %A = shl <2 x i32> %x, <i32 1, i32 1>
950 %B = lshr <2 x i32> %A, <i32 3, i32 3>
954 ; (X <<nsw C1) >>s C2 --> X <<nsw (C1 - C2)
956 define i32 @test52(i32 %x) {
957 ; CHECK-LABEL: @test52(
958 ; CHECK-NEXT: [[B:%.*]] = shl nsw i32 [[X:%.*]], 2
959 ; CHECK-NEXT: ret i32 [[B]]
961 %A = shl nsw i32 %x, 3
966 ; (X <<nsw C1) >>s C2 --> X <<nsw (C1 - C2)
968 define <2 x i32> @test52_splat_vec(<2 x i32> %x) {
969 ; CHECK-LABEL: @test52_splat_vec(
970 ; CHECK-NEXT: [[B:%.*]] = shl nsw <2 x i32> [[X:%.*]], <i32 2, i32 2>
971 ; CHECK-NEXT: ret <2 x i32> [[B]]
973 %A = shl nsw <2 x i32> %x, <i32 3, i32 3>
974 %B = ashr <2 x i32> %A, <i32 1, i32 1>
978 ; (X <<nuw C1) >>u C2 --> X <<nuw/nsw (C1 - C2)
980 define i32 @test53(i32 %x) {
981 ; CHECK-LABEL: @test53(
982 ; CHECK-NEXT: [[B:%.*]] = shl nuw nsw i32 [[X:%.*]], 2
983 ; CHECK-NEXT: ret i32 [[B]]
985 %A = shl nuw i32 %x, 3
990 ; (X <<nuw C1) >>u C2 --> X <<nuw/nsw (C1 - C2)
992 define <2 x i32> @test53_splat_vec(<2 x i32> %x) {
993 ; CHECK-LABEL: @test53_splat_vec(
994 ; CHECK-NEXT: [[B:%.*]] = shl nuw nsw <2 x i32> [[X:%.*]], <i32 2, i32 2>
995 ; CHECK-NEXT: ret <2 x i32> [[B]]
997 %A = shl nuw <2 x i32> %x, <i32 3, i32 3>
998 %B = lshr <2 x i32> %A, <i32 1, i32 1>
1002 ; (X << C1) >>u C2 --> X << (C1 - C2) & (-1 >> C2)
1004 define i8 @test53_no_nuw(i8 %x) {
1005 ; CHECK-LABEL: @test53_no_nuw(
1006 ; CHECK-NEXT: [[TMP1:%.*]] = shl i8 [[X:%.*]], 2
1007 ; CHECK-NEXT: [[B:%.*]] = and i8 [[TMP1]], 124
1008 ; CHECK-NEXT: ret i8 [[B]]
1015 ; (X << C1) >>u C2 --> X << (C1 - C2) & (-1 >> C2)
1017 define <2 x i8> @test53_no_nuw_splat_vec(<2 x i8> %x) {
1018 ; CHECK-LABEL: @test53_no_nuw_splat_vec(
1019 ; CHECK-NEXT: [[TMP1:%.*]] = shl <2 x i8> [[X:%.*]], <i8 2, i8 2>
1020 ; CHECK-NEXT: [[B:%.*]] = and <2 x i8> [[TMP1]], <i8 124, i8 124>
1021 ; CHECK-NEXT: ret <2 x i8> [[B]]
1023 %A = shl <2 x i8> %x, <i8 3, i8 3>
1024 %B = lshr <2 x i8> %A, <i8 1, i8 1>
1028 define i32 @test54(i32 %x) {
1029 ; CHECK-LABEL: @test54(
1030 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 3
1031 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[TMP1]], 16
1032 ; CHECK-NEXT: ret i32 [[AND]]
1034 %shr2 = lshr i32 %x, 1
1035 %shl = shl i32 %shr2, 4
1036 %and = and i32 %shl, 16
1040 define <2 x i32> @test54_splat_vec(<2 x i32> %x) {
1041 ; CHECK-LABEL: @test54_splat_vec(
1042 ; CHECK-NEXT: [[TMP1:%.*]] = shl <2 x i32> [[X:%.*]], <i32 3, i32 3>
1043 ; CHECK-NEXT: [[AND:%.*]] = and <2 x i32> [[TMP1]], <i32 16, i32 16>
1044 ; CHECK-NEXT: ret <2 x i32> [[AND]]
1046 %shr2 = lshr <2 x i32> %x, <i32 1, i32 1>
1047 %shl = shl <2 x i32> %shr2, <i32 4, i32 4>
1048 %and = and <2 x i32> %shl, <i32 16, i32 16>
1052 define i32 @test55(i32 %x) {
1053 ; CHECK-LABEL: @test55(
1054 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 3
1055 ; CHECK-NEXT: [[OR:%.*]] = or i32 [[TMP1]], 8
1056 ; CHECK-NEXT: ret i32 [[OR]]
1058 %shr2 = lshr i32 %x, 1
1059 %shl = shl i32 %shr2, 4
1060 %or = or i32 %shl, 8
1064 define i32 @test56(i32 %x) {
1065 ; CHECK-LABEL: @test56(
1066 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 3
1067 ; CHECK-NEXT: [[SHL:%.*]] = and i32 [[TMP1]], -16
1068 ; CHECK-NEXT: [[OR:%.*]] = or disjoint i32 [[SHL]], 7
1069 ; CHECK-NEXT: ret i32 [[OR]]
1071 %shr2 = lshr i32 %x, 1
1072 %shl = shl i32 %shr2, 4
1073 %or = or i32 %shl, 7
1077 define i32 @test57(i32 %x) {
1078 ; CHECK-LABEL: @test57(
1079 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 3
1080 ; CHECK-NEXT: [[SHL:%.*]] = and i32 [[TMP1]], -16
1081 ; CHECK-NEXT: [[OR:%.*]] = or disjoint i32 [[SHL]], 7
1082 ; CHECK-NEXT: ret i32 [[OR]]
1084 %shr = ashr i32 %x, 1
1085 %shl = shl i32 %shr, 4
1086 %or = or i32 %shl, 7
1090 define i32 @test58(i32 %x) {
1091 ; CHECK-LABEL: @test58(
1092 ; CHECK-NEXT: [[TMP1:%.*]] = ashr i32 [[X:%.*]], 3
1093 ; CHECK-NEXT: [[OR:%.*]] = or i32 [[TMP1]], 1
1094 ; CHECK-NEXT: ret i32 [[OR]]
1096 %shr = ashr i32 %x, 4
1097 %shl = shl i32 %shr, 1
1098 %or = or i32 %shl, 1
1102 define <2 x i32> @test58_splat_vec(<2 x i32> %x) {
1103 ; CHECK-LABEL: @test58_splat_vec(
1104 ; CHECK-NEXT: [[TMP1:%.*]] = ashr <2 x i32> [[X:%.*]], <i32 3, i32 3>
1105 ; CHECK-NEXT: [[OR:%.*]] = or <2 x i32> [[TMP1]], <i32 1, i32 1>
1106 ; CHECK-NEXT: ret <2 x i32> [[OR]]
1108 %shr = ashr <2 x i32> %x, <i32 4, i32 4>
1109 %shl = shl <2 x i32> %shr, <i32 1, i32 1>
1110 %or = or <2 x i32> %shl, <i32 1, i32 1>
1114 define i32 @test59(i32 %x) {
1115 ; CHECK-LABEL: @test59(
1116 ; CHECK-NEXT: [[TMP1:%.*]] = ashr i32 [[X:%.*]], 3
1117 ; CHECK-NEXT: [[SHL:%.*]] = and i32 [[TMP1]], -4
1118 ; CHECK-NEXT: [[OR:%.*]] = or disjoint i32 [[SHL]], 2
1119 ; CHECK-NEXT: ret i32 [[OR]]
1121 %shr = ashr i32 %x, 4
1122 %shl = shl i32 %shr, 1
1123 %or = or i32 %shl, 2
1127 ; propagate "exact" trait
1128 define i32 @test60(i32 %x) {
1129 ; CHECK-LABEL: @test60(
1130 ; CHECK-NEXT: [[SHL:%.*]] = ashr exact i32 [[X:%.*]], 3
1131 ; CHECK-NEXT: [[OR:%.*]] = or i32 [[SHL]], 1
1132 ; CHECK-NEXT: ret i32 [[OR]]
1134 %shr = ashr exact i32 %x, 4
1135 %shl = shl i32 %shr, 1
1136 %or = or i32 %shl, 1
1141 define void @test61(i128 %arg, i1 %c1, i1 %c2, i1 %c3, i1 %c4) {
1142 ; CHECK-LABEL: @test61(
1144 ; CHECK-NEXT: br i1 [[C1:%.*]], label [[BB1:%.*]], label [[BB12:%.*]]
1146 ; CHECK-NEXT: br label [[BB2:%.*]]
1148 ; CHECK-NEXT: br i1 [[C2:%.*]], label [[BB3:%.*]], label [[BB7:%.*]]
1150 ; CHECK-NEXT: br label [[BB8:%.*]]
1152 ; CHECK-NEXT: br i1 [[C3:%.*]], label [[BB8]], label [[BB2]]
1154 ; CHECK-NEXT: br i1 poison, label [[BB11:%.*]], label [[BB12]]
1156 ; CHECK-NEXT: br i1 [[C4:%.*]], label [[BB1]], label [[BB12]]
1158 ; CHECK-NEXT: ret void
1161 br i1 %c1, label %bb1, label %bb12
1163 bb1: ; preds = %bb11, %bb
1166 bb2: ; preds = %bb7, %bb1
1167 br i1 %c2, label %bb3, label %bb7
1170 %i = lshr i128 %arg, 36893488147419103232
1171 %i4 = shl i128 %i, 0
1172 %i5 = or i128 %i4, 0
1173 %i6 = trunc i128 %i5 to i16
1177 br i1 %c3, label %bb8, label %bb2
1179 bb8: ; preds = %bb7, %bb3
1180 %i9 = phi i16 [ %i6, %bb3 ], [ poison, %bb7 ]
1181 %i10 = icmp eq i16 %i9, 0
1182 br i1 %i10, label %bb11, label %bb12
1184 bb11: ; preds = %bb8
1185 br i1 %c4, label %bb1, label %bb12
1187 bb12: ; preds = %bb11, %bb8, %bb
1191 define i32 @test62(i32 %a) {
1192 ; CHECK-LABEL: @test62(
1193 ; CHECK-NEXT: ret i32 poison
1195 %b = ashr i32 %a, 32 ; shift all bits out
1199 define <4 x i32> @test62_splat_vector(<4 x i32> %a) {
1200 ; CHECK-LABEL: @test62_splat_vector(
1201 ; CHECK-NEXT: ret <4 x i32> poison
1203 %b = ashr <4 x i32> %a, <i32 32, i32 32, i32 32, i32 32> ; shift all bits out
1207 define <4 x i32> @test62_non_splat_vector(<4 x i32> %a) {
1208 ; CHECK-LABEL: @test62_non_splat_vector(
1209 ; CHECK-NEXT: [[B:%.*]] = ashr <4 x i32> [[A:%.*]], <i32 32, i32 0, i32 1, i32 2>
1210 ; CHECK-NEXT: ret <4 x i32> [[B]]
1212 %b = ashr <4 x i32> %a, <i32 32, i32 0, i32 1, i32 2> ; shift all bits out
1216 define <2 x i65> @test_63(<2 x i64> %t) {
1217 ; CHECK-LABEL: @test_63(
1218 ; CHECK-NEXT: [[A:%.*]] = zext <2 x i64> [[T:%.*]] to <2 x i65>
1219 ; CHECK-NEXT: [[SEXT:%.*]] = shl <2 x i65> [[A]], <i65 33, i65 33>
1220 ; CHECK-NEXT: [[B:%.*]] = ashr exact <2 x i65> [[SEXT]], <i65 33, i65 33>
1221 ; CHECK-NEXT: ret <2 x i65> [[B]]
1223 %a = zext <2 x i64> %t to <2 x i65>
1224 %sext = shl <2 x i65> %a, <i65 33, i65 33>
1225 %b = ashr <2 x i65> %sext, <i65 33, i65 33>
1229 define i32 @test_shl_zext_bool(i1 %t) {
1230 ; CHECK-LABEL: @test_shl_zext_bool(
1231 ; CHECK-NEXT: [[SHL:%.*]] = select i1 [[T:%.*]], i32 4, i32 0
1232 ; CHECK-NEXT: ret i32 [[SHL]]
1234 %ext = zext i1 %t to i32
1235 %shl = shl i32 %ext, 2
1239 define <2 x i32> @test_shl_zext_bool_splat(<2 x i1> %t) {
1240 ; CHECK-LABEL: @test_shl_zext_bool_splat(
1241 ; CHECK-NEXT: [[SHL:%.*]] = select <2 x i1> [[T:%.*]], <2 x i32> <i32 8, i32 8>, <2 x i32> zeroinitializer
1242 ; CHECK-NEXT: ret <2 x i32> [[SHL]]
1244 %ext = zext <2 x i1> %t to <2 x i32>
1245 %shl = shl <2 x i32> %ext, <i32 3, i32 3>
1249 define <2 x i32> @test_shl_zext_bool_vec(<2 x i1> %t) {
1250 ; CHECK-LABEL: @test_shl_zext_bool_vec(
1251 ; CHECK-NEXT: [[SHL:%.*]] = select <2 x i1> [[T:%.*]], <2 x i32> <i32 4, i32 8>, <2 x i32> zeroinitializer
1252 ; CHECK-NEXT: ret <2 x i32> [[SHL]]
1254 %ext = zext <2 x i1> %t to <2 x i32>
1255 %shl = shl <2 x i32> %ext, <i32 2, i32 3>
1259 define i32 @test_shl_zext_bool_not_constant(i1 %cmp, i32 %shamt) {
1260 ; CHECK-LABEL: @test_shl_zext_bool_not_constant(
1261 ; CHECK-NEXT: [[CONV3:%.*]] = zext i1 [[CMP:%.*]] to i32
1262 ; CHECK-NEXT: [[SHL:%.*]] = shl nuw i32 [[CONV3]], [[SHAMT:%.*]]
1263 ; CHECK-NEXT: ret i32 [[SHL]]
1265 %conv3 = zext i1 %cmp to i32
1266 %shl = shl i32 %conv3, %shamt
1270 define i64 @shl_zext(i32 %t) {
1271 ; CHECK-LABEL: @shl_zext(
1272 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[T:%.*]], 8
1273 ; CHECK-NEXT: [[SHL:%.*]] = zext i32 [[TMP1]] to i64
1274 ; CHECK-NEXT: ret i64 [[SHL]]
1276 %and = and i32 %t, 16777215
1277 %ext = zext i32 %and to i64
1278 %shl = shl i64 %ext, 8
1282 define i64 @shl_zext_extra_use(i32 %t) {
1283 ; CHECK-LABEL: @shl_zext_extra_use(
1284 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[T:%.*]], 16777215
1285 ; CHECK-NEXT: [[EXT:%.*]] = zext nneg i32 [[AND]] to i64
1286 ; CHECK-NEXT: call void @use(i64 [[EXT]])
1287 ; CHECK-NEXT: [[SHL:%.*]] = shl nuw nsw i64 [[EXT]], 8
1288 ; CHECK-NEXT: ret i64 [[SHL]]
1290 %and = and i32 %t, 16777215
1291 %ext = zext i32 %and to i64
1292 call void @use(i64 %ext)
1293 %shl = shl i64 %ext, 8
1297 define <2 x i64> @shl_zext_splat_vec(<2 x i32> %t) {
1298 ; CHECK-LABEL: @shl_zext_splat_vec(
1299 ; CHECK-NEXT: [[TMP1:%.*]] = shl <2 x i32> [[T:%.*]], <i32 8, i32 8>
1300 ; CHECK-NEXT: [[SHL:%.*]] = zext <2 x i32> [[TMP1]] to <2 x i64>
1301 ; CHECK-NEXT: ret <2 x i64> [[SHL]]
1303 %and = and <2 x i32> %t, <i32 16777215, i32 16777215>
1304 %ext = zext <2 x i32> %and to <2 x i64>
1305 %shl = shl <2 x i64> %ext, <i64 8, i64 8>
1309 define i64 @shl_zext_mul(i32 %t) {
1310 ; CHECK-LABEL: @shl_zext_mul(
1311 ; CHECK-NEXT: [[MUL:%.*]] = mul i32 [[T:%.*]], 16777215
1312 ; CHECK-NEXT: [[EXT:%.*]] = zext i32 [[MUL]] to i64
1313 ; CHECK-NEXT: [[SHL:%.*]] = shl nuw i64 [[EXT]], 32
1314 ; CHECK-NEXT: ret i64 [[SHL]]
1316 %mul = mul i32 %t, 16777215
1317 %ext = zext i32 %mul to i64
1318 %shl = shl i64 %ext, 32
1322 define <3 x i17> @shl_zext_mul_splat(<3 x i5> %t) {
1323 ; CHECK-LABEL: @shl_zext_mul_splat(
1324 ; CHECK-NEXT: [[MUL:%.*]] = mul <3 x i5> [[T:%.*]], <i5 13, i5 13, i5 13>
1325 ; CHECK-NEXT: [[EXT:%.*]] = zext <3 x i5> [[MUL]] to <3 x i17>
1326 ; CHECK-NEXT: [[SHL:%.*]] = shl nuw <3 x i17> [[EXT]], <i17 12, i17 12, i17 12>
1327 ; CHECK-NEXT: ret <3 x i17> [[SHL]]
1329 %mul = mul <3 x i5> %t, <i5 13, i5 13, i5 13>
1330 %ext = zext <3 x i5> %mul to <3 x i17>
1331 %shl = shl <3 x i17> %ext, <i17 12, i17 12, i17 12>
1335 define i64 @shl_zext_mul_low_shift_amount(i32 %t) {
1336 ; CHECK-LABEL: @shl_zext_mul_low_shift_amount(
1337 ; CHECK-NEXT: [[MUL:%.*]] = mul i32 [[T:%.*]], 16777215
1338 ; CHECK-NEXT: [[EXT:%.*]] = zext i32 [[MUL]] to i64
1339 ; CHECK-NEXT: [[SHL:%.*]] = shl nuw nsw i64 [[EXT]], 31
1340 ; CHECK-NEXT: ret i64 [[SHL]]
1342 %mul = mul i32 %t, 16777215
1343 %ext = zext i32 %mul to i64
1344 %shl = shl i64 %ext, 31
1348 define i64 @shl_zext_mul_extra_use1(i32 %t) {
1349 ; CHECK-LABEL: @shl_zext_mul_extra_use1(
1350 ; CHECK-NEXT: [[MUL:%.*]] = mul i32 [[T:%.*]], 16777215
1351 ; CHECK-NEXT: [[EXT:%.*]] = zext i32 [[MUL]] to i64
1352 ; CHECK-NEXT: call void @use(i64 [[EXT]])
1353 ; CHECK-NEXT: [[SHL:%.*]] = shl nuw i64 [[EXT]], 32
1354 ; CHECK-NEXT: ret i64 [[SHL]]
1356 %mul = mul i32 %t, 16777215
1357 %ext = zext i32 %mul to i64
1358 call void @use(i64 %ext)
1359 %shl = shl i64 %ext, 32
1363 define i64 @shl_zext_mul_extra_use2(i32 %t) {
1364 ; CHECK-LABEL: @shl_zext_mul_extra_use2(
1365 ; CHECK-NEXT: [[MUL:%.*]] = mul i32 [[T:%.*]], 16777215
1366 ; CHECK-NEXT: call void @use_i32(i32 [[MUL]])
1367 ; CHECK-NEXT: [[EXT:%.*]] = zext i32 [[MUL]] to i64
1368 ; CHECK-NEXT: [[SHL:%.*]] = shl nuw i64 [[EXT]], 32
1369 ; CHECK-NEXT: ret i64 [[SHL]]
1371 %mul = mul i32 %t, 16777215
1372 call void @use_i32(i32 %mul)
1373 %ext = zext i32 %mul to i64
1374 %shl = shl i64 %ext, 32
1378 define <2 x i8> @ashr_demanded_bits_splat(<2 x i8> %x) {
1379 ; CHECK-LABEL: @ashr_demanded_bits_splat(
1380 ; CHECK-NEXT: [[SHR:%.*]] = ashr <2 x i8> [[X:%.*]], <i8 7, i8 7>
1381 ; CHECK-NEXT: ret <2 x i8> [[SHR]]
1383 %and = and <2 x i8> %x, <i8 128, i8 128>
1384 %shr = ashr <2 x i8> %and, <i8 7, i8 7>
1388 define <vscale x 8 x i8> @ashr_demanded_bits_splat2(<vscale x 8 x i8> %x) {
1389 ; CHECK-LABEL: @ashr_demanded_bits_splat2(
1390 ; CHECK-NEXT: [[SHR:%.*]] = ashr <vscale x 8 x i8> [[X:%.*]], shufflevector (<vscale x 8 x i8> insertelement (<vscale x 8 x i8> poison, i8 7, i64 0), <vscale x 8 x i8> poison, <vscale x 8 x i32> zeroinitializer)
1391 ; CHECK-NEXT: ret <vscale x 8 x i8> [[SHR]]
1393 %and = and <vscale x 8 x i8> %x, splat (i8 128)
1394 %shr = ashr <vscale x 8 x i8> %and, splat (i8 7)
1395 ret <vscale x 8 x i8> %shr
1398 define <2 x i8> @lshr_demanded_bits_splat(<2 x i8> %x) {
1399 ; CHECK-LABEL: @lshr_demanded_bits_splat(
1400 ; CHECK-NEXT: [[SHR:%.*]] = lshr <2 x i8> [[X:%.*]], <i8 7, i8 7>
1401 ; CHECK-NEXT: ret <2 x i8> [[SHR]]
1403 %and = and <2 x i8> %x, <i8 128, i8 128>
1404 %shr = lshr <2 x i8> %and, <i8 7, i8 7>
1408 define <vscale x 8 x i8> @lshr_demanded_bits_splat2(<vscale x 8 x i8> %x) {
1409 ; CHECK-LABEL: @lshr_demanded_bits_splat2(
1410 ; CHECK-NEXT: [[SHR:%.*]] = lshr <vscale x 8 x i8> [[X:%.*]], shufflevector (<vscale x 8 x i8> insertelement (<vscale x 8 x i8> poison, i8 7, i64 0), <vscale x 8 x i8> poison, <vscale x 8 x i32> zeroinitializer)
1411 ; CHECK-NEXT: ret <vscale x 8 x i8> [[SHR]]
1413 %and = and <vscale x 8 x i8> %x, splat (i8 128)
1414 %shr = lshr <vscale x 8 x i8> %and, splat (i8 7)
1415 ret <vscale x 8 x i8> %shr
1418 ; Make sure known bits works correctly with non power of 2 bit widths.
1419 define i7 @test65(i7 %a, i7 %b) {
1420 ; CHECK-LABEL: @test65(
1421 ; CHECK-NEXT: ret i7 0
1423 %shiftamt = and i7 %b, 6 ; this ensures the shift amount is even and less than the bit width.
1424 %x = lshr i7 42, %shiftamt ; 42 has a zero in every even numbered bit and a one in every odd bit.
1425 %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.
1429 define i32 @shl_select_add_true(i32 %x, i1 %cond) {
1430 ; CHECK-LABEL: @shl_select_add_true(
1431 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 1
1432 ; CHECK-NEXT: [[TMP2:%.*]] = add i32 [[TMP1]], 14
1433 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
1434 ; CHECK-NEXT: ret i32 [[TMP3]]
1437 %2 = select i1 %cond, i32 %1, i32 %x
1442 define i32 @shl_select_add_false(i32 %x, i1 %cond) {
1443 ; CHECK-LABEL: @shl_select_add_false(
1444 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 1
1445 ; CHECK-NEXT: [[TMP2:%.*]] = add i32 [[TMP1]], 14
1446 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP1]], i32 [[TMP2]]
1447 ; CHECK-NEXT: ret i32 [[TMP3]]
1450 %2 = select i1 %cond, i32 %x, i32 %1
1455 define i32 @shl_select_and_true(i32 %x, i1 %cond) {
1456 ; CHECK-LABEL: @shl_select_and_true(
1457 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 1
1458 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], 14
1459 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
1460 ; CHECK-NEXT: ret i32 [[TMP3]]
1463 %2 = select i1 %cond, i32 %1, i32 %x
1468 define i32 @shl_select_and_false(i32 %x, i1 %cond) {
1469 ; CHECK-LABEL: @shl_select_and_false(
1470 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 1
1471 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], 14
1472 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP1]], i32 [[TMP2]]
1473 ; CHECK-NEXT: ret i32 [[TMP3]]
1476 %2 = select i1 %cond, i32 %x, i32 %1
1481 define i32 @lshr_select_and_true(i32 %x, i1 %cond) {
1482 ; CHECK-LABEL: @lshr_select_and_true(
1483 ; CHECK-NEXT: [[TMP1:%.*]] = lshr i32 [[X:%.*]], 1
1484 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], 3
1485 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
1486 ; CHECK-NEXT: ret i32 [[TMP3]]
1489 %2 = select i1 %cond, i32 %1, i32 %x
1494 define i32 @lshr_select_and_false(i32 %x, i1 %cond) {
1495 ; CHECK-LABEL: @lshr_select_and_false(
1496 ; CHECK-NEXT: [[TMP1:%.*]] = lshr i32 [[X:%.*]], 1
1497 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], 3
1498 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP1]], i32 [[TMP2]]
1499 ; CHECK-NEXT: ret i32 [[TMP3]]
1502 %2 = select i1 %cond, i32 %x, i32 %1
1507 define i32 @ashr_select_and_true(i32 %x, i1 %cond) {
1508 ; CHECK-LABEL: @ashr_select_and_true(
1509 ; CHECK-NEXT: [[TMP1:%.*]] = ashr i32 [[X:%.*]], 1
1510 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], -1073741821
1511 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
1512 ; CHECK-NEXT: ret i32 [[TMP3]]
1514 %1 = and i32 %x, 2147483655
1515 %2 = select i1 %cond, i32 %1, i32 %x
1520 define i32 @ashr_select_and_false(i32 %x, i1 %cond) {
1521 ; CHECK-LABEL: @ashr_select_and_false(
1522 ; CHECK-NEXT: [[TMP1:%.*]] = ashr i32 [[X:%.*]], 1
1523 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], -1073741821
1524 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP1]], i32 [[TMP2]]
1525 ; CHECK-NEXT: ret i32 [[TMP3]]
1527 %1 = and i32 %x, 2147483655
1528 %2 = select i1 %cond, i32 %x, i32 %1
1533 define i32 @shl_select_or_true(i32 %x, i1 %cond) {
1534 ; CHECK-LABEL: @shl_select_or_true(
1535 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 1
1536 ; CHECK-NEXT: [[TMP2:%.*]] = or i32 [[TMP1]], 14
1537 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
1538 ; CHECK-NEXT: ret i32 [[TMP3]]
1541 %2 = select i1 %cond, i32 %1, i32 %x
1546 define i32 @shl_select_or_false(i32 %x, i1 %cond) {
1547 ; CHECK-LABEL: @shl_select_or_false(
1548 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 1
1549 ; CHECK-NEXT: [[TMP2:%.*]] = or i32 [[TMP1]], 14
1550 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP1]], i32 [[TMP2]]
1551 ; CHECK-NEXT: ret i32 [[TMP3]]
1554 %2 = select i1 %cond, i32 %x, i32 %1
1559 define i32 @lshr_select_or_true(i32 %x, i1 %cond) {
1560 ; CHECK-LABEL: @lshr_select_or_true(
1561 ; CHECK-NEXT: [[TMP1:%.*]] = lshr i32 [[X:%.*]], 1
1562 ; CHECK-NEXT: [[TMP2:%.*]] = or i32 [[TMP1]], 3
1563 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
1564 ; CHECK-NEXT: ret i32 [[TMP3]]
1567 %2 = select i1 %cond, i32 %1, i32 %x
1572 define i32 @lshr_select_or_false(i32 %x, i1 %cond) {
1573 ; CHECK-LABEL: @lshr_select_or_false(
1574 ; CHECK-NEXT: [[TMP1:%.*]] = lshr i32 [[X:%.*]], 1
1575 ; CHECK-NEXT: [[TMP2:%.*]] = or i32 [[TMP1]], 3
1576 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP1]], i32 [[TMP2]]
1577 ; CHECK-NEXT: ret i32 [[TMP3]]
1580 %2 = select i1 %cond, i32 %x, i32 %1
1585 define i32 @ashr_select_or_true(i32 %x, i1 %cond) {
1586 ; CHECK-LABEL: @ashr_select_or_true(
1587 ; CHECK-NEXT: [[TMP1:%.*]] = ashr i32 [[X:%.*]], 1
1588 ; CHECK-NEXT: [[TMP2:%.*]] = or i32 [[TMP1]], 3
1589 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
1590 ; CHECK-NEXT: ret i32 [[TMP3]]
1593 %2 = select i1 %cond, i32 %1, i32 %x
1598 define i32 @ashr_select_or_false(i32 %x, i1 %cond) {
1599 ; CHECK-LABEL: @ashr_select_or_false(
1600 ; CHECK-NEXT: [[TMP1:%.*]] = ashr i32 [[X:%.*]], 1
1601 ; CHECK-NEXT: [[TMP2:%.*]] = or i32 [[TMP1]], 3
1602 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP1]], i32 [[TMP2]]
1603 ; CHECK-NEXT: ret i32 [[TMP3]]
1606 %2 = select i1 %cond, i32 %x, i32 %1
1611 define i32 @shl_select_xor_true(i32 %x, i1 %cond) {
1612 ; CHECK-LABEL: @shl_select_xor_true(
1613 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 1
1614 ; CHECK-NEXT: [[TMP2:%.*]] = xor i32 [[TMP1]], 14
1615 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
1616 ; CHECK-NEXT: ret i32 [[TMP3]]
1619 %2 = select i1 %cond, i32 %1, i32 %x
1624 define i32 @shl_select_xor_false(i32 %x, i1 %cond) {
1625 ; CHECK-LABEL: @shl_select_xor_false(
1626 ; CHECK-NEXT: [[TMP1:%.*]] = shl i32 [[X:%.*]], 1
1627 ; CHECK-NEXT: [[TMP2:%.*]] = xor i32 [[TMP1]], 14
1628 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP1]], i32 [[TMP2]]
1629 ; CHECK-NEXT: ret i32 [[TMP3]]
1632 %2 = select i1 %cond, i32 %x, i32 %1
1637 define i32 @lshr_select_xor_true(i32 %x, i1 %cond) {
1638 ; CHECK-LABEL: @lshr_select_xor_true(
1639 ; CHECK-NEXT: [[TMP1:%.*]] = lshr i32 [[X:%.*]], 1
1640 ; CHECK-NEXT: [[TMP2:%.*]] = xor i32 [[TMP1]], 3
1641 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
1642 ; CHECK-NEXT: ret i32 [[TMP3]]
1645 %2 = select i1 %cond, i32 %1, i32 %x
1650 define i32 @lshr_select_xor_false(i32 %x, i1 %cond) {
1651 ; CHECK-LABEL: @lshr_select_xor_false(
1652 ; CHECK-NEXT: [[TMP1:%.*]] = lshr i32 [[X:%.*]], 1
1653 ; CHECK-NEXT: [[TMP2:%.*]] = xor i32 [[TMP1]], 3
1654 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP1]], i32 [[TMP2]]
1655 ; CHECK-NEXT: ret i32 [[TMP3]]
1658 %2 = select i1 %cond, i32 %x, i32 %1
1663 define i32 @ashr_select_xor_true(i32 %x, i1 %cond) {
1664 ; CHECK-LABEL: @ashr_select_xor_true(
1665 ; CHECK-NEXT: [[TMP1:%.*]] = ashr i32 [[X:%.*]], 1
1666 ; CHECK-NEXT: [[TMP2:%.*]] = xor i32 [[TMP1]], 3
1667 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP2]], i32 [[TMP1]]
1668 ; CHECK-NEXT: ret i32 [[TMP3]]
1671 %2 = select i1 %cond, i32 %1, i32 %x
1676 define i32 @ashr_select_xor_false(i32 %x, i1 %cond) {
1677 ; CHECK-LABEL: @ashr_select_xor_false(
1678 ; CHECK-NEXT: [[TMP1:%.*]] = ashr i32 [[X:%.*]], 1
1679 ; CHECK-NEXT: [[TMP2:%.*]] = xor i32 [[TMP1]], 3
1680 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[COND:%.*]], i32 [[TMP1]], i32 [[TMP2]]
1681 ; CHECK-NEXT: ret i32 [[TMP3]]
1684 %2 = select i1 %cond, i32 %x, i32 %1
1690 ; https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=4871
1691 define i177 @lshr_out_of_range(i177 %Y, ptr %A2, ptr %ptr) {
1692 ; CHECK-LABEL: @lshr_out_of_range(
1693 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ne i177 [[Y:%.*]], -1
1694 ; CHECK-NEXT: [[B4:%.*]] = sext i1 [[TMP1]] to i177
1695 ; CHECK-NEXT: [[C8:%.*]] = icmp ult i177 [[B4]], [[Y]]
1696 ; CHECK-NEXT: [[TMP2:%.*]] = sext i1 [[C8]] to i64
1697 ; CHECK-NEXT: [[G18:%.*]] = getelementptr ptr, ptr [[A2:%.*]], i64 [[TMP2]]
1698 ; CHECK-NEXT: store ptr [[G18]], ptr [[PTR:%.*]], align 8
1699 ; CHECK-NEXT: ret i177 0
1701 %B5 = udiv i177 %Y, -1
1702 %B4 = add i177 %B5, -1
1703 %B2 = add i177 %B4, -1
1704 %B6 = mul i177 %B5, %B2
1705 %B3 = add i177 %B2, %B2
1706 %B10 = sub i177 %B5, %B3
1707 %B12 = lshr i177 %Y, %B6
1708 %C8 = icmp ugt i177 %B12, %B4
1709 %G18 = getelementptr ptr, ptr %A2, i1 %C8
1710 store ptr %G18, ptr %ptr
1711 %B1 = udiv i177 %B10, %B6
1716 ; https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=26716
1717 define i177 @lshr_out_of_range2(i177 %Y, ptr %A2, ptr %ptr) {
1718 ; CHECK-LABEL: @lshr_out_of_range2(
1719 ; CHECK-NEXT: [[C8:%.*]] = icmp ne i177 [[Y:%.*]], 0
1720 ; CHECK-NEXT: [[TMP1:%.*]] = sext i1 [[C8]] to i64
1721 ; CHECK-NEXT: [[G18:%.*]] = getelementptr ptr, ptr [[A2:%.*]], i64 [[TMP1]]
1722 ; CHECK-NEXT: store ptr [[G18]], ptr [[PTR:%.*]], align 8
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 ptr, ptr %A2, i1 %C8
1733 store ptr %G18, ptr %ptr, 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(ptr %A) {
1741 ; CHECK-LABEL: @ashr_out_of_range(
1742 ; CHECK-NEXT: [[L:%.*]] = load i177, ptr [[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, ptr [[A]], i64 [[TMP2]]
1746 ; CHECK-NEXT: [[L7:%.*]] = load i177, ptr [[G11]], align 4
1747 ; CHECK-NEXT: [[L7_FROZEN:%.*]] = freeze i177 [[L7]]
1748 ; CHECK-NEXT: [[C171:%.*]] = icmp slt i177 [[L7_FROZEN]], 0
1749 ; CHECK-NEXT: [[C17:%.*]] = select i1 [[TMP1]], i1 [[C171]], i1 false
1750 ; CHECK-NEXT: [[TMP3:%.*]] = sext i1 [[C17]] to i64
1751 ; CHECK-NEXT: [[G62:%.*]] = getelementptr i177, ptr [[G11]], i64 [[TMP3]]
1752 ; CHECK-NEXT: [[TMP4:%.*]] = icmp eq i177 [[L7_FROZEN]], -1
1753 ; CHECK-NEXT: [[B28:%.*]] = select i1 [[TMP4]], i177 0, i177 [[L7_FROZEN]]
1754 ; CHECK-NEXT: store i177 [[B28]], ptr [[G62]], align 4
1755 ; CHECK-NEXT: ret void
1757 %L = load i177, ptr %A
1758 %B5 = udiv i177 %L, -1
1759 %B4 = add i177 %B5, -1
1760 %B2 = add i177 %B4, -1
1761 %G11 = getelementptr i177, ptr %A, i177 %B2
1762 %L7 = load i177, ptr %G11
1763 %B6 = mul i177 %B5, %B2
1764 %B24 = ashr i177 %L7, %B6
1765 %B36 = and i177 %L7, %B4
1766 %C17 = icmp sgt i177 %B36, %B24
1767 %G62 = getelementptr i177, ptr %G11, i1 %C17
1768 %B28 = urem i177 %B24, %B6
1769 store i177 %B28, ptr %G62
1774 ; https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=26135
1775 define void @ashr_out_of_range_1(ptr %A) {
1776 ; CHECK-LABEL: @ashr_out_of_range_1(
1777 ; CHECK-NEXT: [[L:%.*]] = load i177, ptr [[A:%.*]], align 4
1778 ; CHECK-NEXT: [[L_FROZEN:%.*]] = freeze i177 [[L]]
1779 ; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i177 [[L_FROZEN]], -1
1780 ; CHECK-NEXT: [[TMP2:%.*]] = trunc i177 [[L_FROZEN]] to i64
1781 ; CHECK-NEXT: [[TMP3:%.*]] = select i1 [[TMP1]], i64 0, i64 [[TMP2]]
1782 ; CHECK-NEXT: [[TMP4:%.*]] = getelementptr i177, ptr [[A]], i64 [[TMP3]]
1783 ; CHECK-NEXT: [[G11:%.*]] = getelementptr i8, ptr [[TMP4]], i64 -24
1784 ; CHECK-NEXT: [[TMP5:%.*]] = sext i1 [[TMP1]] to i64
1785 ; CHECK-NEXT: [[G62:%.*]] = getelementptr i177, ptr [[G11]], i64 [[TMP5]]
1786 ; CHECK-NEXT: [[TMP6:%.*]] = icmp eq i177 [[L_FROZEN]], -1
1787 ; CHECK-NEXT: [[B28:%.*]] = select i1 [[TMP6]], i177 0, i177 [[L_FROZEN]]
1788 ; CHECK-NEXT: store i177 [[B28]], ptr [[G62]], align 4
1789 ; CHECK-NEXT: ret void
1791 %L = load i177, ptr %A, align 4
1792 %B5 = udiv i177 %L, -1
1793 %B4 = add i177 %B5, -1
1794 %B = and i177 %B4, %L
1795 %B2 = add i177 %B, -1
1796 %G11 = getelementptr i177, ptr %A, i177 %B2
1797 %B6 = mul i177 %B5, %B2
1798 %B24 = ashr i177 %L, %B6
1799 %C17 = icmp sgt i177 %B, %B24
1800 %G62 = getelementptr i177, ptr %G11, i1 %C17
1801 %B28 = urem i177 %B24, %B6
1802 store i177 %B28, ptr %G62, align 4
1807 ; https://bugs.chromium.org/p/oss-fuzz/issues/detail?id=38078
1808 define void @ossfuzz_38078(i32 %arg, i32 %arg1, ptr %ptr, ptr %ptr2, ptr %ptr3, ptr %ptr4, ptr %ptr5, ptr %ptr6, ptr %ptr7) {
1809 ; CHECK-LABEL: @ossfuzz_38078(
1811 ; CHECK-NEXT: [[G1:%.*]] = getelementptr i8, ptr [[PTR:%.*]], i64 -4
1812 ; CHECK-NEXT: [[I2:%.*]] = sub i32 0, [[ARG1:%.*]]
1813 ; CHECK-NEXT: [[I5:%.*]] = icmp eq i32 [[I2]], [[ARG:%.*]]
1814 ; CHECK-NEXT: call void @llvm.assume(i1 [[I5]])
1815 ; CHECK-NEXT: store volatile i32 2147483647, ptr [[G1]], align 4
1816 ; CHECK-NEXT: br label [[BB:%.*]]
1818 ; CHECK-NEXT: unreachable
1822 %B24 = urem i32 %i, -2147483648
1823 %B21 = or i32 %i, %i
1824 %i2 = add nsw i32 %arg, %arg1
1825 %B7 = or i32 %i, %i2
1826 %B8 = and i32 %i, %i2
1827 %B12 = sdiv i32 %i2, %B7
1828 %B3 = add i32 %i2, %B24
1829 %B5 = and i32 %i, %B3
1830 %B18 = and i32 %i, %B8
1831 %i3 = xor i32 %i2, %B3
1832 %C1 = icmp ne i32 %B8, %B5
1833 %i4 = lshr i32 %B5, %i3
1834 %B29 = shl nuw i32 %B8, %i3
1835 %B2 = lshr i32 %B12, %i2
1836 %B16 = add i32 %B2, %i3
1837 %B = sdiv i32 %B29, %B5
1838 %B15 = sub i32 %i2, %B5
1839 %B22 = or i32 %B21, %B29
1840 %B23 = mul i32 %B15, %B
1841 %C2 = icmp sge i1 %C1, false
1842 %C7 = icmp sle i32 %i3, %B16
1843 %B20 = xor i32 %B21, %B22
1844 %G1 = getelementptr i32, ptr %ptr, i32 %B22
1846 %B26 = ashr i32 %B29, 0
1847 %B4 = add i32 0, %B5
1848 %B27 = srem i32 %B12, %B21
1849 %i5 = icmp eq i32 %B20, %B18
1850 %C11 = icmp ugt i32 %i4, %B4
1851 call void @llvm.assume(i1 %i5)
1852 store volatile i32 %B4, ptr %G1, align 4
1853 %B11 = or i32 0, %B23
1857 store i1 %C7, ptr %ptr2, align 1
1858 store i32 %B11, ptr %ptr3, align 4
1859 store i1 %C11, ptr %ptr4, align 1
1860 store i32 %B1, ptr %ptr5, align 4
1861 store i32 %B27, ptr %ptr6, align 4
1862 %C = icmp ne i32 %B26, 0
1863 %B17 = or i1 %C, %C2
1864 store i1 %B17, ptr %ptr7, align 1
1867 declare void @llvm.assume(i1 noundef)
1869 define i8 @lshr_mask_demand(i8 %x) {
1870 ; CHECK-LABEL: @lshr_mask_demand(
1871 ; CHECK-NEXT: [[S:%.*]] = lshr i8 63, [[X:%.*]]
1872 ; CHECK-NEXT: [[R:%.*]] = and i8 [[S]], 32
1873 ; CHECK-NEXT: ret i8 [[R]]
1875 %s = lshr i8 63, %x ; 0b00111111
1876 %r = and i8 %s, 224 ; 0b11100000
1880 define i8 @shl_mask_demand(i8 %x) {
1881 ; CHECK-LABEL: @shl_mask_demand(
1882 ; CHECK-NEXT: [[S:%.*]] = shl i8 12, [[X:%.*]]
1883 ; CHECK-NEXT: [[R:%.*]] = and i8 [[S]], 4
1884 ; CHECK-NEXT: ret i8 [[R]]
1886 %s = shl i8 12, %x ; 0b00001100
1887 %r = and i8 %s, 7 ; 0b00000111
1891 define i64 @lshr_mul_negpow2(i64 %x) {
1892 ; CHECK-LABEL: @lshr_mul_negpow2(
1893 ; CHECK-NEXT: [[TMP1:%.*]] = sub i64 0, [[X:%.*]]
1894 ; CHECK-NEXT: [[A:%.*]] = and i64 [[TMP1]], 4294967295
1895 ; CHECK-NEXT: ret i64 [[A]]
1897 %a = mul i64 %x, -4294967296
1898 %b = lshr i64 %a, 32
1902 define i64 @lshr_mul_negpow2_2(i64 %x) {
1903 ; CHECK-LABEL: @lshr_mul_negpow2_2(
1904 ; CHECK-NEXT: [[TMP1:%.*]] = sub i64 0, [[X:%.*]]
1905 ; CHECK-NEXT: [[A:%.*]] = and i64 [[TMP1]], 281474976710655
1906 ; CHECK-NEXT: ret i64 [[A]]
1908 %a = mul i64 %x, -65536
1909 %b = lshr i64 %a, 16
1913 define <2 x i32> @lshr_mul_negpow2_3(<2 x i32> %x) {
1914 ; CHECK-LABEL: @lshr_mul_negpow2_3(
1915 ; CHECK-NEXT: [[TMP1:%.*]] = sub <2 x i32> zeroinitializer, [[X:%.*]]
1916 ; CHECK-NEXT: [[A:%.*]] = and <2 x i32> [[TMP1]], <i32 255, i32 255>
1917 ; CHECK-NEXT: ret <2 x i32> [[A]]
1919 %a = mul <2 x i32> %x, <i32 -16777216, i32 -16777216>
1920 %b = lshr <2 x i32> %a, <i32 24, i32 24>
1924 define i32 @lshr_mul_negpow2_4(i32 %x) {
1925 ; CHECK-LABEL: @lshr_mul_negpow2_4(
1926 ; CHECK-NEXT: [[TMP1:%.*]] = sub i32 0, [[X:%.*]]
1927 ; CHECK-NEXT: [[A:%.*]] = and i32 [[TMP1]], 65535
1928 ; CHECK-NEXT: [[B:%.*]] = xor i32 [[A]], 1
1929 ; CHECK-NEXT: ret i32 [[B]]
1931 %a = mul i32 %x, -65536
1932 %b = xor i32 %a, 65536
1933 %c = lshr i32 %b, 16
1937 define <2 x i32> @lshr_mul_negpow2_5(<2 x i32> %x) {
1938 ; CHECK-LABEL: @lshr_mul_negpow2_5(
1939 ; CHECK-NEXT: [[TMP1:%.*]] = sub <2 x i32> zeroinitializer, [[X:%.*]]
1940 ; CHECK-NEXT: [[A:%.*]] = and <2 x i32> [[TMP1]], <i32 65527, i32 65527>
1941 ; CHECK-NEXT: [[B:%.*]] = or disjoint <2 x i32> [[A]], <i32 8, i32 8>
1942 ; CHECK-NEXT: ret <2 x i32> [[B]]
1944 %a = mul <2 x i32> %x, <i32 -65536, i32 -65536>
1945 %b = or <2 x i32> %a, <i32 524288, i32 524288>
1946 %c = lshr <2 x i32> %b, <i32 16, i32 16>
1950 define i64 @lshr_mul_negpow2_extra_use(i64 %x) {
1951 ; CHECK-LABEL: @lshr_mul_negpow2_extra_use(
1952 ; CHECK-NEXT: [[A:%.*]] = mul i64 [[X:%.*]], -4294967296
1953 ; CHECK-NEXT: [[B:%.*]] = lshr exact i64 [[A]], 32
1954 ; CHECK-NEXT: call void @use(i64 [[A]])
1955 ; CHECK-NEXT: ret i64 [[B]]
1957 %a = mul i64 %x, -4294967296
1958 %b = lshr i64 %a, 32
1959 call void @use(i64 %a)
1963 define i8 @ashr_sdiv_pos(i8 %x) {
1964 ; CHECK-LABEL: @ashr_sdiv_pos(
1965 ; CHECK-NEXT: [[TMP1:%.*]] = icmp slt i8 [[X:%.*]], -41
1966 ; CHECK-NEXT: [[R:%.*]] = sext i1 [[TMP1]] to i8
1967 ; CHECK-NEXT: ret i8 [[R]]
1974 define <2 x i8> @ashr_sdiv_neg_splat_vec(<2 x i8> %x) {
1975 ; CHECK-LABEL: @ashr_sdiv_neg_splat_vec(
1976 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt <2 x i8> [[X:%.*]], <i8 41, i8 41>
1977 ; CHECK-NEXT: [[R:%.*]] = sext <2 x i1> [[TMP1]] to <2 x i8>
1978 ; CHECK-NEXT: ret <2 x i8> [[R]]
1980 %d = sdiv <2 x i8> %x, <i8 -42, i8 -42>
1981 %r = ashr <2 x i8> %d, <i8 7, i8 7>
1985 define <2 x i8> @ashr_sdiv_neg_splat_vec_poison(<2 x i8> %x) {
1986 ; CHECK-LABEL: @ashr_sdiv_neg_splat_vec_poison(
1987 ; CHECK-NEXT: [[TMP1:%.*]] = icmp eq <2 x i8> [[X:%.*]], <i8 127, i8 127>
1988 ; CHECK-NEXT: [[R:%.*]] = sext <2 x i1> [[TMP1]] to <2 x i8>
1989 ; CHECK-NEXT: ret <2 x i8> [[R]]
1991 %d = sdiv <2 x i8> %x, <i8 -127, i8 -127>
1992 %r = ashr <2 x i8> %d, <i8 7, i8 poison>
1996 define i8 @lshr_sdiv_pos(i8 %x) {
1997 ; CHECK-LABEL: @lshr_sdiv_pos(
1998 ; CHECK-NEXT: [[TMP1:%.*]] = icmp slt i8 [[X:%.*]], -11
1999 ; CHECK-NEXT: [[R:%.*]] = zext i1 [[TMP1]] to i8
2000 ; CHECK-NEXT: ret i8 [[R]]
2007 define i18 @lshr_sdiv_neg(i18 %x) {
2008 ; CHECK-LABEL: @lshr_sdiv_neg(
2009 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i18 [[X:%.*]], 11
2010 ; CHECK-NEXT: [[R:%.*]] = zext i1 [[TMP1]] to i18
2011 ; CHECK-NEXT: ret i18 [[R]]
2013 %d = sdiv i18 %x, -12
2014 %r = lshr i18 %d, 17
2020 define i8 @ashr_sdiv_not_full_shift(i8 %x) {
2021 ; CHECK-LABEL: @ashr_sdiv_not_full_shift(
2022 ; CHECK-NEXT: [[D:%.*]] = sdiv i8 [[X:%.*]], 42
2023 ; CHECK-NEXT: [[R:%.*]] = ashr i8 [[D]], 6
2024 ; CHECK-NEXT: ret i8 [[R]]
2033 define i32 @ashr_sdiv_extra_use(i32 %x) {
2034 ; CHECK-LABEL: @ashr_sdiv_extra_use(
2035 ; CHECK-NEXT: [[D:%.*]] = sdiv i32 [[X:%.*]], 42
2036 ; CHECK-NEXT: call void @use_i32(i32 [[D]])
2037 ; CHECK-NEXT: [[TMP1:%.*]] = icmp slt i32 [[X]], -41
2038 ; CHECK-NEXT: [[R:%.*]] = sext i1 [[TMP1]] to i32
2039 ; CHECK-NEXT: ret i32 [[R]]
2041 %d = sdiv i32 %x, 42
2042 call void @use_i32(i32 %d)
2043 %r = ashr i32 %d, 31
2047 define i32 @shl1_cttz(i32 %x) {
2048 ; CHECK-LABEL: @shl1_cttz(
2049 ; CHECK-NEXT: [[NEG:%.*]] = sub i32 0, [[X:%.*]]
2050 ; CHECK-NEXT: [[SHL:%.*]] = and i32 [[NEG]], [[X]]
2051 ; CHECK-NEXT: ret i32 [[SHL]]
2053 %tz = call i32 @llvm.cttz.i32(i32 %x, i1 true)
2054 %shl = shl i32 1, %tz
2058 define <2 x i8> @shl1_cttz_vec(<2 x i8> %x) {
2059 ; CHECK-LABEL: @shl1_cttz_vec(
2060 ; CHECK-NEXT: [[NEG:%.*]] = sub <2 x i8> zeroinitializer, [[X:%.*]]
2061 ; CHECK-NEXT: [[SHL:%.*]] = and <2 x i8> [[NEG]], [[X]]
2062 ; CHECK-NEXT: ret <2 x i8> [[SHL]]
2064 %tz = call <2 x i8> @llvm.cttz.v2i8(<2 x i8> %x, i1 false)
2065 %shl = shl <2 x i8> <i8 1, i8 1>, %tz
2069 define <2 x i8> @shl1_cttz_vec_poison(<2 x i8> %x) {
2070 ; CHECK-LABEL: @shl1_cttz_vec_poison(
2071 ; CHECK-NEXT: [[NEG:%.*]] = sub <2 x i8> zeroinitializer, [[X:%.*]]
2072 ; CHECK-NEXT: [[SHL:%.*]] = and <2 x i8> [[NEG]], [[X]]
2073 ; CHECK-NEXT: ret <2 x i8> [[SHL]]
2075 %tz = call <2 x i8> @llvm.cttz.v2i8(<2 x i8> %x, i1 false)
2076 %shl = shl <2 x i8> <i8 1, i8 poison>, %tz
2080 ; negative test - extra use
2082 define i32 @shl1_cttz_extra_use(i32 %x) {
2083 ; CHECK-LABEL: @shl1_cttz_extra_use(
2084 ; CHECK-NEXT: [[TZ:%.*]] = call range(i32 0, 33) i32 @llvm.cttz.i32(i32 [[X:%.*]], i1 false)
2085 ; CHECK-NEXT: call void @use_i32(i32 [[TZ]])
2086 ; CHECK-NEXT: [[SHL:%.*]] = shl nuw i32 1, [[TZ]]
2087 ; CHECK-NEXT: ret i32 [[SHL]]
2089 %tz = call i32 @llvm.cttz.i32(i32 %x, i1 false)
2090 call void @use_i32(i32 %tz)
2091 %shl = shl i32 1, %tz
2095 ; negative test - must be shift-left of 1
2097 define i32 @shl2_cttz(i32 %x) {
2098 ; CHECK-LABEL: @shl2_cttz(
2099 ; CHECK-NEXT: [[TZ:%.*]] = call range(i32 0, 33) i32 @llvm.cttz.i32(i32 [[X:%.*]], i1 true)
2100 ; CHECK-NEXT: [[SHL:%.*]] = shl i32 2, [[TZ]]
2101 ; CHECK-NEXT: ret i32 [[SHL]]
2103 %tz = call i32 @llvm.cttz.i32(i32 %x, i1 true)
2104 %shl = shl i32 2, %tz
2108 ; shift (X, amt | bitwidth - 1) -> shift (X, bitwidth - 1)
2109 define i6 @shl_or7_eq_shl7(i6 %x, i6 %c) {
2110 ; CHECK-LABEL: @shl_or7_eq_shl7(
2111 ; CHECK-NEXT: [[Y:%.*]] = shl nsw i6 [[X:%.*]], 5
2112 ; CHECK-NEXT: ret i6 [[Y]]
2115 ;; nsw not needed for transform, just check that we propagate.
2116 %y = shl nsw i6 %x, %amt
2120 define <2 x i8> @lshr_vec_or7_eq_shl7(<2 x i8> %x, <2 x i8> %c) {
2121 ; CHECK-LABEL: @lshr_vec_or7_eq_shl7(
2122 ; CHECK-NEXT: [[Y:%.*]] = lshr exact <2 x i8> [[X:%.*]], <i8 7, i8 7>
2123 ; CHECK-NEXT: ret <2 x i8> [[Y]]
2125 %amt = or <2 x i8> %c, <i8 7, i8 7>
2126 ;; exact not needed for transform, just check that we propagate.
2127 %y = lshr exact <2 x i8> %x, %amt
2131 define <2 x i8> @ashr_vec_or7_eq_ashr7(<2 x i8> %x, <2 x i8> %c) {
2132 ; CHECK-LABEL: @ashr_vec_or7_eq_ashr7(
2133 ; CHECK-NEXT: [[Y:%.*]] = ashr <2 x i8> [[X:%.*]], <i8 7, i8 7>
2134 ; CHECK-NEXT: ret <2 x i8> [[Y]]
2136 %amt = or <2 x i8> %c, <i8 7, i8 7>
2137 %y = ashr <2 x i8> %x, %amt
2141 ; Negative test not bitwidth - 1
2142 define <2 x i8> @ashr_vec_or6_fail(<2 x i8> %x, <2 x i8> %c) {
2143 ; CHECK-LABEL: @ashr_vec_or6_fail(
2144 ; CHECK-NEXT: [[AMT:%.*]] = or <2 x i8> [[C:%.*]], <i8 6, i8 6>
2145 ; CHECK-NEXT: [[Y:%.*]] = ashr <2 x i8> [[X:%.*]], [[AMT]]
2146 ; CHECK-NEXT: ret <2 x i8> [[Y]]
2148 %amt = or <2 x i8> %c, <i8 6, i8 6>
2149 %y = ashr <2 x i8> %x, %amt
2153 define i16 @lshr_and_not_demanded(i8 %x) {
2154 ; CHECK-LABEL: @lshr_and_not_demanded(
2155 ; CHECK-NEXT: [[Y_EXT:%.*]] = sext i8 [[X:%.*]] to i16
2156 ; CHECK-NEXT: [[SHR:%.*]] = lshr i16 [[Y_EXT]], 1
2157 ; CHECK-NEXT: ret i16 [[SHR]]
2160 %y.ext = sext i8 %y to i16
2161 %shr = lshr i16 %y.ext, 1
2165 define i16 @lshr_exact_and_not_demanded(i8 %x) {
2166 ; CHECK-LABEL: @lshr_exact_and_not_demanded(
2167 ; CHECK-NEXT: [[Y_EXT:%.*]] = sext i8 [[X:%.*]] to i16
2168 ; CHECK-NEXT: [[SHR:%.*]] = lshr i16 [[Y_EXT]], 1
2169 ; CHECK-NEXT: ret i16 [[SHR]]
2172 %y.ext = sext i8 %y to i16
2173 %shr = lshr exact i16 %y.ext, 1
2177 define i16 @lshr_and_demanded(i8 %x) {
2178 ; CHECK-LABEL: @lshr_and_demanded(
2179 ; CHECK-NEXT: [[Y:%.*]] = and i8 [[X:%.*]], -4
2180 ; CHECK-NEXT: [[Y_EXT:%.*]] = sext i8 [[Y]] to i16
2181 ; CHECK-NEXT: [[SHR:%.*]] = lshr exact i16 [[Y_EXT]], 1
2182 ; CHECK-NEXT: ret i16 [[SHR]]
2185 %y.ext = sext i8 %y to i16
2186 %shr = lshr i16 %y.ext, 1
2190 define i16 @ashr_umax_not_demanded(i16 %x) {
2191 ; CHECK-LABEL: @ashr_umax_not_demanded(
2192 ; CHECK-NEXT: [[SHR:%.*]] = ashr i16 [[X:%.*]], 1
2193 ; CHECK-NEXT: ret i16 [[SHR]]
2195 %y = call i16 @llvm.umax.i16(i16 %x, i16 1)
2196 %shr = ashr i16 %y, 1
2200 define i16 @ashr_exact_umax_not_demanded(i16 %x) {
2201 ; CHECK-LABEL: @ashr_exact_umax_not_demanded(
2202 ; CHECK-NEXT: [[SHR:%.*]] = ashr i16 [[X:%.*]], 1
2203 ; CHECK-NEXT: ret i16 [[SHR]]
2205 %y = call i16 @llvm.umax.i16(i16 %x, i16 1)
2206 %shr = ashr exact i16 %y, 1
2210 define i16 @ashr_umax_demanded(i16 %x) {
2211 ; CHECK-LABEL: @ashr_umax_demanded(
2212 ; CHECK-NEXT: [[Y:%.*]] = call i16 @llvm.umax.i16(i16 [[X:%.*]], i16 2)
2213 ; CHECK-NEXT: [[SHR:%.*]] = ashr i16 [[Y]], 1
2214 ; CHECK-NEXT: ret i16 [[SHR]]
2216 %y = call i16 @llvm.umax.i16(i16 %x, i16 2)
2217 %shr = ashr i16 %y, 1
2221 define i128 @shift_zext_nneg(i8 %arg) {
2222 ; CHECK-LABEL: @shift_zext_nneg(
2223 ; CHECK-NEXT: [[EXT:%.*]] = zext nneg i8 [[ARG:%.*]] to i128
2224 ; CHECK-NEXT: [[SHL:%.*]] = shl nuw i128 1, [[EXT]]
2225 ; CHECK-NEXT: ret i128 [[SHL]]
2227 %ext = zext i8 %arg to i128
2228 %shl = shl i128 1, %ext
2232 define i129 @shift_zext_not_nneg(i8 %arg) {
2233 ; CHECK-LABEL: @shift_zext_not_nneg(
2234 ; CHECK-NEXT: [[EXT:%.*]] = zext i8 [[ARG:%.*]] to i129
2235 ; CHECK-NEXT: [[SHL:%.*]] = shl nuw i129 1, [[EXT]]
2236 ; CHECK-NEXT: ret i129 [[SHL]]
2238 %ext = zext i8 %arg to i129
2239 %shl = shl i129 1, %ext
2243 define i8 @src_shl_nsw(i8 %x) {
2244 ; CHECK-LABEL: @src_shl_nsw(
2245 ; CHECK-NEXT: [[R:%.*]] = shl nsw i8 32, [[X:%.*]]
2246 ; CHECK-NEXT: ret i8 [[R]]
2248 %sh = shl nsw i8 1, %x
2249 %r = shl nsw i8 %sh, 5
2253 define i8 @src_shl_nsw_fail(i8 %x) {
2254 ; CHECK-LABEL: @src_shl_nsw_fail(
2255 ; CHECK-NEXT: [[R:%.*]] = shl i8 32, [[X:%.*]]
2256 ; CHECK-NEXT: ret i8 [[R]]
2258 %sh = shl nsw i8 1, %x
2263 define i8 @src_shl_nuw(i8 %x) {
2264 ; CHECK-LABEL: @src_shl_nuw(
2265 ; CHECK-NEXT: [[R:%.*]] = shl nuw i8 12, [[X:%.*]]
2266 ; CHECK-NEXT: ret i8 [[R]]
2268 %sh = shl nuw i8 3, %x
2269 %r = shl nuw i8 %sh, 2
2273 define i8 @src_shl_nuw_fail(i8 %x) {
2274 ; CHECK-LABEL: @src_shl_nuw_fail(
2275 ; CHECK-NEXT: [[R:%.*]] = shl i8 12, [[X:%.*]]
2276 ; CHECK-NEXT: ret i8 [[R]]
2279 %r = shl nuw i8 %sh, 2
2283 define i8 @src_lshr_exact(i8 %x) {
2284 ; CHECK-LABEL: @src_lshr_exact(
2285 ; CHECK-NEXT: [[R:%.*]] = lshr exact i8 48, [[X:%.*]]
2286 ; CHECK-NEXT: ret i8 [[R]]
2288 %sh = lshr exact i8 96, %x
2289 %r = lshr exact i8 %sh, 1
2293 define i8 @src_lshr_exact_fail(i8 %x) {
2294 ; CHECK-LABEL: @src_lshr_exact_fail(
2295 ; CHECK-NEXT: [[R:%.*]] = lshr i8 48, [[X:%.*]]
2296 ; CHECK-NEXT: ret i8 [[R]]
2298 %sh = lshr exact i8 96, %x
2303 define i8 @src_ashr_exact(i8 %x) {
2304 ; CHECK-LABEL: @src_ashr_exact(
2305 ; CHECK-NEXT: [[R:%.*]] = ashr exact i8 -8, [[X:%.*]]
2306 ; CHECK-NEXT: ret i8 [[R]]
2308 %sh = ashr exact i8 -32, %x
2309 %r = ashr exact i8 %sh, 2
2313 define i8 @src_ashr_exact_fail(i8 %x) {
2314 ; CHECK-LABEL: @src_ashr_exact_fail(
2315 ; CHECK-NEXT: [[R:%.*]] = ashr i8 -8, [[X:%.*]]
2316 ; CHECK-NEXT: ret i8 [[R]]
2318 %sh = ashr i8 -32, %x
2319 %r = ashr exact i8 %sh, 2
2323 declare i16 @llvm.umax.i16(i16, i16)