1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
5 declare void @use32(i32)
7 ; There should be no 'and' instructions left in any test.
9 define i32 @test1(i32 %A) {
10 ; CHECK-LABEL: @test1(
11 ; CHECK-NEXT: ret i32 0
17 define i32 @test2(i32 %A) {
18 ; CHECK-LABEL: @test2(
19 ; CHECK-NEXT: ret i32 [[A:%.*]]
25 define i1 @test3(i1 %A) {
26 ; CHECK-LABEL: @test3(
27 ; CHECK-NEXT: ret i1 false
33 define i1 @test3_logical(i1 %A) {
34 ; CHECK-LABEL: @test3_logical(
35 ; CHECK-NEXT: ret i1 false
37 %B = select i1 %A, i1 false, i1 false
41 define i1 @test4(i1 %A) {
42 ; CHECK-LABEL: @test4(
43 ; CHECK-NEXT: ret i1 [[A:%.*]]
49 define i1 @test4_logical(i1 %A) {
50 ; CHECK-LABEL: @test4_logical(
51 ; CHECK-NEXT: ret i1 [[A:%.*]]
53 %B = select i1 %A, i1 true, i1 false
57 define i32 @test5(i32 %A) {
58 ; CHECK-LABEL: @test5(
59 ; CHECK-NEXT: ret i32 [[A:%.*]]
65 define i1 @test6(i1 %A) {
66 ; CHECK-LABEL: @test6(
67 ; CHECK-NEXT: ret i1 [[A:%.*]]
73 define i1 @test6_logical(i1 %A) {
74 ; CHECK-LABEL: @test6_logical(
75 ; CHECK-NEXT: ret i1 [[A:%.*]]
77 %B = select i1 %A, i1 %A, i1 false
82 define i32 @test7(i32 %A) {
83 ; CHECK-LABEL: @test7(
84 ; CHECK-NEXT: ret i32 0
86 %NotA = xor i32 %A, -1
87 %B = and i32 %A, %NotA
92 define i8 @test8(i8 %A) {
93 ; CHECK-LABEL: @test8(
94 ; CHECK-NEXT: ret i8 0
101 ; Test of sign bit, convert to setle %A, 0
102 define i1 @test9(i32 %A) {
103 ; CHECK-LABEL: @test9(
104 ; CHECK-NEXT: [[C:%.*]] = icmp slt i32 [[A:%.*]], 0
105 ; CHECK-NEXT: ret i1 [[C]]
107 %B = and i32 %A, -2147483648
108 %C = icmp ne i32 %B, 0
112 ; Test of sign bit, convert to setle %A, 0
113 define i1 @test9a(i32 %A) {
114 ; CHECK-LABEL: @test9a(
115 ; CHECK-NEXT: [[C:%.*]] = icmp slt i32 [[A:%.*]], 0
116 ; CHECK-NEXT: ret i1 [[C]]
118 %B = and i32 %A, -2147483648
119 %C = icmp ne i32 %B, 0
123 define i32 @test10(i32 %A) {
124 ; CHECK-LABEL: @test10(
125 ; CHECK-NEXT: ret i32 1
129 ; (X ^ C1) & C2 --> (X & C2) ^ (C1&C2)
134 define i32 @test11(i32 %A, i32* %P) {
135 ; CHECK-LABEL: @test11(
136 ; CHECK-NEXT: [[B:%.*]] = or i32 [[A:%.*]], 3
137 ; CHECK-NEXT: [[C:%.*]] = xor i32 [[B]], 12
138 ; CHECK-NEXT: store i32 [[C]], i32* [[P:%.*]], align 4
139 ; CHECK-NEXT: ret i32 3
143 ; additional use of C
144 store i32 %C, i32* %P
145 ; %C = and uint %B, 3 --> 3
150 define i1 @test12(i32 %A, i32 %B) {
151 ; CHECK-LABEL: @test12(
152 ; CHECK-NEXT: [[C1:%.*]] = icmp ult i32 [[A:%.*]], [[B:%.*]]
153 ; CHECK-NEXT: ret i1 [[C1]]
155 %C1 = icmp ult i32 %A, %B
156 %C2 = icmp ule i32 %A, %B
157 ; (A < B) & (A <= B) === (A < B)
162 define i1 @test12_logical(i32 %A, i32 %B) {
163 ; CHECK-LABEL: @test12_logical(
164 ; CHECK-NEXT: [[C1:%.*]] = icmp ult i32 [[A:%.*]], [[B:%.*]]
165 ; CHECK-NEXT: ret i1 [[C1]]
167 %C1 = icmp ult i32 %A, %B
168 %C2 = icmp ule i32 %A, %B
169 ; (A < B) & (A <= B) === (A < B)
170 %D = select i1 %C1, i1 %C2, i1 false
174 define i1 @test13(i32 %A, i32 %B) {
175 ; CHECK-LABEL: @test13(
176 ; CHECK-NEXT: ret i1 false
178 %C1 = icmp ult i32 %A, %B
179 %C2 = icmp ugt i32 %A, %B
180 ; (A < B) & (A > B) === false
185 define i1 @test13_logical(i32 %A, i32 %B) {
186 ; CHECK-LABEL: @test13_logical(
187 ; CHECK-NEXT: ret i1 false
189 %C1 = icmp ult i32 %A, %B
190 %C2 = icmp ugt i32 %A, %B
191 ; (A < B) & (A > B) === false
192 %D = select i1 %C1, i1 %C2, i1 false
196 define i1 @test14(i8 %A) {
197 ; CHECK-LABEL: @test14(
198 ; CHECK-NEXT: [[C:%.*]] = icmp slt i8 [[A:%.*]], 0
199 ; CHECK-NEXT: ret i1 [[C]]
202 %C = icmp ne i8 %B, 0
206 define i8 @test15(i8 %A) {
207 ; CHECK-LABEL: @test15(
208 ; CHECK-NEXT: ret i8 0
216 define i8 @test16(i8 %A) {
217 ; CHECK-LABEL: @test16(
218 ; CHECK-NEXT: ret i8 0
225 define i1 @test18(i32 %A) {
226 ; CHECK-LABEL: @test18(
227 ; CHECK-NEXT: [[C:%.*]] = icmp ugt i32 [[A:%.*]], 127
228 ; CHECK-NEXT: ret i1 [[C]]
230 %B = and i32 %A, -128
232 %C = icmp ne i32 %B, 0
236 define <2 x i1> @test18_vec(<2 x i32> %A) {
237 ; CHECK-LABEL: @test18_vec(
238 ; CHECK-NEXT: [[C:%.*]] = icmp ugt <2 x i32> [[A:%.*]], <i32 127, i32 127>
239 ; CHECK-NEXT: ret <2 x i1> [[C]]
241 %B = and <2 x i32> %A, <i32 -128, i32 -128>
242 %C = icmp ne <2 x i32> %B, zeroinitializer
246 define i1 @test18a(i8 %A) {
247 ; CHECK-LABEL: @test18a(
248 ; CHECK-NEXT: [[C:%.*]] = icmp ult i8 [[A:%.*]], 2
249 ; CHECK-NEXT: ret i1 [[C]]
252 %C = icmp eq i8 %B, 0
256 define <2 x i1> @test18a_vec(<2 x i8> %A) {
257 ; CHECK-LABEL: @test18a_vec(
258 ; CHECK-NEXT: [[C:%.*]] = icmp ult <2 x i8> [[A:%.*]], <i8 2, i8 2>
259 ; CHECK-NEXT: ret <2 x i1> [[C]]
261 %B = and <2 x i8> %A, <i8 -2, i8 -2>
262 %C = icmp eq <2 x i8> %B, zeroinitializer
266 define i32 @test19(i32 %A) {
267 ; CHECK-LABEL: @test19(
268 ; CHECK-NEXT: [[B:%.*]] = shl i32 [[A:%.*]], 3
269 ; CHECK-NEXT: ret i32 [[B]]
272 ;; Clearing a zero bit
277 define i8 @test20(i8 %A) {
278 ; CHECK-LABEL: @test20(
279 ; CHECK-NEXT: [[C:%.*]] = lshr i8 [[A:%.*]], 7
280 ; CHECK-NEXT: ret i8 [[C]]
288 define i1 @test23(i32 %A) {
289 ; CHECK-LABEL: @test23(
290 ; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i32 [[A:%.*]], 2
291 ; CHECK-NEXT: ret i1 [[TMP1]]
293 %B = icmp sgt i32 %A, 1
294 %C = icmp sle i32 %A, 2
299 define i1 @test23_logical(i32 %A) {
300 ; CHECK-LABEL: @test23_logical(
301 ; CHECK-NEXT: [[TMP1:%.*]] = icmp eq i32 [[A:%.*]], 2
302 ; CHECK-NEXT: ret i1 [[TMP1]]
304 %B = icmp sgt i32 %A, 1
305 %C = icmp sle i32 %A, 2
306 %D = select i1 %B, i1 %C, i1 false
310 ; FIXME: Vectors should fold too.
311 define <2 x i1> @test23vec(<2 x i32> %A) {
312 ; CHECK-LABEL: @test23vec(
313 ; CHECK-NEXT: [[B:%.*]] = icmp sgt <2 x i32> [[A:%.*]], <i32 1, i32 1>
314 ; CHECK-NEXT: [[C:%.*]] = icmp slt <2 x i32> [[A]], <i32 3, i32 3>
315 ; CHECK-NEXT: [[D:%.*]] = and <2 x i1> [[B]], [[C]]
316 ; CHECK-NEXT: ret <2 x i1> [[D]]
318 %B = icmp sgt <2 x i32> %A, <i32 1, i32 1>
319 %C = icmp sle <2 x i32> %A, <i32 2, i32 2>
320 %D = and <2 x i1> %B, %C
324 define i1 @test24(i32 %A) {
325 ; CHECK-LABEL: @test24(
326 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i32 [[A:%.*]], 2
327 ; CHECK-NEXT: ret i1 [[TMP1]]
329 %B = icmp sgt i32 %A, 1
330 %C = icmp ne i32 %A, 2
336 define i1 @test24_logical(i32 %A) {
337 ; CHECK-LABEL: @test24_logical(
338 ; CHECK-NEXT: [[TMP1:%.*]] = icmp sgt i32 [[A:%.*]], 2
339 ; CHECK-NEXT: ret i1 [[TMP1]]
341 %B = icmp sgt i32 %A, 1
342 %C = icmp ne i32 %A, 2
344 %D = select i1 %B, i1 %C, i1 false
348 define i1 @test25(i32 %A) {
349 ; CHECK-LABEL: @test25(
350 ; CHECK-NEXT: [[A_OFF:%.*]] = add i32 [[A:%.*]], -50
351 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ult i32 [[A_OFF]], 50
352 ; CHECK-NEXT: ret i1 [[TMP1]]
354 %B = icmp sge i32 %A, 50
355 %C = icmp slt i32 %A, 100
360 define i1 @test25_logical(i32 %A) {
361 ; CHECK-LABEL: @test25_logical(
362 ; CHECK-NEXT: [[A_OFF:%.*]] = add i32 [[A:%.*]], -50
363 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ult i32 [[A_OFF]], 50
364 ; CHECK-NEXT: ret i1 [[TMP1]]
366 %B = icmp sge i32 %A, 50
367 %C = icmp slt i32 %A, 100
368 %D = select i1 %B, i1 %C, i1 false
372 ; FIXME: Vectors should fold too.
373 define <2 x i1> @test25vec(<2 x i32> %A) {
374 ; CHECK-LABEL: @test25vec(
375 ; CHECK-NEXT: [[B:%.*]] = icmp sgt <2 x i32> [[A:%.*]], <i32 49, i32 49>
376 ; CHECK-NEXT: [[C:%.*]] = icmp slt <2 x i32> [[A]], <i32 100, i32 100>
377 ; CHECK-NEXT: [[D:%.*]] = and <2 x i1> [[B]], [[C]]
378 ; CHECK-NEXT: ret <2 x i1> [[D]]
380 %B = icmp sge <2 x i32> %A, <i32 50, i32 50>
381 %C = icmp slt <2 x i32> %A, <i32 100, i32 100>
382 %D = and <2 x i1> %B, %C
386 define i8 @test27(i8 %A) {
387 ; CHECK-LABEL: @test27(
388 ; CHECK-NEXT: ret i8 0
398 ;; This is just a zero-extending shr.
399 define i32 @test28(i32 %X) {
400 ; CHECK-LABEL: @test28(
401 ; CHECK-NEXT: [[TMP1:%.*]] = lshr i32 [[X:%.*]], 24
402 ; CHECK-NEXT: ret i32 [[TMP1]]
406 ;; Mask out sign bits
411 define i32 @test29(i8 %X) {
412 ; CHECK-LABEL: @test29(
413 ; CHECK-NEXT: [[Y:%.*]] = zext i8 [[X:%.*]] to i32
414 ; CHECK-NEXT: ret i32 [[Y]]
416 %Y = zext i8 %X to i32
417 ;; Zero extend makes this unneeded.
422 define i32 @test30(i1 %X) {
423 ; CHECK-LABEL: @test30(
424 ; CHECK-NEXT: [[Y:%.*]] = zext i1 [[X:%.*]] to i32
425 ; CHECK-NEXT: ret i32 [[Y]]
427 %Y = zext i1 %X to i32
432 define i32 @test31(i1 %X) {
433 ; CHECK-LABEL: @test31(
434 ; CHECK-NEXT: [[Z:%.*]] = select i1 [[X:%.*]], i32 16, i32 0
435 ; CHECK-NEXT: ret i32 [[Z]]
437 %Y = zext i1 %X to i32
443 ; Demanded bit analysis allows us to eliminate the add.
445 define <2 x i32> @and_demanded_bits_splat_vec(<2 x i32> %x) {
446 ; CHECK-LABEL: @and_demanded_bits_splat_vec(
447 ; CHECK-NEXT: [[Z:%.*]] = and <2 x i32> [[X:%.*]], <i32 7, i32 7>
448 ; CHECK-NEXT: ret <2 x i32> [[Z]]
450 %y = add <2 x i32> %x, <i32 8, i32 8>
451 %z = and <2 x i32> %y, <i32 7, i32 7>
455 ; zext (x >> 8) has all zeros in the high 24-bits: 0x000000xx
456 ; (y | 255) has all ones in the low 8-bits: 0xyyyyyyff
457 ; 'and' of those is all known bits - it's just 'z'.
459 define i32 @and_zext_demanded(i16 %x, i32 %y) {
460 ; CHECK-LABEL: @and_zext_demanded(
461 ; CHECK-NEXT: [[S:%.*]] = lshr i16 [[X:%.*]], 8
462 ; CHECK-NEXT: [[Z:%.*]] = zext i16 [[S]] to i32
463 ; CHECK-NEXT: ret i32 [[Z]]
466 %z = zext i16 %s to i32
472 define i32 @test32(i32 %In) {
473 ; CHECK-LABEL: @test32(
474 ; CHECK-NEXT: ret i32 0
482 ;; Code corresponding to one-bit bitfield ^1.
483 define i32 @test33(i32 %b) {
484 ; CHECK-LABEL: @test33(
485 ; CHECK-NEXT: [[T13:%.*]] = xor i32 [[B:%.*]], 1
486 ; CHECK-NEXT: ret i32 [[T13]]
488 %t4.mask = and i32 %b, 1
489 %t10 = xor i32 %t4.mask, 1
490 %t12 = and i32 %b, -2
491 %t13 = or i32 %t12, %t10
495 define i32 @test33b(i32 %b) {
496 ; CHECK-LABEL: @test33b(
497 ; CHECK-NEXT: [[T13:%.*]] = xor i32 [[B:%.*]], 1
498 ; CHECK-NEXT: ret i32 [[T13]]
500 %t4.mask = and i32 %b, 1
501 %t10 = xor i32 %t4.mask, 1
502 %t12 = and i32 %b, -2
503 %t13 = or i32 %t10, %t12
507 define <2 x i32> @test33vec(<2 x i32> %b) {
508 ; CHECK-LABEL: @test33vec(
509 ; CHECK-NEXT: [[T13:%.*]] = xor <2 x i32> [[B:%.*]], <i32 1, i32 1>
510 ; CHECK-NEXT: ret <2 x i32> [[T13]]
512 %t4.mask = and <2 x i32> %b, <i32 1, i32 1>
513 %t10 = xor <2 x i32> %t4.mask, <i32 1, i32 1>
514 %t12 = and <2 x i32> %b, <i32 -2, i32 -2>
515 %t13 = or <2 x i32> %t12, %t10
519 define <2 x i32> @test33vecb(<2 x i32> %b) {
520 ; CHECK-LABEL: @test33vecb(
521 ; CHECK-NEXT: [[T13:%.*]] = xor <2 x i32> [[B:%.*]], <i32 1, i32 1>
522 ; CHECK-NEXT: ret <2 x i32> [[T13]]
524 %t4.mask = and <2 x i32> %b, <i32 1, i32 1>
525 %t10 = xor <2 x i32> %t4.mask, <i32 1, i32 1>
526 %t12 = and <2 x i32> %b, <i32 -2, i32 -2>
527 %t13 = or <2 x i32> %t10, %t12
531 define i32 @test34(i32 %A, i32 %B) {
532 ; CHECK-LABEL: @test34(
533 ; CHECK-NEXT: ret i32 [[B:%.*]]
536 %t4 = and i32 %t2, %B
540 ; FIXME: This test should only need -instsimplify (ValueTracking / computeKnownBits), not -instcombine.
542 define <2 x i32> @PR24942(<2 x i32> %x) {
543 ; CHECK-LABEL: @PR24942(
544 ; CHECK-NEXT: ret <2 x i32> zeroinitializer
546 %lshr = lshr <2 x i32> %x, <i32 31, i32 31>
547 %and = and <2 x i32> %lshr, <i32 2, i32 2>
551 define i64 @test35(i32 %X) {
552 ; CHECK-LABEL: @test35(
553 ; CHECK-NEXT: [[TMP1:%.*]] = sub i32 0, [[X:%.*]]
554 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], 240
555 ; CHECK-NEXT: [[RES:%.*]] = zext i32 [[TMP2]] to i64
556 ; CHECK-NEXT: ret i64 [[RES]]
558 %zext = zext i32 %X to i64
559 %zsub = sub i64 0, %zext
560 %res = and i64 %zsub, 240
564 define <2 x i64> @test35_uniform(<2 x i32> %X) {
565 ; CHECK-LABEL: @test35_uniform(
566 ; CHECK-NEXT: [[ZEXT:%.*]] = zext <2 x i32> [[X:%.*]] to <2 x i64>
567 ; CHECK-NEXT: [[ZSUB:%.*]] = sub nsw <2 x i64> zeroinitializer, [[ZEXT]]
568 ; CHECK-NEXT: [[RES:%.*]] = and <2 x i64> [[ZSUB]], <i64 240, i64 240>
569 ; CHECK-NEXT: ret <2 x i64> [[RES]]
571 %zext = zext <2 x i32> %X to <2 x i64>
572 %zsub = sub <2 x i64> zeroinitializer, %zext
573 %res = and <2 x i64> %zsub, <i64 240, i64 240>
577 define i64 @test36(i32 %X) {
578 ; CHECK-LABEL: @test36(
579 ; CHECK-NEXT: [[TMP1:%.*]] = add i32 [[X:%.*]], 7
580 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], 240
581 ; CHECK-NEXT: [[RES:%.*]] = zext i32 [[TMP2]] to i64
582 ; CHECK-NEXT: ret i64 [[RES]]
584 %zext = zext i32 %X to i64
585 %zsub = add i64 %zext, 7
586 %res = and i64 %zsub, 240
590 define <2 x i64> @test36_undef(<2 x i32> %X) {
591 ; CHECK-LABEL: @test36_undef(
592 ; CHECK-NEXT: [[ZEXT:%.*]] = zext <2 x i32> [[X:%.*]] to <2 x i64>
593 ; CHECK-NEXT: [[ZSUB:%.*]] = add <2 x i64> [[ZEXT]], <i64 7, i64 undef>
594 ; CHECK-NEXT: [[RES:%.*]] = and <2 x i64> [[ZSUB]], <i64 240, i64 undef>
595 ; CHECK-NEXT: ret <2 x i64> [[RES]]
597 %zext = zext <2 x i32> %X to <2 x i64>
598 %zsub = add <2 x i64> %zext, <i64 7, i64 undef>
599 %res = and <2 x i64> %zsub, <i64 240, i64 undef>
603 define i64 @test37(i32 %X) {
604 ; CHECK-LABEL: @test37(
605 ; CHECK-NEXT: [[TMP1:%.*]] = mul i32 [[X:%.*]], 7
606 ; CHECK-NEXT: [[TMP2:%.*]] = and i32 [[TMP1]], 240
607 ; CHECK-NEXT: [[RES:%.*]] = zext i32 [[TMP2]] to i64
608 ; CHECK-NEXT: ret i64 [[RES]]
610 %zext = zext i32 %X to i64
611 %zsub = mul i64 %zext, 7
612 %res = and i64 %zsub, 240
616 define <2 x i64> @test37_nonuniform(<2 x i32> %X) {
617 ; CHECK-LABEL: @test37_nonuniform(
618 ; CHECK-NEXT: [[ZEXT:%.*]] = zext <2 x i32> [[X:%.*]] to <2 x i64>
619 ; CHECK-NEXT: [[ZSUB:%.*]] = mul nuw nsw <2 x i64> [[ZEXT]], <i64 7, i64 9>
620 ; CHECK-NEXT: [[RES:%.*]] = and <2 x i64> [[ZSUB]], <i64 240, i64 110>
621 ; CHECK-NEXT: ret <2 x i64> [[RES]]
623 %zext = zext <2 x i32> %X to <2 x i64>
624 %zsub = mul <2 x i64> %zext, <i64 7, i64 9>
625 %res = and <2 x i64> %zsub, <i64 240, i64 110>
629 define i64 @test38(i32 %X) {
630 ; CHECK-LABEL: @test38(
631 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], 240
632 ; CHECK-NEXT: [[RES:%.*]] = zext i32 [[TMP1]] to i64
633 ; CHECK-NEXT: ret i64 [[RES]]
635 %zext = zext i32 %X to i64
636 %zsub = xor i64 %zext, 7
637 %res = and i64 %zsub, 240
641 define i64 @test39(i32 %X) {
642 ; CHECK-LABEL: @test39(
643 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[X:%.*]], 240
644 ; CHECK-NEXT: [[RES:%.*]] = zext i32 [[TMP1]] to i64
645 ; CHECK-NEXT: ret i64 [[RES]]
647 %zext = zext i32 %X to i64
648 %zsub = or i64 %zext, 7
649 %res = and i64 %zsub, 240
653 define i32 @test40(i1 %C) {
654 ; CHECK-LABEL: @test40(
655 ; CHECK-NEXT: [[A:%.*]] = select i1 [[C:%.*]], i32 104, i32 10
656 ; CHECK-NEXT: ret i32 [[A]]
658 %A = select i1 %C, i32 1000, i32 10
663 define <2 x i32> @test40vec(i1 %C) {
664 ; CHECK-LABEL: @test40vec(
665 ; CHECK-NEXT: [[A:%.*]] = select i1 [[C:%.*]], <2 x i32> <i32 104, i32 104>, <2 x i32> <i32 10, i32 10>
666 ; CHECK-NEXT: ret <2 x i32> [[A]]
668 %A = select i1 %C, <2 x i32> <i32 1000, i32 1000>, <2 x i32> <i32 10, i32 10>
669 %V = and <2 x i32> %A, <i32 123, i32 123>
673 define <2 x i32> @test40vec2(i1 %C) {
674 ; CHECK-LABEL: @test40vec2(
675 ; CHECK-NEXT: [[V:%.*]] = select i1 [[C:%.*]], <2 x i32> <i32 104, i32 324>, <2 x i32> <i32 10, i32 12>
676 ; CHECK-NEXT: ret <2 x i32> [[V]]
678 %A = select i1 %C, <2 x i32> <i32 1000, i32 2500>, <2 x i32> <i32 10, i32 30>
679 %V = and <2 x i32> %A, <i32 123, i32 333>
683 define i32 @test41(i1 %which) {
684 ; CHECK-LABEL: @test41(
686 ; CHECK-NEXT: br i1 [[WHICH:%.*]], label [[FINAL:%.*]], label [[DELAY:%.*]]
688 ; CHECK-NEXT: br label [[FINAL]]
690 ; CHECK-NEXT: [[A:%.*]] = phi i32 [ 104, [[ENTRY:%.*]] ], [ 10, [[DELAY]] ]
691 ; CHECK-NEXT: ret i32 [[A]]
694 br i1 %which, label %final, label %delay
700 %A = phi i32 [ 1000, %entry ], [ 10, %delay ]
701 %value = and i32 %A, 123
705 define <2 x i32> @test41vec(i1 %which) {
706 ; CHECK-LABEL: @test41vec(
708 ; CHECK-NEXT: br i1 [[WHICH:%.*]], label [[FINAL:%.*]], label [[DELAY:%.*]]
710 ; CHECK-NEXT: br label [[FINAL]]
712 ; CHECK-NEXT: [[A:%.*]] = phi <2 x i32> [ <i32 104, i32 104>, [[ENTRY:%.*]] ], [ <i32 10, i32 10>, [[DELAY]] ]
713 ; CHECK-NEXT: ret <2 x i32> [[A]]
716 br i1 %which, label %final, label %delay
722 %A = phi <2 x i32> [ <i32 1000, i32 1000>, %entry ], [ <i32 10, i32 10>, %delay ]
723 %value = and <2 x i32> %A, <i32 123, i32 123>
727 define <2 x i32> @test41vec2(i1 %which) {
728 ; CHECK-LABEL: @test41vec2(
730 ; CHECK-NEXT: br i1 [[WHICH:%.*]], label [[FINAL:%.*]], label [[DELAY:%.*]]
732 ; CHECK-NEXT: br label [[FINAL]]
734 ; CHECK-NEXT: [[A:%.*]] = phi <2 x i32> [ <i32 104, i32 324>, [[ENTRY:%.*]] ], [ <i32 10, i32 12>, [[DELAY]] ]
735 ; CHECK-NEXT: ret <2 x i32> [[A]]
738 br i1 %which, label %final, label %delay
744 %A = phi <2 x i32> [ <i32 1000, i32 2500>, %entry ], [ <i32 10, i32 30>, %delay ]
745 %value = and <2 x i32> %A, <i32 123, i32 333>
749 define i32 @test42(i32 %a, i32 %c, i32 %d) {
750 ; CHECK-LABEL: @test42(
751 ; CHECK-NEXT: [[FORCE:%.*]] = mul i32 [[C:%.*]], [[D:%.*]]
752 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[FORCE]], [[A:%.*]]
753 ; CHECK-NEXT: ret i32 [[AND]]
755 %force = mul i32 %c, %d ; forces the complexity sorting
756 %or = or i32 %a, %force
757 %nota = xor i32 %a, -1
758 %xor = xor i32 %nota, %force
759 %and = and i32 %xor, %or
763 define i32 @test43(i32 %a, i32 %c, i32 %d) {
764 ; CHECK-LABEL: @test43(
765 ; CHECK-NEXT: [[FORCE:%.*]] = mul i32 [[C:%.*]], [[D:%.*]]
766 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[FORCE]], [[A:%.*]]
767 ; CHECK-NEXT: ret i32 [[AND]]
769 %force = mul i32 %c, %d ; forces the complexity sorting
770 %or = or i32 %a, %force
771 %nota = xor i32 %a, -1
772 %xor = xor i32 %nota, %force
773 %and = and i32 %or, %xor
777 ; (~y | x) & y -> x & y
778 define i32 @test44(i32 %x, i32 %y) nounwind {
779 ; CHECK-LABEL: @test44(
780 ; CHECK-NEXT: [[A:%.*]] = and i32 [[X:%.*]], [[Y:%.*]]
781 ; CHECK-NEXT: ret i32 [[A]]
789 ; (x | ~y) & y -> x & y
790 define i32 @test45(i32 %x, i32 %y) nounwind {
791 ; CHECK-LABEL: @test45(
792 ; CHECK-NEXT: [[A:%.*]] = and i32 [[X:%.*]], [[Y:%.*]]
793 ; CHECK-NEXT: ret i32 [[A]]
801 ; y & (~y | x) -> y | x
802 define i32 @test46(i32 %x, i32 %y) nounwind {
803 ; CHECK-LABEL: @test46(
804 ; CHECK-NEXT: [[A:%.*]] = and i32 [[X:%.*]], [[Y:%.*]]
805 ; CHECK-NEXT: ret i32 [[A]]
813 ; y & (x | ~y) -> y | x
814 define i32 @test47(i32 %x, i32 %y) nounwind {
815 ; CHECK-LABEL: @test47(
816 ; CHECK-NEXT: [[A:%.*]] = and i32 [[X:%.*]], [[Y:%.*]]
817 ; CHECK-NEXT: ret i32 [[A]]
825 ; In the next 4 tests, vary the types and predicates for extra coverage.
826 ; (X & (Y | ~X)) -> (X & Y), where 'not' is an inverted cmp
828 define i1 @and_orn_cmp_1(i32 %a, i32 %b, i32 %c) {
829 ; CHECK-LABEL: @and_orn_cmp_1(
830 ; CHECK-NEXT: [[X:%.*]] = icmp sgt i32 [[A:%.*]], [[B:%.*]]
831 ; CHECK-NEXT: [[Y:%.*]] = icmp ugt i32 [[C:%.*]], 42
832 ; CHECK-NEXT: [[AND:%.*]] = and i1 [[X]], [[Y]]
833 ; CHECK-NEXT: ret i1 [[AND]]
835 %x = icmp sgt i32 %a, %b
836 %x_inv = icmp sle i32 %a, %b
837 %y = icmp ugt i32 %c, 42 ; thwart complexity-based ordering
838 %or = or i1 %y, %x_inv
839 %and = and i1 %x, %or
843 define i1 @and_orn_cmp_1_logical(i32 %a, i32 %b, i32 %c) {
844 ; CHECK-LABEL: @and_orn_cmp_1_logical(
845 ; CHECK-NEXT: [[X:%.*]] = icmp sgt i32 [[A:%.*]], [[B:%.*]]
846 ; CHECK-NEXT: [[Y:%.*]] = icmp ugt i32 [[C:%.*]], 42
847 ; CHECK-NEXT: [[AND:%.*]] = select i1 [[X]], i1 [[Y]], i1 false
848 ; CHECK-NEXT: ret i1 [[AND]]
850 %x = icmp sgt i32 %a, %b
851 %x_inv = icmp sle i32 %a, %b
852 %y = icmp ugt i32 %c, 42 ; thwart complexity-based ordering
853 %or = select i1 %y, i1 true, i1 %x_inv
854 %and = select i1 %x, i1 %or, i1 false
859 ; ((Y | ~X) & X) -> (X & Y), where 'not' is an inverted cmp
861 define <2 x i1> @and_orn_cmp_2(<2 x i32> %a, <2 x i32> %b, <2 x i32> %c) {
862 ; CHECK-LABEL: @and_orn_cmp_2(
863 ; CHECK-NEXT: [[X:%.*]] = icmp sge <2 x i32> [[A:%.*]], [[B:%.*]]
864 ; CHECK-NEXT: [[Y:%.*]] = icmp ugt <2 x i32> [[C:%.*]], <i32 42, i32 47>
865 ; CHECK-NEXT: [[AND:%.*]] = and <2 x i1> [[Y]], [[X]]
866 ; CHECK-NEXT: ret <2 x i1> [[AND]]
868 %x = icmp sge <2 x i32> %a, %b
869 %x_inv = icmp slt <2 x i32> %a, %b
870 %y = icmp ugt <2 x i32> %c, <i32 42, i32 47> ; thwart complexity-based ordering
871 %or = or <2 x i1> %y, %x_inv
872 %and = and <2 x i1> %or, %x
877 ; (X & (~X | Y)) -> (X & Y), where 'not' is an inverted cmp
879 define i1 @and_orn_cmp_3(i72 %a, i72 %b, i72 %c) {
880 ; CHECK-LABEL: @and_orn_cmp_3(
881 ; CHECK-NEXT: [[X:%.*]] = icmp ugt i72 [[A:%.*]], [[B:%.*]]
882 ; CHECK-NEXT: [[Y:%.*]] = icmp ugt i72 [[C:%.*]], 42
883 ; CHECK-NEXT: [[AND:%.*]] = and i1 [[X]], [[Y]]
884 ; CHECK-NEXT: ret i1 [[AND]]
886 %x = icmp ugt i72 %a, %b
887 %x_inv = icmp ule i72 %a, %b
888 %y = icmp ugt i72 %c, 42 ; thwart complexity-based ordering
889 %or = or i1 %x_inv, %y
890 %and = and i1 %x, %or
894 define i1 @and_orn_cmp_3_logical(i72 %a, i72 %b, i72 %c) {
895 ; CHECK-LABEL: @and_orn_cmp_3_logical(
896 ; CHECK-NEXT: [[X:%.*]] = icmp ugt i72 [[A:%.*]], [[B:%.*]]
897 ; CHECK-NEXT: [[Y:%.*]] = icmp ugt i72 [[C:%.*]], 42
898 ; CHECK-NEXT: [[AND:%.*]] = select i1 [[X]], i1 [[Y]], i1 false
899 ; CHECK-NEXT: ret i1 [[AND]]
901 %x = icmp ugt i72 %a, %b
902 %x_inv = icmp ule i72 %a, %b
903 %y = icmp ugt i72 %c, 42 ; thwart complexity-based ordering
904 %or = select i1 %x_inv, i1 true, i1 %y
905 %and = select i1 %x, i1 %or, i1 false
910 ; ((~X | Y) & X) -> (X & Y), where 'not' is an inverted cmp
912 define <3 x i1> @or_andn_cmp_4(<3 x i32> %a, <3 x i32> %b, <3 x i32> %c) {
913 ; CHECK-LABEL: @or_andn_cmp_4(
914 ; CHECK-NEXT: [[X:%.*]] = icmp eq <3 x i32> [[A:%.*]], [[B:%.*]]
915 ; CHECK-NEXT: [[Y:%.*]] = icmp ugt <3 x i32> [[C:%.*]], <i32 42, i32 43, i32 -1>
916 ; CHECK-NEXT: [[AND:%.*]] = and <3 x i1> [[Y]], [[X]]
917 ; CHECK-NEXT: ret <3 x i1> [[AND]]
919 %x = icmp eq <3 x i32> %a, %b
920 %x_inv = icmp ne <3 x i32> %a, %b
921 %y = icmp ugt <3 x i32> %c, <i32 42, i32 43, i32 -1> ; thwart complexity-based ordering
922 %or = or <3 x i1> %x_inv, %y
923 %and = and <3 x i1> %or, %x
927 ; In the next 4 tests, vary the types and predicates for extra coverage.
928 ; (~X & (Y | X)) -> (~X & Y), where 'not' is an inverted cmp
930 define i1 @andn_or_cmp_1(i37 %a, i37 %b, i37 %c) {
931 ; CHECK-LABEL: @andn_or_cmp_1(
932 ; CHECK-NEXT: [[X_INV:%.*]] = icmp sle i37 [[A:%.*]], [[B:%.*]]
933 ; CHECK-NEXT: [[Y:%.*]] = icmp ugt i37 [[C:%.*]], 42
934 ; CHECK-NEXT: [[AND:%.*]] = and i1 [[X_INV]], [[Y]]
935 ; CHECK-NEXT: ret i1 [[AND]]
937 %x = icmp sgt i37 %a, %b
938 %x_inv = icmp sle i37 %a, %b
939 %y = icmp ugt i37 %c, 42 ; thwart complexity-based ordering
941 %and = and i1 %x_inv, %or
945 define i1 @andn_or_cmp_1_logical(i37 %a, i37 %b, i37 %c) {
946 ; CHECK-LABEL: @andn_or_cmp_1_logical(
947 ; CHECK-NEXT: [[X_INV:%.*]] = icmp sle i37 [[A:%.*]], [[B:%.*]]
948 ; CHECK-NEXT: [[Y:%.*]] = icmp ugt i37 [[C:%.*]], 42
949 ; CHECK-NEXT: [[AND:%.*]] = select i1 [[X_INV]], i1 [[Y]], i1 false
950 ; CHECK-NEXT: ret i1 [[AND]]
952 %x = icmp sgt i37 %a, %b
953 %x_inv = icmp sle i37 %a, %b
954 %y = icmp ugt i37 %c, 42 ; thwart complexity-based ordering
955 %or = select i1 %y, i1 true, i1 %x
956 %and = select i1 %x_inv, i1 %or, i1 false
961 ; ((Y | X) & ~X) -> (~X & Y), where 'not' is an inverted cmp
963 define i1 @andn_or_cmp_2(i16 %a, i16 %b, i16 %c) {
964 ; CHECK-LABEL: @andn_or_cmp_2(
965 ; CHECK-NEXT: [[X_INV:%.*]] = icmp slt i16 [[A:%.*]], [[B:%.*]]
966 ; CHECK-NEXT: [[Y:%.*]] = icmp ugt i16 [[C:%.*]], 42
967 ; CHECK-NEXT: [[AND:%.*]] = and i1 [[Y]], [[X_INV]]
968 ; CHECK-NEXT: ret i1 [[AND]]
970 %x = icmp sge i16 %a, %b
971 %x_inv = icmp slt i16 %a, %b
972 %y = icmp ugt i16 %c, 42 ; thwart complexity-based ordering
974 %and = and i1 %or, %x_inv
978 define i1 @andn_or_cmp_2_logical(i16 %a, i16 %b, i16 %c) {
979 ; CHECK-LABEL: @andn_or_cmp_2_logical(
980 ; CHECK-NEXT: [[X_INV:%.*]] = icmp slt i16 [[A:%.*]], [[B:%.*]]
981 ; CHECK-NEXT: [[Y:%.*]] = icmp ugt i16 [[C:%.*]], 42
982 ; CHECK-NEXT: [[AND:%.*]] = select i1 [[Y]], i1 [[X_INV]], i1 false
983 ; CHECK-NEXT: ret i1 [[AND]]
985 %x = icmp sge i16 %a, %b
986 %x_inv = icmp slt i16 %a, %b
987 %y = icmp ugt i16 %c, 42 ; thwart complexity-based ordering
988 %or = select i1 %y, i1 true, i1 %x
989 %and = select i1 %or, i1 %x_inv, i1 false
994 ; (~X & (X | Y)) -> (~X & Y), where 'not' is an inverted cmp
996 define <4 x i1> @andn_or_cmp_3(<4 x i32> %a, <4 x i32> %b, <4 x i32> %c) {
997 ; CHECK-LABEL: @andn_or_cmp_3(
998 ; CHECK-NEXT: [[X_INV:%.*]] = icmp ule <4 x i32> [[A:%.*]], [[B:%.*]]
999 ; CHECK-NEXT: [[Y:%.*]] = icmp ugt <4 x i32> [[C:%.*]], <i32 42, i32 0, i32 1, i32 -1>
1000 ; CHECK-NEXT: [[AND:%.*]] = and <4 x i1> [[X_INV]], [[Y]]
1001 ; CHECK-NEXT: ret <4 x i1> [[AND]]
1003 %x = icmp ugt <4 x i32> %a, %b
1004 %x_inv = icmp ule <4 x i32> %a, %b
1005 %y = icmp ugt <4 x i32> %c, <i32 42, i32 0, i32 1, i32 -1> ; thwart complexity-based ordering
1006 %or = or <4 x i1> %x, %y
1007 %and = and <4 x i1> %x_inv, %or
1011 ; Commute the 'and':
1012 ; ((X | Y) & ~X) -> (~X & Y), where 'not' is an inverted cmp
1014 define i1 @andn_or_cmp_4(i32 %a, i32 %b, i32 %c) {
1015 ; CHECK-LABEL: @andn_or_cmp_4(
1016 ; CHECK-NEXT: [[X_INV:%.*]] = icmp ne i32 [[A:%.*]], [[B:%.*]]
1017 ; CHECK-NEXT: [[Y:%.*]] = icmp ugt i32 [[C:%.*]], 42
1018 ; CHECK-NEXT: [[AND:%.*]] = and i1 [[Y]], [[X_INV]]
1019 ; CHECK-NEXT: ret i1 [[AND]]
1021 %x = icmp eq i32 %a, %b
1022 %x_inv = icmp ne i32 %a, %b
1023 %y = icmp ugt i32 %c, 42 ; thwart complexity-based ordering
1025 %and = and i1 %or, %x_inv
1029 define i1 @andn_or_cmp_4_logical(i32 %a, i32 %b, i32 %c) {
1030 ; CHECK-LABEL: @andn_or_cmp_4_logical(
1031 ; CHECK-NEXT: [[X_INV:%.*]] = icmp ne i32 [[A:%.*]], [[B:%.*]]
1032 ; CHECK-NEXT: [[Y:%.*]] = icmp ugt i32 [[C:%.*]], 42
1033 ; CHECK-NEXT: [[AND:%.*]] = select i1 [[X_INV]], i1 [[Y]], i1 false
1034 ; CHECK-NEXT: ret i1 [[AND]]
1036 %x = icmp eq i32 %a, %b
1037 %x_inv = icmp ne i32 %a, %b
1038 %y = icmp ugt i32 %c, 42 ; thwart complexity-based ordering
1039 %or = select i1 %x, i1 true, i1 %y
1040 %and = select i1 %or, i1 %x_inv, i1 false
1044 define i32 @lowbitmask_casted_shift(i8 %x) {
1045 ; CHECK-LABEL: @lowbitmask_casted_shift(
1046 ; CHECK-NEXT: [[TMP1:%.*]] = sext i8 [[X:%.*]] to i32
1047 ; CHECK-NEXT: [[R:%.*]] = lshr i32 [[TMP1]], 1
1048 ; CHECK-NEXT: ret i32 [[R]]
1051 %s = sext i8 %a to i32
1052 %r = and i32 %s, 2147483647
1056 ; Negative test - mask constant is too big.
1058 define i32 @lowbitmask_casted_shift_wrong_mask1(i8 %x) {
1059 ; CHECK-LABEL: @lowbitmask_casted_shift_wrong_mask1(
1060 ; CHECK-NEXT: [[A:%.*]] = ashr i8 [[X:%.*]], 2
1061 ; CHECK-NEXT: [[S:%.*]] = sext i8 [[A]] to i32
1062 ; CHECK-NEXT: [[R:%.*]] = and i32 [[S]], 2147483647
1063 ; CHECK-NEXT: ret i32 [[R]]
1066 %s = sext i8 %a to i32
1067 %r = and i32 %s, 2147483647 ; 0x7fffffff
1071 ; Negative test - mask constant is too small.
1073 define i32 @lowbitmask_casted_shift_wrong_mask2(i8 %x) {
1074 ; CHECK-LABEL: @lowbitmask_casted_shift_wrong_mask2(
1075 ; CHECK-NEXT: [[A:%.*]] = ashr i8 [[X:%.*]], 2
1076 ; CHECK-NEXT: [[S:%.*]] = sext i8 [[A]] to i32
1077 ; CHECK-NEXT: [[R:%.*]] = and i32 [[S]], 536870911
1078 ; CHECK-NEXT: ret i32 [[R]]
1081 %s = sext i8 %a to i32
1082 %r = and i32 %s, 536870911 ; 0x1fffffff
1086 ; Extra use of shift is ok.
1088 define i32 @lowbitmask_casted_shift_use1(i8 %x) {
1089 ; CHECK-LABEL: @lowbitmask_casted_shift_use1(
1090 ; CHECK-NEXT: [[A:%.*]] = ashr i8 [[X:%.*]], 3
1091 ; CHECK-NEXT: call void @use8(i8 [[A]])
1092 ; CHECK-NEXT: [[TMP1:%.*]] = sext i8 [[X]] to i32
1093 ; CHECK-NEXT: [[R:%.*]] = lshr i32 [[TMP1]], 3
1094 ; CHECK-NEXT: ret i32 [[R]]
1097 call void @use8(i8 %a)
1098 %s = sext i8 %a to i32
1099 %r = and i32 %s, 536870911
1103 ; Negative test - extra use of sext requires more instructions.
1105 define i32 @lowbitmask_casted_shift_use2(i8 %x) {
1106 ; CHECK-LABEL: @lowbitmask_casted_shift_use2(
1107 ; CHECK-NEXT: [[A:%.*]] = ashr i8 [[X:%.*]], 3
1108 ; CHECK-NEXT: [[S:%.*]] = sext i8 [[A]] to i32
1109 ; CHECK-NEXT: call void @use32(i32 [[S]])
1110 ; CHECK-NEXT: [[R:%.*]] = and i32 [[S]], 536870911
1111 ; CHECK-NEXT: ret i32 [[R]]
1114 %s = sext i8 %a to i32
1115 call void @use32(i32 %s)
1116 %r = and i32 %s, 536870911
1120 ; Vectors/weird types are ok.
1122 define <2 x i59> @lowbitmask_casted_shift_vec_splat(<2 x i47> %x) {
1123 ; CHECK-LABEL: @lowbitmask_casted_shift_vec_splat(
1124 ; CHECK-NEXT: [[TMP1:%.*]] = sext <2 x i47> [[X:%.*]] to <2 x i59>
1125 ; CHECK-NEXT: [[R:%.*]] = lshr <2 x i59> [[TMP1]], <i59 5, i59 5>
1126 ; CHECK-NEXT: ret <2 x i59> [[R]]
1128 %a = ashr <2 x i47> %x, <i47 5, i47 5>
1129 %s = sext <2 x i47> %a to <2 x i59>
1130 %r = and <2 x i59> %s, <i59 18014398509481983, i59 18014398509481983> ; -1 u>> 5 == 0x3f_ffff_ffff_ffff
1134 define i32 @lowmask_sext_in_reg(i32 %x) {
1135 ; CHECK-LABEL: @lowmask_sext_in_reg(
1136 ; CHECK-NEXT: [[L:%.*]] = shl i32 [[X:%.*]], 20
1137 ; CHECK-NEXT: [[R:%.*]] = ashr exact i32 [[L]], 20
1138 ; CHECK-NEXT: call void @use32(i32 [[R]])
1139 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[X]], 4095
1140 ; CHECK-NEXT: ret i32 [[AND]]
1143 %r = ashr i32 %l, 20
1144 call void @use32(i32 %r)
1145 %and = and i32 %r, 4095
1149 ; Negative test - mismatched shift amounts
1151 define i32 @lowmask_not_sext_in_reg(i32 %x) {
1152 ; CHECK-LABEL: @lowmask_not_sext_in_reg(
1153 ; CHECK-NEXT: [[L:%.*]] = shl i32 [[X:%.*]], 19
1154 ; CHECK-NEXT: [[R:%.*]] = ashr i32 [[L]], 20
1155 ; CHECK-NEXT: call void @use32(i32 [[R]])
1156 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[R]], 4095
1157 ; CHECK-NEXT: ret i32 [[AND]]
1160 %r = ashr i32 %l, 20
1161 call void @use32(i32 %r)
1162 %and = and i32 %r, 4095
1166 ; Negative test - too much shift for mask
1168 define i32 @not_lowmask_sext_in_reg(i32 %x) {
1169 ; CHECK-LABEL: @not_lowmask_sext_in_reg(
1170 ; CHECK-NEXT: [[L:%.*]] = shl i32 [[X:%.*]], 20
1171 ; CHECK-NEXT: [[R:%.*]] = ashr exact i32 [[L]], 20
1172 ; CHECK-NEXT: call void @use32(i32 [[R]])
1173 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[R]], 4096
1174 ; CHECK-NEXT: ret i32 [[AND]]
1177 %r = ashr i32 %l, 20
1178 call void @use32(i32 %r)
1179 %and = and i32 %r, 4096
1183 ; Negative test - too much shift for mask
1185 define i32 @not_lowmask_sext_in_reg2(i32 %x) {
1186 ; CHECK-LABEL: @not_lowmask_sext_in_reg2(
1187 ; CHECK-NEXT: [[L:%.*]] = shl i32 [[X:%.*]], 21
1188 ; CHECK-NEXT: [[R:%.*]] = ashr exact i32 [[L]], 21
1189 ; CHECK-NEXT: call void @use32(i32 [[R]])
1190 ; CHECK-NEXT: [[AND:%.*]] = and i32 [[R]], 4095
1191 ; CHECK-NEXT: ret i32 [[AND]]
1194 %r = ashr i32 %l, 21
1195 call void @use32(i32 %r)
1196 %and = and i32 %r, 4095
1200 define <2 x i32> @lowmask_sext_in_reg_splat(<2 x i32> %x, <2 x i32>* %p) {
1201 ; CHECK-LABEL: @lowmask_sext_in_reg_splat(
1202 ; CHECK-NEXT: [[L:%.*]] = shl <2 x i32> [[X:%.*]], <i32 20, i32 20>
1203 ; CHECK-NEXT: [[R:%.*]] = ashr exact <2 x i32> [[L]], <i32 20, i32 20>
1204 ; CHECK-NEXT: store <2 x i32> [[R]], <2 x i32>* [[P:%.*]], align 8
1205 ; CHECK-NEXT: [[AND:%.*]] = and <2 x i32> [[X]], <i32 4095, i32 4095>
1206 ; CHECK-NEXT: ret <2 x i32> [[AND]]
1208 %l = shl <2 x i32> %x, <i32 20, i32 20>
1209 %r = ashr <2 x i32> %l, <i32 20, i32 20>
1210 store <2 x i32> %r, <2 x i32>* %p
1211 %and = and <2 x i32> %r, <i32 4095, i32 4095>
1215 define i8 @lowmask_add(i8 %x) {
1216 ; CHECK-LABEL: @lowmask_add(
1217 ; CHECK-NEXT: [[A:%.*]] = add i8 [[X:%.*]], -64
1218 ; CHECK-NEXT: call void @use8(i8 [[A]])
1219 ; CHECK-NEXT: [[R:%.*]] = and i8 [[X]], 32
1220 ; CHECK-NEXT: ret i8 [[R]]
1222 %a = add i8 %x, -64 ; 0xc0
1223 call void @use8(i8 %a)
1224 %r = and i8 %a, 32 ; 0x20
1228 define i8 @lowmask_add_2(i8 %x) {
1229 ; CHECK-LABEL: @lowmask_add_2(
1230 ; CHECK-NEXT: [[R:%.*]] = and i8 [[X:%.*]], 63
1231 ; CHECK-NEXT: ret i8 [[R]]
1233 %a = add i8 %x, -64 ; 0xc0
1234 %r = and i8 %a, 63 ; 0x3f
1238 define i8 @lowmask_add_2_uses(i8 %x) {
1239 ; CHECK-LABEL: @lowmask_add_2_uses(
1240 ; CHECK-NEXT: [[A:%.*]] = add i8 [[X:%.*]], -64
1241 ; CHECK-NEXT: call void @use8(i8 [[A]])
1242 ; CHECK-NEXT: [[R:%.*]] = and i8 [[X]], 63
1243 ; CHECK-NEXT: ret i8 [[R]]
1245 %a = add i8 %x, -64 ; 0xc0
1246 call void @use8(i8 %a)
1247 %r = and i8 %a, 63 ; 0x3f
1251 define <2 x i8> @lowmask_add_2_splat(<2 x i8> %x, <2 x i8>* %p) {
1252 ; CHECK-LABEL: @lowmask_add_2_splat(
1253 ; CHECK-NEXT: [[A:%.*]] = add <2 x i8> [[X:%.*]], <i8 -64, i8 -64>
1254 ; CHECK-NEXT: store <2 x i8> [[A]], <2 x i8>* [[P:%.*]], align 2
1255 ; CHECK-NEXT: [[R:%.*]] = and <2 x i8> [[X]], <i8 63, i8 63>
1256 ; CHECK-NEXT: ret <2 x i8> [[R]]
1258 %a = add <2 x i8> %x, <i8 -64, i8 -64> ; 0xc0
1259 store <2 x i8> %a, <2 x i8>* %p
1260 %r = and <2 x i8> %a, <i8 63, i8 63> ; 0x3f
1264 ; Negative test - mask overlaps low bit of add
1266 define i8 @not_lowmask_add(i8 %x) {
1267 ; CHECK-LABEL: @not_lowmask_add(
1268 ; CHECK-NEXT: [[A:%.*]] = add i8 [[X:%.*]], -64
1269 ; CHECK-NEXT: call void @use8(i8 [[A]])
1270 ; CHECK-NEXT: [[R:%.*]] = and i8 [[A]], 64
1271 ; CHECK-NEXT: ret i8 [[R]]
1273 %a = add i8 %x, -64 ; 0xc0
1274 call void @use8(i8 %a)
1275 %r = and i8 %a, 64 ; 0x40
1279 ; Negative test - mask overlaps low bit of add
1281 define i8 @not_lowmask_add2(i8 %x) {
1282 ; CHECK-LABEL: @not_lowmask_add2(
1283 ; CHECK-NEXT: [[A:%.*]] = add i8 [[X:%.*]], -96
1284 ; CHECK-NEXT: call void @use8(i8 [[A]])
1285 ; CHECK-NEXT: [[R:%.*]] = and i8 [[A]], 63
1286 ; CHECK-NEXT: ret i8 [[R]]
1288 %a = add i8 %x, -96 ; 0xe0
1289 call void @use8(i8 %a)
1290 %r = and i8 %a, 63 ; 0x3f
1294 define <2 x i8> @lowmask_add_splat(<2 x i8> %x, <2 x i8>* %p) {
1295 ; CHECK-LABEL: @lowmask_add_splat(
1296 ; CHECK-NEXT: [[A:%.*]] = add <2 x i8> [[X:%.*]], <i8 -64, i8 -64>
1297 ; CHECK-NEXT: store <2 x i8> [[A]], <2 x i8>* [[P:%.*]], align 2
1298 ; CHECK-NEXT: [[R:%.*]] = and <2 x i8> [[X]], <i8 32, i8 32>
1299 ; CHECK-NEXT: ret <2 x i8> [[R]]
1301 %a = add <2 x i8> %x, <i8 -64, i8 -64> ; 0xc0
1302 store <2 x i8> %a, <2 x i8>* %p
1303 %r = and <2 x i8> %a, <i8 32, i8 32> ; 0x20
1307 define <2 x i8> @lowmask_add_splat_undef(<2 x i8> %x, <2 x i8>* %p) {
1308 ; CHECK-LABEL: @lowmask_add_splat_undef(
1309 ; CHECK-NEXT: [[A:%.*]] = add <2 x i8> [[X:%.*]], <i8 -64, i8 undef>
1310 ; CHECK-NEXT: store <2 x i8> [[A]], <2 x i8>* [[P:%.*]], align 2
1311 ; CHECK-NEXT: [[R:%.*]] = and <2 x i8> [[A]], <i8 undef, i8 32>
1312 ; CHECK-NEXT: ret <2 x i8> [[R]]
1314 %a = add <2 x i8> %x, <i8 -64, i8 undef> ; 0xc0
1315 store <2 x i8> %a, <2 x i8>* %p
1316 %r = and <2 x i8> %a, <i8 undef, i8 32> ; 0x20
1320 define <2 x i8> @lowmask_add_vec(<2 x i8> %x, <2 x i8>* %p) {
1321 ; CHECK-LABEL: @lowmask_add_vec(
1322 ; CHECK-NEXT: [[A:%.*]] = add <2 x i8> [[X:%.*]], <i8 -96, i8 -64>
1323 ; CHECK-NEXT: store <2 x i8> [[A]], <2 x i8>* [[P:%.*]], align 2
1324 ; CHECK-NEXT: [[R:%.*]] = and <2 x i8> [[A]], <i8 16, i8 32>
1325 ; CHECK-NEXT: ret <2 x i8> [[R]]
1327 %a = add <2 x i8> %x, <i8 -96, i8 -64> ; 0xe0, 0xc0
1328 store <2 x i8> %a, <2 x i8>* %p
1329 %r = and <2 x i8> %a, <i8 16, i8 32> ; 0x10, 0x20
1334 define i8 @flip_masked_bit(i8 %A) {
1335 ; CHECK-LABEL: @flip_masked_bit(
1336 ; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[A:%.*]], 16
1337 ; CHECK-NEXT: [[C:%.*]] = xor i8 [[TMP1]], 16
1338 ; CHECK-NEXT: ret i8 [[C]]
1345 define <2 x i8> @flip_masked_bit_uniform(<2 x i8> %A) {
1346 ; CHECK-LABEL: @flip_masked_bit_uniform(
1347 ; CHECK-NEXT: [[TMP1:%.*]] = and <2 x i8> [[A:%.*]], <i8 16, i8 16>
1348 ; CHECK-NEXT: [[C:%.*]] = xor <2 x i8> [[TMP1]], <i8 16, i8 16>
1349 ; CHECK-NEXT: ret <2 x i8> [[C]]
1351 %B = add <2 x i8> %A, <i8 16, i8 16>
1352 %C = and <2 x i8> %B, <i8 16, i8 16>
1356 define <2 x i8> @flip_masked_bit_undef(<2 x i8> %A) {
1357 ; CHECK-LABEL: @flip_masked_bit_undef(
1358 ; CHECK-NEXT: [[B:%.*]] = add <2 x i8> [[A:%.*]], <i8 16, i8 undef>
1359 ; CHECK-NEXT: [[C:%.*]] = and <2 x i8> [[B]], <i8 16, i8 undef>
1360 ; CHECK-NEXT: ret <2 x i8> [[C]]
1362 %B = add <2 x i8> %A, <i8 16, i8 undef>
1363 %C = and <2 x i8> %B, <i8 16, i8 undef>
1367 define <2 x i8> @flip_masked_bit_nonuniform(<2 x i8> %A) {
1368 ; CHECK-LABEL: @flip_masked_bit_nonuniform(
1369 ; CHECK-NEXT: [[B:%.*]] = add <2 x i8> [[A:%.*]], <i8 16, i8 4>
1370 ; CHECK-NEXT: [[C:%.*]] = and <2 x i8> [[B]], <i8 16, i8 4>
1371 ; CHECK-NEXT: ret <2 x i8> [[C]]
1373 %B = add <2 x i8> %A, <i8 16, i8 4>
1374 %C = and <2 x i8> %B, <i8 16, i8 4>