1 ; NOTE: Assertions have been autogenerated by utils/update_test_checks.py
2 ; RUN: opt < %s -instcombine -S | FileCheck %s
9 define i1 @test0(i1 %A) {
10 ; CHECK-LABEL: @test0(
11 ; CHECK-NEXT: ret i1 [[A:%.*]]
17 define i32 @test1(i32 %A) {
18 ; CHECK-LABEL: @test1(
19 ; CHECK-NEXT: ret i32 [[A:%.*]]
25 define i1 @test2(i1 %A) {
26 ; CHECK-LABEL: @test2(
27 ; CHECK-NEXT: ret i1 false
33 define i32 @test3(i32 %A) {
34 ; CHECK-LABEL: @test3(
35 ; CHECK-NEXT: ret i32 0
41 define i32 @test4(i32 %A) {
42 ; CHECK-LABEL: @test4(
43 ; CHECK-NEXT: ret i32 -1
45 %NotA = xor i32 -1, %A
46 %B = xor i32 %A, %NotA
50 define i32 @test5(i32 %A) {
51 ; CHECK-LABEL: @test5(
52 ; CHECK-NEXT: [[TMP1:%.*]] = and i32 [[A:%.*]], -124
53 ; CHECK-NEXT: ret i32 [[TMP1]]
60 define i8 @test6(i8 %A) {
61 ; CHECK-LABEL: @test6(
62 ; CHECK-NEXT: ret i8 [[A:%.*]]
69 define i32 @test7(i32 %A, i32 %B) {
70 ; CHECK-LABEL: @test7(
71 ; CHECK-NEXT: [[A1:%.*]] = and i32 [[A:%.*]], 7
72 ; CHECK-NEXT: [[B1:%.*]] = and i32 [[B:%.*]], 128
73 ; CHECK-NEXT: [[C11:%.*]] = or i32 [[A1]], [[B1]]
74 ; CHECK-NEXT: ret i32 [[C11]]
78 %C1 = xor i32 %A1, %B1
82 define i8 @test8(i1 %c) {
83 ; CHECK-LABEL: @test8(
84 ; CHECK-NEXT: br i1 [[C:%.*]], label [[FALSE:%.*]], label [[TRUE:%.*]]
86 ; CHECK-NEXT: ret i8 1
88 ; CHECK-NEXT: ret i8 3
91 br i1 %d, label %True, label %False
100 define i1 @test9(i8 %A) {
101 ; CHECK-LABEL: @test9(
102 ; CHECK-NEXT: [[C:%.*]] = icmp eq i8 [[A:%.*]], 89
103 ; CHECK-NEXT: ret i1 [[C]]
106 %C = icmp eq i8 %B, 34
110 define <2 x i1> @test9vec(<2 x i8> %a) {
111 ; CHECK-LABEL: @test9vec(
112 ; CHECK-NEXT: [[C:%.*]] = icmp eq <2 x i8> [[A:%.*]], <i8 89, i8 89>
113 ; CHECK-NEXT: ret <2 x i1> [[C]]
115 %b = xor <2 x i8> %a, <i8 123, i8 123>
116 %c = icmp eq <2 x i8> %b, <i8 34, i8 34>
120 define i8 @test10(i8 %A) {
121 ; CHECK-LABEL: @test10(
122 ; CHECK-NEXT: [[B:%.*]] = and i8 [[A:%.*]], 3
123 ; CHECK-NEXT: [[C1:%.*]] = or i8 [[B]], 4
124 ; CHECK-NEXT: ret i8 [[C1]]
131 define i8 @test11(i8 %A) {
132 ; CHECK-LABEL: @test11(
133 ; CHECK-NEXT: [[B:%.*]] = and i8 [[A:%.*]], -13
134 ; CHECK-NEXT: [[TMP1:%.*]] = or i8 [[B]], 8
135 ; CHECK-NEXT: ret i8 [[TMP1]]
142 define i1 @test12(i8 %A) {
143 ; CHECK-LABEL: @test12(
144 ; CHECK-NEXT: [[C:%.*]] = icmp ne i8 [[A:%.*]], 4
145 ; CHECK-NEXT: ret i1 [[C]]
148 %c = icmp ne i8 %B, 0
152 define <2 x i1> @test12vec(<2 x i8> %a) {
153 ; CHECK-LABEL: @test12vec(
154 ; CHECK-NEXT: [[C:%.*]] = icmp ne <2 x i8> [[A:%.*]], <i8 4, i8 4>
155 ; CHECK-NEXT: ret <2 x i1> [[C]]
157 %b = xor <2 x i8> %a, <i8 4, i8 4>
158 %c = icmp ne <2 x i8> %b, zeroinitializer
162 define i32 @test18(i32 %A) {
163 ; CHECK-LABEL: @test18(
164 ; CHECK-NEXT: [[C:%.*]] = add i32 [[A:%.*]], 124
165 ; CHECK-NEXT: ret i32 [[C]]
172 define i32 @test19(i32 %A, i32 %B) {
173 ; CHECK-LABEL: @test19(
174 ; CHECK-NEXT: ret i32 [[B:%.*]]
181 define void @test20(i32 %A, i32 %B) {
182 ; CHECK-LABEL: @test20(
183 ; CHECK-NEXT: store i32 [[B:%.*]], i32* @G1, align 4
184 ; CHECK-NEXT: store i32 [[A:%.*]], i32* @G2, align 4
185 ; CHECK-NEXT: ret void
188 %t5 = xor i32 %t2, %B
189 %t8 = xor i32 %t5, %t2
190 store i32 %t8, i32* @G1
191 store i32 %t5, i32* @G2
195 define i32 @test22(i1 %X) {
196 ; CHECK-LABEL: @test22(
197 ; CHECK-NEXT: [[Z:%.*]] = zext i1 [[X:%.*]] to i32
198 ; CHECK-NEXT: ret i32 [[Z]]
201 %Z = zext i1 %Y to i32
206 ; Look through a zext between xors.
208 define i32 @fold_zext_xor_sandwich(i1 %X) {
209 ; CHECK-LABEL: @fold_zext_xor_sandwich(
210 ; CHECK-NEXT: [[Z:%.*]] = zext i1 [[X:%.*]] to i32
211 ; CHECK-NEXT: [[Q:%.*]] = xor i32 [[Z]], 3
212 ; CHECK-NEXT: ret i32 [[Q]]
215 %Z = zext i1 %Y to i32
220 define <2 x i32> @fold_zext_xor_sandwich_vec(<2 x i1> %X) {
221 ; CHECK-LABEL: @fold_zext_xor_sandwich_vec(
222 ; CHECK-NEXT: [[Z:%.*]] = zext <2 x i1> [[X:%.*]] to <2 x i32>
223 ; CHECK-NEXT: [[Q:%.*]] = xor <2 x i32> [[Z]], <i32 3, i32 3>
224 ; CHECK-NEXT: ret <2 x i32> [[Q]]
226 %Y = xor <2 x i1> %X, <i1 true, i1 true>
227 %Z = zext <2 x i1> %Y to <2 x i32>
228 %Q = xor <2 x i32> %Z, <i32 2, i32 2>
232 define i1 @test23(i32 %a, i32 %b) {
233 ; CHECK-LABEL: @test23(
234 ; CHECK-NEXT: [[T4:%.*]] = icmp eq i32 [[B:%.*]], 0
235 ; CHECK-NEXT: ret i1 [[T4]]
238 %t4 = icmp eq i32 %t2, %a
242 define i1 @test24(i32 %c, i32 %d) {
243 ; CHECK-LABEL: @test24(
244 ; CHECK-NEXT: [[T4:%.*]] = icmp ne i32 [[D:%.*]], 0
245 ; CHECK-NEXT: ret i1 [[T4]]
248 %t4 = icmp ne i32 %t2, %c
252 define i32 @test25(i32 %g, i32 %h) {
253 ; CHECK-LABEL: @test25(
254 ; CHECK-NEXT: [[T4:%.*]] = and i32 [[H:%.*]], [[G:%.*]]
255 ; CHECK-NEXT: ret i32 [[T4]]
258 %t2 = and i32 %h2, %g
259 %t4 = xor i32 %t2, %g
263 define i32 @test27(i32 %b, i32 %c, i32 %d) {
264 ; CHECK-LABEL: @test27(
265 ; CHECK-NEXT: [[T6:%.*]] = icmp eq i32 [[B:%.*]], [[C:%.*]]
266 ; CHECK-NEXT: [[T7:%.*]] = zext i1 [[T6]] to i32
267 ; CHECK-NEXT: ret i32 [[T7]]
271 %t6 = icmp eq i32 %t2, %t5
272 %t7 = zext i1 %t6 to i32
276 define i32 @test28(i32 %indvar) {
277 ; CHECK-LABEL: @test28(
278 ; CHECK-NEXT: [[T214:%.*]] = add i32 [[INDVAR:%.*]], 1
279 ; CHECK-NEXT: ret i32 [[T214]]
281 %t7 = add i32 %indvar, -2147483647
282 %t214 = xor i32 %t7, -2147483648
286 define <2 x i32> @test28vec(<2 x i32> %indvar) {
287 ; CHECK-LABEL: @test28vec(
288 ; CHECK-NEXT: [[T214:%.*]] = add <2 x i32> [[INDVAR:%.*]], <i32 1, i32 1>
289 ; CHECK-NEXT: ret <2 x i32> [[T214]]
291 %t7 = add <2 x i32> %indvar, <i32 -2147483647, i32 -2147483647>
292 %t214 = xor <2 x i32> %t7, <i32 -2147483648, i32 -2147483648>
296 define i32 @test28_sub(i32 %indvar) {
297 ; CHECK-LABEL: @test28_sub(
298 ; CHECK-NEXT: [[T214:%.*]] = sub i32 1, [[INDVAR:%.*]]
299 ; CHECK-NEXT: ret i32 [[T214]]
301 %t7 = sub i32 -2147483647, %indvar
302 %t214 = xor i32 %t7, -2147483648
306 define <2 x i32> @test28_subvec(<2 x i32> %indvar) {
307 ; CHECK-LABEL: @test28_subvec(
308 ; CHECK-NEXT: [[T214:%.*]] = sub <2 x i32> <i32 1, i32 1>, [[INDVAR:%.*]]
309 ; CHECK-NEXT: ret <2 x i32> [[T214]]
311 %t7 = sub <2 x i32> <i32 -2147483647, i32 -2147483647>, %indvar
312 %t214 = xor <2 x i32> %t7, <i32 -2147483648, i32 -2147483648>
316 define i32 @test29(i1 %C) {
317 ; CHECK-LABEL: @test29(
318 ; CHECK-NEXT: [[V:%.*]] = select i1 [[C:%.*]], i32 915, i32 113
319 ; CHECK-NEXT: ret i32 [[V]]
321 %A = select i1 %C, i32 1000, i32 10
326 define <2 x i32> @test29vec(i1 %C) {
327 ; CHECK-LABEL: @test29vec(
328 ; CHECK-NEXT: [[V:%.*]] = select i1 [[C:%.*]], <2 x i32> <i32 915, i32 915>, <2 x i32> <i32 113, i32 113>
329 ; CHECK-NEXT: ret <2 x i32> [[V]]
331 %A = select i1 %C, <2 x i32> <i32 1000, i32 1000>, <2 x i32> <i32 10, i32 10>
332 %V = xor <2 x i32> %A, <i32 123, i32 123>
336 define <2 x i32> @test29vec2(i1 %C) {
337 ; CHECK-LABEL: @test29vec2(
338 ; CHECK-NEXT: [[V:%.*]] = select i1 [[C:%.*]], <2 x i32> <i32 915, i32 2185>, <2 x i32> <i32 113, i32 339>
339 ; CHECK-NEXT: ret <2 x i32> [[V]]
341 %A = select i1 %C, <2 x i32> <i32 1000, i32 2500>, <2 x i32> <i32 10, i32 30>
342 %V = xor <2 x i32> %A, <i32 123, i32 333>
346 define i32 @test30(i1 %which) {
347 ; CHECK-LABEL: @test30(
349 ; CHECK-NEXT: br i1 [[WHICH:%.*]], label [[FINAL:%.*]], label [[DELAY:%.*]]
351 ; CHECK-NEXT: br label [[FINAL]]
353 ; CHECK-NEXT: [[A:%.*]] = phi i32 [ 915, [[ENTRY:%.*]] ], [ 113, [[DELAY]] ]
354 ; CHECK-NEXT: ret i32 [[A]]
357 br i1 %which, label %final, label %delay
363 %A = phi i32 [ 1000, %entry ], [ 10, %delay ]
364 %value = xor i32 %A, 123
368 define <2 x i32> @test30vec(i1 %which) {
369 ; CHECK-LABEL: @test30vec(
371 ; CHECK-NEXT: br i1 [[WHICH:%.*]], label [[FINAL:%.*]], label [[DELAY:%.*]]
373 ; CHECK-NEXT: br label [[FINAL]]
375 ; CHECK-NEXT: [[A:%.*]] = phi <2 x i32> [ <i32 915, i32 915>, [[ENTRY:%.*]] ], [ <i32 113, i32 113>, [[DELAY]] ]
376 ; CHECK-NEXT: ret <2 x i32> [[A]]
379 br i1 %which, label %final, label %delay
385 %A = phi <2 x i32> [ <i32 1000, i32 1000>, %entry ], [ <i32 10, i32 10>, %delay ]
386 %value = xor <2 x i32> %A, <i32 123, i32 123>
390 define <2 x i32> @test30vec2(i1 %which) {
391 ; CHECK-LABEL: @test30vec2(
393 ; CHECK-NEXT: br i1 [[WHICH:%.*]], label [[FINAL:%.*]], label [[DELAY:%.*]]
395 ; CHECK-NEXT: br label [[FINAL]]
397 ; CHECK-NEXT: [[A:%.*]] = phi <2 x i32> [ <i32 915, i32 2185>, [[ENTRY:%.*]] ], [ <i32 113, i32 339>, [[DELAY]] ]
398 ; CHECK-NEXT: ret <2 x i32> [[A]]
401 br i1 %which, label %final, label %delay
407 %A = phi <2 x i32> [ <i32 1000, i32 2500>, %entry ], [ <i32 10, i32 30>, %delay ]
408 %value = xor <2 x i32> %A, <i32 123, i32 333>
412 ; B ^ (B | A) --> A & ~B
413 ; The division ops are here to thwart complexity-based canonicalization: all ops are binops.
415 define i32 @or_xor_commute1(i32 %p1, i32 %p2) {
416 ; CHECK-LABEL: @or_xor_commute1(
417 ; CHECK-NEXT: [[A:%.*]] = udiv i32 42, [[P1:%.*]]
418 ; CHECK-NEXT: [[B:%.*]] = udiv i32 42, [[P2:%.*]]
419 ; CHECK-NEXT: [[TMP1:%.*]] = xor i32 [[B]], -1
420 ; CHECK-NEXT: [[R:%.*]] = and i32 [[A]], [[TMP1]]
421 ; CHECK-NEXT: ret i32 [[R]]
423 %a = udiv i32 42, %p1
424 %b = udiv i32 42, %p2
430 ; B ^ (B | A) --> A & ~B
431 ; The division ops are here to thwart complexity-based canonicalization: all ops are binops.
433 define i32 @or_xor_commute2(i32 %p1, i32 %p2) {
434 ; CHECK-LABEL: @or_xor_commute2(
435 ; CHECK-NEXT: [[A:%.*]] = udiv i32 42, [[P1:%.*]]
436 ; CHECK-NEXT: [[B:%.*]] = udiv i32 42, [[P2:%.*]]
437 ; CHECK-NEXT: [[TMP1:%.*]] = xor i32 [[B]], -1
438 ; CHECK-NEXT: [[R:%.*]] = and i32 [[A]], [[TMP1]]
439 ; CHECK-NEXT: ret i32 [[R]]
441 %a = udiv i32 42, %p1
442 %b = udiv i32 42, %p2
448 ; B ^ (B | A) --> A & ~B
449 ; The division ops are here to thwart complexity-based canonicalization: all ops are binops.
451 define i32 @or_xor_commute3(i32 %p1, i32 %p2) {
452 ; CHECK-LABEL: @or_xor_commute3(
453 ; CHECK-NEXT: [[A:%.*]] = udiv i32 42, [[P1:%.*]]
454 ; CHECK-NEXT: [[B:%.*]] = udiv i32 42, [[P2:%.*]]
455 ; CHECK-NEXT: [[TMP1:%.*]] = xor i32 [[B]], -1
456 ; CHECK-NEXT: [[R:%.*]] = and i32 [[A]], [[TMP1]]
457 ; CHECK-NEXT: ret i32 [[R]]
459 %a = udiv i32 42, %p1
460 %b = udiv i32 42, %p2
466 ; B ^ (B | A) --> A & ~B
467 ; The division ops are here to thwart complexity-based canonicalization: all ops are binops.
469 define i32 @or_xor_commute4(i32 %p1, i32 %p2) {
470 ; CHECK-LABEL: @or_xor_commute4(
471 ; CHECK-NEXT: [[A:%.*]] = udiv i32 42, [[P1:%.*]]
472 ; CHECK-NEXT: [[B:%.*]] = udiv i32 42, [[P2:%.*]]
473 ; CHECK-NEXT: [[TMP1:%.*]] = xor i32 [[B]], -1
474 ; CHECK-NEXT: [[R:%.*]] = and i32 [[A]], [[TMP1]]
475 ; CHECK-NEXT: ret i32 [[R]]
477 %a = udiv i32 42, %p1
478 %b = udiv i32 42, %p2
484 define i32 @or_xor_extra_use(i32 %a, i32 %b, i32* %p) {
485 ; CHECK-LABEL: @or_xor_extra_use(
486 ; CHECK-NEXT: [[O:%.*]] = or i32 [[A:%.*]], [[B:%.*]]
487 ; CHECK-NEXT: store i32 [[O]], i32* [[P:%.*]], align 4
488 ; CHECK-NEXT: [[R:%.*]] = xor i32 [[O]], [[B]]
489 ; CHECK-NEXT: ret i32 [[R]]
492 store i32 %o, i32* %p
497 ; B ^ (B & A) --> ~A & B
498 ; The division ops are here to thwart complexity-based canonicalization: all ops are binops.
500 define i32 @and_xor_commute1(i32 %p1, i32 %p2) {
501 ; CHECK-LABEL: @and_xor_commute1(
502 ; CHECK-NEXT: [[A:%.*]] = udiv i32 42, [[P1:%.*]]
503 ; CHECK-NEXT: [[B:%.*]] = udiv i32 42, [[P2:%.*]]
504 ; CHECK-NEXT: [[TMP1:%.*]] = xor i32 [[A]], -1
505 ; CHECK-NEXT: [[R:%.*]] = and i32 [[B]], [[TMP1]]
506 ; CHECK-NEXT: ret i32 [[R]]
508 %a = udiv i32 42, %p1
509 %b = udiv i32 42, %p2
515 ; B ^ (B & A) --> ~A & B
516 ; The division ops are here to thwart complexity-based canonicalization: all ops are binops.
518 define i32 @and_xor_commute2(i32 %p1, i32 %p2) {
519 ; CHECK-LABEL: @and_xor_commute2(
520 ; CHECK-NEXT: [[A:%.*]] = udiv i32 42, [[P1:%.*]]
521 ; CHECK-NEXT: [[B:%.*]] = udiv i32 42, [[P2:%.*]]
522 ; CHECK-NEXT: [[TMP1:%.*]] = xor i32 [[A]], -1
523 ; CHECK-NEXT: [[R:%.*]] = and i32 [[B]], [[TMP1]]
524 ; CHECK-NEXT: ret i32 [[R]]
526 %a = udiv i32 42, %p1
527 %b = udiv i32 42, %p2
533 ; B ^ (B & A) --> ~A & B
534 ; The division ops are here to thwart complexity-based canonicalization: all ops are binops.
536 define i32 @and_xor_commute3(i32 %p1, i32 %p2) {
537 ; CHECK-LABEL: @and_xor_commute3(
538 ; CHECK-NEXT: [[A:%.*]] = udiv i32 42, [[P1:%.*]]
539 ; CHECK-NEXT: [[B:%.*]] = udiv i32 42, [[P2:%.*]]
540 ; CHECK-NEXT: [[TMP1:%.*]] = xor i32 [[A]], -1
541 ; CHECK-NEXT: [[R:%.*]] = and i32 [[B]], [[TMP1]]
542 ; CHECK-NEXT: ret i32 [[R]]
544 %a = udiv i32 42, %p1
545 %b = udiv i32 42, %p2
551 ; B ^ (B & A) --> ~A & B
552 ; The division ops are here to thwart complexity-based canonicalization: all ops are binops.
554 define i32 @and_xor_commute4(i32 %p1, i32 %p2) {
555 ; CHECK-LABEL: @and_xor_commute4(
556 ; CHECK-NEXT: [[A:%.*]] = udiv i32 42, [[P1:%.*]]
557 ; CHECK-NEXT: [[B:%.*]] = udiv i32 42, [[P2:%.*]]
558 ; CHECK-NEXT: [[TMP1:%.*]] = xor i32 [[A]], -1
559 ; CHECK-NEXT: [[R:%.*]] = and i32 [[B]], [[TMP1]]
560 ; CHECK-NEXT: ret i32 [[R]]
562 %a = udiv i32 42, %p1
563 %b = udiv i32 42, %p2
569 define i32 @and_xor_extra_use(i32 %a, i32 %b, i32* %p) {
570 ; CHECK-LABEL: @and_xor_extra_use(
571 ; CHECK-NEXT: [[O:%.*]] = and i32 [[A:%.*]], [[B:%.*]]
572 ; CHECK-NEXT: store i32 [[O]], i32* [[P:%.*]], align 4
573 ; CHECK-NEXT: [[R:%.*]] = xor i32 [[O]], [[B]]
574 ; CHECK-NEXT: ret i32 [[R]]
577 store i32 %o, i32* %p
582 ; (~X | C2) ^ C1 --> ((X & ~C2) ^ -1) ^ C1 --> (X & ~C2) ^ ~C1
583 ; The extra use (store) is here because the simpler case
584 ; may be transformed using demanded bits.
586 define i8 @xor_or_not(i8 %x, i8* %p) {
587 ; CHECK-LABEL: @xor_or_not(
588 ; CHECK-NEXT: [[NX:%.*]] = xor i8 [[X:%.*]], -1
589 ; CHECK-NEXT: store i8 [[NX]], i8* [[P:%.*]], align 1
590 ; CHECK-NEXT: [[TMP1:%.*]] = and i8 [[X]], -8
591 ; CHECK-NEXT: [[R:%.*]] = xor i8 [[TMP1]], -13
592 ; CHECK-NEXT: ret i8 [[R]]
601 ; Don't do this if the 'or' has extra uses.
603 define i8 @xor_or_not_uses(i8 %x, i8* %p) {
604 ; CHECK-LABEL: @xor_or_not_uses(
605 ; CHECK-NEXT: [[NX:%.*]] = xor i8 [[X:%.*]], -1
606 ; CHECK-NEXT: [[OR:%.*]] = or i8 [[NX]], 7
607 ; CHECK-NEXT: store i8 [[OR]], i8* [[P:%.*]], align 1
608 ; CHECK-NEXT: [[R:%.*]] = xor i8 [[OR]], 12
609 ; CHECK-NEXT: ret i8 [[R]]
618 ; (~X & C2) ^ C1 --> ((X | ~C2) ^ -1) ^ C1 --> (X | ~C2) ^ ~C1
619 ; The extra use (store) is here because the simpler case
620 ; may be transformed using demanded bits.
622 define i8 @xor_and_not(i8 %x, i8* %p) {
623 ; CHECK-LABEL: @xor_and_not(
624 ; CHECK-NEXT: [[NX:%.*]] = xor i8 [[X:%.*]], -1
625 ; CHECK-NEXT: store i8 [[NX]], i8* [[P:%.*]], align 1
626 ; CHECK-NEXT: [[TMP1:%.*]] = or i8 [[X]], -43
627 ; CHECK-NEXT: [[R:%.*]] = xor i8 [[TMP1]], -32
628 ; CHECK-NEXT: ret i8 [[R]]
632 %and = and i8 %nx, 42
637 ; Don't do this if the 'and' has extra uses.
639 define i8 @xor_and_not_uses(i8 %x, i8* %p) {
640 ; CHECK-LABEL: @xor_and_not_uses(
641 ; CHECK-NEXT: [[NX:%.*]] = and i8 [[X:%.*]], 42
642 ; CHECK-NEXT: [[AND:%.*]] = xor i8 [[NX]], 42
643 ; CHECK-NEXT: store i8 [[AND]], i8* [[P:%.*]], align 1
644 ; CHECK-NEXT: [[R:%.*]] = xor i8 [[NX]], 53
645 ; CHECK-NEXT: ret i8 [[R]]
648 %and = and i8 %nx, 42
649 store i8 %and, i8* %p
654 ; The tests 39-47 are related to the canonicalization:
655 ; %notx = xor i32 %x, -1
656 ; %cmp = icmp sgt i32 %notx, %y
657 ; %smax = select i1 %cmp, i32 %notx, i32 %y
658 ; %res = xor i32 %smax, -1
660 ; %noty = xor i32 %y, -1
661 ; %cmp2 = icmp slt %x, %noty
662 ; %res = select i1 %cmp2, i32 %x, i32 %noty
664 ; Same transformations is valid for smin/umax/umin.
666 define i32 @test39(i32 %x) {
667 ; CHECK-LABEL: @test39(
668 ; CHECK-NEXT: [[TMP1:%.*]] = icmp slt i32 [[X:%.*]], 255
669 ; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[TMP1]], i32 [[X]], i32 255
670 ; CHECK-NEXT: ret i32 [[TMP2]]
673 %2 = icmp sgt i32 %1, -256
674 %3 = select i1 %2, i32 %1, i32 -256
675 %res = xor i32 %3, -1
679 define i32 @test40(i32 %x, i32 %y) {
680 ; CHECK-LABEL: @test40(
681 ; CHECK-NEXT: [[TMP1:%.*]] = xor i32 [[Y:%.*]], -1
682 ; CHECK-NEXT: [[TMP2:%.*]] = icmp sgt i32 [[TMP1]], [[X:%.*]]
683 ; CHECK-NEXT: [[RES:%.*]] = select i1 [[TMP2]], i32 [[X]], i32 [[TMP1]]
684 ; CHECK-NEXT: ret i32 [[RES]]
686 %notx = xor i32 %x, -1
687 %cmp1 = icmp sgt i32 %notx, %y
688 %smax = select i1 %cmp1, i32 %notx, i32 %y
689 %res = xor i32 %smax, -1
693 define i32 @test41(i32 %x, i32 %y) {
694 ; CHECK-LABEL: @test41(
695 ; CHECK-NEXT: [[TMP1:%.*]] = xor i32 [[Y:%.*]], -1
696 ; CHECK-NEXT: [[TMP2:%.*]] = icmp slt i32 [[TMP1]], [[X:%.*]]
697 ; CHECK-NEXT: [[RES:%.*]] = select i1 [[TMP2]], i32 [[X]], i32 [[TMP1]]
698 ; CHECK-NEXT: ret i32 [[RES]]
700 %notx = xor i32 %x, -1
701 %cmp1 = icmp slt i32 %notx, %y
702 %smin = select i1 %cmp1, i32 %notx, i32 %y
703 %res = xor i32 %smin, -1
707 define i32 @test42(i32 %x, i32 %y) {
708 ; CHECK-LABEL: @test42(
709 ; CHECK-NEXT: [[TMP1:%.*]] = xor i32 [[Y:%.*]], -1
710 ; CHECK-NEXT: [[TMP2:%.*]] = icmp ugt i32 [[TMP1]], [[X:%.*]]
711 ; CHECK-NEXT: [[RES:%.*]] = select i1 [[TMP2]], i32 [[X]], i32 [[TMP1]]
712 ; CHECK-NEXT: ret i32 [[RES]]
714 %notx = xor i32 %x, -1
715 %cmp1 = icmp ugt i32 %notx, %y
716 %umax = select i1 %cmp1, i32 %notx, i32 %y
717 %res = xor i32 %umax, -1
721 define i32 @test43(i32 %x, i32 %y) {
722 ; CHECK-LABEL: @test43(
723 ; CHECK-NEXT: [[TMP1:%.*]] = xor i32 [[Y:%.*]], -1
724 ; CHECK-NEXT: [[TMP2:%.*]] = icmp ult i32 [[TMP1]], [[X:%.*]]
725 ; CHECK-NEXT: [[RES:%.*]] = select i1 [[TMP2]], i32 [[X]], i32 [[TMP1]]
726 ; CHECK-NEXT: ret i32 [[RES]]
728 %notx = xor i32 %x, -1
729 %cmp1 = icmp ult i32 %notx, %y
730 %umin = select i1 %cmp1, i32 %notx, i32 %y
731 %res = xor i32 %umin, -1
735 define i32 @test44(i32 %x, i32 %y) {
736 ; CHECK-LABEL: @test44(
737 ; CHECK-NEXT: [[TMP1:%.*]] = sub i32 -4, [[Y:%.*]]
738 ; CHECK-NEXT: [[TMP2:%.*]] = icmp ugt i32 [[TMP1]], [[X:%.*]]
739 ; CHECK-NEXT: [[RES:%.*]] = select i1 [[TMP2]], i32 [[TMP1]], i32 [[X]]
740 ; CHECK-NEXT: ret i32 [[RES]]
742 %z = add i32 %y, 3 ; thwart complexity-based canonicalization
743 %notx = xor i32 %x, -1
744 %cmp1 = icmp ult i32 %z, %notx
745 %umin = select i1 %cmp1, i32 %z, i32 %notx
746 %res = xor i32 %umin, -1
750 define i32 @test45(i32 %x, i32 %y) {
751 ; CHECK-LABEL: @test45(
752 ; CHECK-NEXT: [[TMP1:%.*]] = icmp ugt i32 [[Y:%.*]], [[X:%.*]]
753 ; CHECK-NEXT: [[TMP2:%.*]] = select i1 [[TMP1]], i32 [[Y]], i32 [[X]]
754 ; CHECK-NEXT: ret i32 [[TMP2]]
757 %notx = xor i32 %x, -1
758 %cmp1 = icmp ult i32 %z, %notx
759 %umin = select i1 %cmp1, i32 %z, i32 %notx
760 %res = xor i32 %umin, -1
764 ; Check that we work with splat vectors also.
765 define <4 x i32> @test46(<4 x i32> %x) {
766 ; CHECK-LABEL: @test46(
767 ; CHECK-NEXT: [[TMP1:%.*]] = icmp slt <4 x i32> [[X:%.*]], <i32 255, i32 255, i32 255, i32 255>
768 ; CHECK-NEXT: [[TMP2:%.*]] = select <4 x i1> [[TMP1]], <4 x i32> [[X]], <4 x i32> <i32 255, i32 255, i32 255, i32 255>
769 ; CHECK-NEXT: ret <4 x i32> [[TMP2]]
771 %1 = xor <4 x i32> %x, <i32 -1, i32 -1, i32 -1, i32 -1>
772 %2 = icmp sgt <4 x i32> %1, <i32 -256, i32 -256, i32 -256, i32 -256>
773 %3 = select <4 x i1> %2, <4 x i32> %1, <4 x i32> <i32 -256, i32 -256, i32 -256, i32 -256>
774 %4 = xor <4 x i32> %3, <i32 -1, i32 -1, i32 -1, i32 -1>
778 ; Test case when select pattern has more than one use.
779 define i32 @test47(i32 %x, i32 %y, i32 %z) {
780 ; CHECK-LABEL: @test47(
781 ; CHECK-NEXT: [[NOTX:%.*]] = xor i32 [[X:%.*]], -1
782 ; CHECK-NEXT: [[CMP1:%.*]] = icmp ugt i32 [[NOTX]], [[Y:%.*]]
783 ; CHECK-NEXT: [[UMAX:%.*]] = select i1 [[CMP1]], i32 [[NOTX]], i32 [[Y]]
784 ; CHECK-NEXT: [[UMIN:%.*]] = xor i32 [[UMAX]], -1
785 ; CHECK-NEXT: [[ADD:%.*]] = add i32 [[UMAX]], [[Z:%.*]]
786 ; CHECK-NEXT: [[RES:%.*]] = mul i32 [[ADD]], [[UMIN]]
787 ; CHECK-NEXT: ret i32 [[RES]]
789 %notx = xor i32 %x, -1
790 %cmp1 = icmp ugt i32 %notx, %y
791 %umax = select i1 %cmp1, i32 %notx, i32 %y
792 %umin = xor i32 %umax, -1
793 %add = add i32 %umax, %z
794 %res = mul i32 %umin, %add
798 define i32 @test48(i32 %x) {
799 ; CHECK-LABEL: @test48(
800 ; CHECK-NEXT: [[TMP1:%.*]] = add i32 [[X:%.*]], 1
801 ; CHECK-NEXT: [[TMP2:%.*]] = icmp slt i32 [[TMP1]], -1
802 ; CHECK-NEXT: [[D:%.*]] = select i1 [[TMP2]], i32 [[TMP1]], i32 -1
803 ; CHECK-NEXT: ret i32 [[D]]
806 %b = icmp sgt i32 %a, 0
807 %c = select i1 %b, i32 %a, i32 0
812 define <2 x i32> @test48vec(<2 x i32> %x) {
813 ; CHECK-LABEL: @test48vec(
814 ; CHECK-NEXT: [[TMP1:%.*]] = add <2 x i32> [[X:%.*]], <i32 1, i32 1>
815 ; CHECK-NEXT: [[TMP2:%.*]] = icmp slt <2 x i32> [[TMP1]], <i32 -1, i32 -1>
816 ; CHECK-NEXT: [[D:%.*]] = select <2 x i1> [[TMP2]], <2 x i32> [[TMP1]], <2 x i32> <i32 -1, i32 -1>
817 ; CHECK-NEXT: ret <2 x i32> [[D]]
819 %a = sub <2 x i32> <i32 -2, i32 -2>, %x
820 %b = icmp sgt <2 x i32> %a, zeroinitializer
821 %c = select <2 x i1> %b, <2 x i32> %a, <2 x i32> zeroinitializer
822 %d = xor <2 x i32> %c, <i32 -1, i32 -1>
826 define i32 @test49(i32 %x) {
827 ; CHECK-LABEL: @test49(
828 ; CHECK-NEXT: [[TMP1:%.*]] = sub i32 1, [[X:%.*]]
829 ; CHECK-NEXT: [[TMP2:%.*]] = icmp sgt i32 [[TMP1]], 0
830 ; CHECK-NEXT: [[D:%.*]] = select i1 [[TMP2]], i32 [[TMP1]], i32 0
831 ; CHECK-NEXT: ret i32 [[D]]
834 %b = icmp slt i32 %a, -1
835 %c = select i1 %b, i32 %a, i32 -1
840 define <2 x i32> @test49vec(<2 x i32> %x) {
841 ; CHECK-LABEL: @test49vec(
842 ; CHECK-NEXT: [[TMP1:%.*]] = sub <2 x i32> <i32 1, i32 1>, [[X:%.*]]
843 ; CHECK-NEXT: [[TMP2:%.*]] = icmp sgt <2 x i32> [[TMP1]], zeroinitializer
844 ; CHECK-NEXT: [[D:%.*]] = select <2 x i1> [[TMP2]], <2 x i32> [[TMP1]], <2 x i32> zeroinitializer
845 ; CHECK-NEXT: ret <2 x i32> [[D]]
847 %a = add <2 x i32> %x, <i32 -2, i32 -2>
848 %b = icmp slt <2 x i32> %a, <i32 -1, i32 -1>
849 %c = select <2 x i1> %b, <2 x i32> %a, <2 x i32> <i32 -1, i32 -1>
850 %d = xor <2 x i32> %c, <i32 -1, i32 -1>
854 define i32 @test50(i32 %x, i32 %y) {
855 ; CHECK-LABEL: @test50(
856 ; CHECK-NEXT: [[TMP1:%.*]] = sub i32 1, [[X:%.*]]
857 ; CHECK-NEXT: [[TMP2:%.*]] = add i32 [[Y:%.*]], 1
858 ; CHECK-NEXT: [[TMP3:%.*]] = icmp sgt i32 [[TMP1]], [[TMP2]]
859 ; CHECK-NEXT: [[E:%.*]] = select i1 [[TMP3]], i32 [[TMP1]], i32 [[TMP2]]
860 ; CHECK-NEXT: ret i32 [[E]]
864 %c = icmp slt i32 %a, %b
865 %d = select i1 %c, i32 %a, i32 %b
870 define <2 x i32> @test50vec(<2 x i32> %x, <2 x i32> %y) {
871 ; CHECK-LABEL: @test50vec(
872 ; CHECK-NEXT: [[TMP1:%.*]] = sub <2 x i32> <i32 1, i32 1>, [[X:%.*]]
873 ; CHECK-NEXT: [[TMP2:%.*]] = add <2 x i32> [[Y:%.*]], <i32 1, i32 1>
874 ; CHECK-NEXT: [[TMP3:%.*]] = icmp sgt <2 x i32> [[TMP1]], [[TMP2]]
875 ; CHECK-NEXT: [[E:%.*]] = select <2 x i1> [[TMP3]], <2 x i32> [[TMP1]], <2 x i32> [[TMP2]]
876 ; CHECK-NEXT: ret <2 x i32> [[E]]
878 %a = add <2 x i32> %x, <i32 -2, i32 -2>
879 %b = sub <2 x i32> <i32 -2, i32 -2>, %y
880 %c = icmp slt <2 x i32> %a, %b
881 %d = select <2 x i1> %c, <2 x i32> %a, <2 x i32> %b
882 %e = xor <2 x i32> %d, <i32 -1, i32 -1>
886 define i32 @test51(i32 %x, i32 %y) {
887 ; CHECK-LABEL: @test51(
888 ; CHECK-NEXT: [[TMP1:%.*]] = sub i32 -3, [[X:%.*]]
889 ; CHECK-NEXT: [[TMP2:%.*]] = add i32 [[Y:%.*]], -3
890 ; CHECK-NEXT: [[TMP3:%.*]] = icmp slt i32 [[TMP1]], [[TMP2]]
891 ; CHECK-NEXT: [[E:%.*]] = select i1 [[TMP3]], i32 [[TMP1]], i32 [[TMP2]]
892 ; CHECK-NEXT: ret i32 [[E]]
896 %c = icmp sgt i32 %a, %b
897 %d = select i1 %c, i32 %a, i32 %b
902 define <2 x i32> @test51vec(<2 x i32> %x, <2 x i32> %y) {
903 ; CHECK-LABEL: @test51vec(
904 ; CHECK-NEXT: [[TMP1:%.*]] = sub <2 x i32> <i32 -3, i32 -3>, [[X:%.*]]
905 ; CHECK-NEXT: [[TMP2:%.*]] = add <2 x i32> [[Y:%.*]], <i32 -3, i32 -3>
906 ; CHECK-NEXT: [[TMP3:%.*]] = icmp slt <2 x i32> [[TMP1]], [[TMP2]]
907 ; CHECK-NEXT: [[E:%.*]] = select <2 x i1> [[TMP3]], <2 x i32> [[TMP1]], <2 x i32> [[TMP2]]
908 ; CHECK-NEXT: ret <2 x i32> [[E]]
910 %a = add <2 x i32> %x, <i32 2, i32 2>
911 %b = sub <2 x i32> <i32 2, i32 2>, %y
912 %c = icmp sgt <2 x i32> %a, %b
913 %d = select <2 x i1> %c, <2 x i32> %a, <2 x i32> %b
914 %e = xor <2 x i32> %d, <i32 -1, i32 -1>
918 define i4 @or_or_xor(i4 %x, i4 %y, i4 %z) {
919 ; CHECK-LABEL: @or_or_xor(
920 ; CHECK-NEXT: [[TMP1:%.*]] = xor i4 [[Z:%.*]], -1
921 ; CHECK-NEXT: [[TMP2:%.*]] = xor i4 [[X:%.*]], [[Y:%.*]]
922 ; CHECK-NEXT: [[R:%.*]] = and i4 [[TMP2]], [[TMP1]]
923 ; CHECK-NEXT: ret i4 [[R]]
931 define i4 @or_or_xor_commute1(i4 %x, i4 %y, i4 %z) {
932 ; CHECK-LABEL: @or_or_xor_commute1(
933 ; CHECK-NEXT: [[TMP1:%.*]] = xor i4 [[Z:%.*]], -1
934 ; CHECK-NEXT: [[TMP2:%.*]] = xor i4 [[X:%.*]], [[Y:%.*]]
935 ; CHECK-NEXT: [[R:%.*]] = and i4 [[TMP2]], [[TMP1]]
936 ; CHECK-NEXT: ret i4 [[R]]
944 define i4 @or_or_xor_commute2(i4 %x, i4 %y, i4 %z) {
945 ; CHECK-LABEL: @or_or_xor_commute2(
946 ; CHECK-NEXT: [[TMP1:%.*]] = xor i4 [[Z:%.*]], -1
947 ; CHECK-NEXT: [[TMP2:%.*]] = xor i4 [[X:%.*]], [[Y:%.*]]
948 ; CHECK-NEXT: [[R:%.*]] = and i4 [[TMP2]], [[TMP1]]
949 ; CHECK-NEXT: ret i4 [[R]]
957 define <2 x i4> @or_or_xor_commute3(<2 x i4> %x, <2 x i4> %y, <2 x i4> %z) {
958 ; CHECK-LABEL: @or_or_xor_commute3(
959 ; CHECK-NEXT: [[TMP1:%.*]] = xor <2 x i4> [[Z:%.*]], <i4 -1, i4 -1>
960 ; CHECK-NEXT: [[TMP2:%.*]] = xor <2 x i4> [[X:%.*]], [[Y:%.*]]
961 ; CHECK-NEXT: [[R:%.*]] = and <2 x i4> [[TMP2]], [[TMP1]]
962 ; CHECK-NEXT: ret <2 x i4> [[R]]
964 %o1 = or <2 x i4> %x, %z
965 %o2 = or <2 x i4> %y, %z
966 %r = xor <2 x i4> %o1, %o2
970 define i4 @or_or_xor_use1(i4 %x, i4 %y, i4 %z, i4* %p) {
971 ; CHECK-LABEL: @or_or_xor_use1(
972 ; CHECK-NEXT: [[O1:%.*]] = or i4 [[Z:%.*]], [[X:%.*]]
973 ; CHECK-NEXT: store i4 [[O1]], i4* [[P:%.*]], align 1
974 ; CHECK-NEXT: [[O2:%.*]] = or i4 [[Z]], [[Y:%.*]]
975 ; CHECK-NEXT: [[R:%.*]] = xor i4 [[O1]], [[O2]]
976 ; CHECK-NEXT: ret i4 [[R]]
985 define i4 @or_or_xor_use2(i4 %x, i4 %y, i4 %z, i4* %p) {
986 ; CHECK-LABEL: @or_or_xor_use2(
987 ; CHECK-NEXT: [[O1:%.*]] = or i4 [[Z:%.*]], [[X:%.*]]
988 ; CHECK-NEXT: [[O2:%.*]] = or i4 [[Z]], [[Y:%.*]]
989 ; CHECK-NEXT: store i4 [[O2]], i4* [[P:%.*]], align 1
990 ; CHECK-NEXT: [[R:%.*]] = xor i4 [[O1]], [[O2]]
991 ; CHECK-NEXT: ret i4 [[R]]
1000 ; PR32706 - https://bugs.llvm.org/show_bug.cgi?id=32706
1001 ; Pin an xor constant operand to -1 if possible because 'not' is better for SCEV and codegen.
1003 define i32 @not_is_canonical(i32 %x, i32 %y) {
1004 ; CHECK-LABEL: @not_is_canonical(
1005 ; CHECK-NEXT: [[SUB:%.*]] = xor i32 [[X:%.*]], -1
1006 ; CHECK-NEXT: [[ADD:%.*]] = add i32 [[SUB]], [[Y:%.*]]
1007 ; CHECK-NEXT: [[MUL:%.*]] = shl i32 [[ADD]], 2
1008 ; CHECK-NEXT: ret i32 [[MUL]]
1010 %sub = xor i32 %x, 1073741823
1011 %add = add i32 %sub, %y
1012 %mul = shl i32 %add, 2
1016 define i8 @not_shl(i8 %x) {
1017 ; CHECK-LABEL: @not_shl(
1018 ; CHECK-NEXT: [[TMP1:%.*]] = xor i8 [[X:%.*]], -1
1019 ; CHECK-NEXT: [[R:%.*]] = shl i8 [[TMP1]], 7
1020 ; CHECK-NEXT: ret i8 [[R]]
1027 define <2 x i8> @not_shl_vec(<2 x i8> %x) {
1028 ; CHECK-LABEL: @not_shl_vec(
1029 ; CHECK-NEXT: [[TMP1:%.*]] = xor <2 x i8> [[X:%.*]], <i8 -1, i8 -1>
1030 ; CHECK-NEXT: [[R:%.*]] = shl <2 x i8> [[TMP1]], <i8 5, i8 5>
1031 ; CHECK-NEXT: ret <2 x i8> [[R]]
1033 %a = shl <2 x i8> %x, <i8 5, i8 5>
1034 %r = xor <2 x i8> %a, <i8 224, i8 224>
1040 define i8 @not_shl_extra_use(i8 %x) {
1041 ; CHECK-LABEL: @not_shl_extra_use(
1042 ; CHECK-NEXT: [[A:%.*]] = shl i8 [[X:%.*]], 7
1043 ; CHECK-NEXT: call void @use(i8 [[A]])
1044 ; CHECK-NEXT: [[R:%.*]] = xor i8 [[A]], -128
1045 ; CHECK-NEXT: ret i8 [[R]]
1048 call void @use(i8 %a)
1055 define i8 @not_shl_wrong_const(i8 %x) {
1056 ; CHECK-LABEL: @not_shl_wrong_const(
1057 ; CHECK-NEXT: [[A:%.*]] = shl i8 [[X:%.*]], 6
1058 ; CHECK-NEXT: [[R:%.*]] = xor i8 [[A]], -128
1059 ; CHECK-NEXT: ret i8 [[R]]
1066 define i8 @not_lshr(i8 %x) {
1067 ; CHECK-LABEL: @not_lshr(
1068 ; CHECK-NEXT: [[TMP1:%.*]] = xor i8 [[X:%.*]], -1
1069 ; CHECK-NEXT: [[R:%.*]] = lshr i8 [[TMP1]], 5
1070 ; CHECK-NEXT: ret i8 [[R]]
1077 define <2 x i8> @not_lshr_vec(<2 x i8> %x) {
1078 ; CHECK-LABEL: @not_lshr_vec(
1079 ; CHECK-NEXT: [[TMP1:%.*]] = xor <2 x i8> [[X:%.*]], <i8 -1, i8 -1>
1080 ; CHECK-NEXT: [[R:%.*]] = lshr <2 x i8> [[TMP1]], <i8 7, i8 7>
1081 ; CHECK-NEXT: ret <2 x i8> [[R]]
1083 %a = lshr <2 x i8> %x, <i8 7, i8 7>
1084 %r = xor <2 x i8> %a, <i8 1, i8 1>
1090 define i8 @not_lshr_extra_use(i8 %x) {
1091 ; CHECK-LABEL: @not_lshr_extra_use(
1092 ; CHECK-NEXT: [[A:%.*]] = lshr i8 [[X:%.*]], 5
1093 ; CHECK-NEXT: call void @use(i8 [[A]])
1094 ; CHECK-NEXT: [[R:%.*]] = xor i8 [[A]], 7
1095 ; CHECK-NEXT: ret i8 [[R]]
1098 call void @use(i8 %a)
1105 define i8 @not_lshr_wrong_const(i8 %x) {
1106 ; CHECK-LABEL: @not_lshr_wrong_const(
1107 ; CHECK-NEXT: [[A:%.*]] = lshr i8 [[X:%.*]], 5
1108 ; CHECK-NEXT: [[R:%.*]] = xor i8 [[A]], 3
1109 ; CHECK-NEXT: ret i8 [[R]]
1116 define i8 @ashr_not(i8 %x) {
1117 ; CHECK-LABEL: @ashr_not(
1118 ; CHECK-NEXT: [[N:%.*]] = ashr i8 [[X:%.*]], 5
1119 ; CHECK-NEXT: [[R:%.*]] = xor i8 [[N]], -1
1120 ; CHECK-NEXT: ret i8 [[R]]
1127 ; Unlike the logicial shifts, 'not' is canonicalized after ashr.
1129 define i8 @not_ashr(i8 %x) {
1130 ; CHECK-LABEL: @not_ashr(
1131 ; CHECK-NEXT: [[A:%.*]] = ashr i8 [[X:%.*]], 5
1132 ; CHECK-NEXT: [[R:%.*]] = xor i8 [[A]], -1
1133 ; CHECK-NEXT: ret i8 [[R]]
1140 define <2 x i8> @not_ashr_vec(<2 x i8> %x) {
1141 ; CHECK-LABEL: @not_ashr_vec(
1142 ; CHECK-NEXT: [[A:%.*]] = ashr <2 x i8> [[X:%.*]], <i8 7, i8 7>
1143 ; CHECK-NEXT: [[R:%.*]] = xor <2 x i8> [[A]], <i8 -1, i8 -1>
1144 ; CHECK-NEXT: ret <2 x i8> [[R]]
1146 %a = ashr <2 x i8> %x, <i8 7, i8 7>
1147 %r = xor <2 x i8> %a, <i8 -1, i8 -1>
1151 define i8 @not_ashr_extra_use(i8 %x) {
1152 ; CHECK-LABEL: @not_ashr_extra_use(
1153 ; CHECK-NEXT: [[A:%.*]] = ashr i8 [[X:%.*]], 5
1154 ; CHECK-NEXT: call void @use(i8 [[A]])
1155 ; CHECK-NEXT: [[R:%.*]] = xor i8 [[A]], -1
1156 ; CHECK-NEXT: ret i8 [[R]]
1159 call void @use(i8 %a)
1164 define i8 @not_ashr_wrong_const(i8 %x) {
1165 ; CHECK-LABEL: @not_ashr_wrong_const(
1166 ; CHECK-NEXT: [[A:%.*]] = ashr i8 [[X:%.*]], 5
1167 ; CHECK-NEXT: [[R:%.*]] = xor i8 [[A]], -2
1168 ; CHECK-NEXT: ret i8 [[R]]
1175 ; (~A & B) ^ A --> A | B
1177 define <2 x i32> @xor_andn_commute1(<2 x i32> %a, <2 x i32> %b) {
1178 ; CHECK-LABEL: @xor_andn_commute1(
1179 ; CHECK-NEXT: [[Z:%.*]] = or <2 x i32> [[A:%.*]], [[B:%.*]]
1180 ; CHECK-NEXT: ret <2 x i32> [[Z]]
1182 %nota = xor <2 x i32> %a, <i32 -1, i32 -1>
1183 %r = and <2 x i32> %nota, %b
1184 %z = xor <2 x i32> %r, %a
1188 ; (B & ~A) ^ A --> A | B
1190 define i33 @xor_andn_commute2(i33 %a, i33 %pb) {
1191 ; CHECK-LABEL: @xor_andn_commute2(
1192 ; CHECK-NEXT: [[B:%.*]] = udiv i33 42, [[PB:%.*]]
1193 ; CHECK-NEXT: [[Z:%.*]] = or i33 [[B]], [[A:%.*]]
1194 ; CHECK-NEXT: ret i33 [[Z]]
1196 %b = udiv i33 42, %pb ; thwart complexity-based canonicalization
1197 %nota = xor i33 %a, -1
1198 %r = and i33 %b, %nota
1203 ; A ^ (~A & B) --> A | B
1205 define i32 @xor_andn_commute3(i32 %pa, i32 %b) {
1206 ; CHECK-LABEL: @xor_andn_commute3(
1207 ; CHECK-NEXT: [[A:%.*]] = udiv i32 42, [[PA:%.*]]
1208 ; CHECK-NEXT: [[Z:%.*]] = or i32 [[A]], [[B:%.*]]
1209 ; CHECK-NEXT: ret i32 [[Z]]
1211 %a = udiv i32 42, %pa ; thwart complexity-based canonicalization
1212 %nota = xor i32 %a, -1
1213 %r = and i32 %nota, %b
1218 ; A ^ (B & ~A) --> A | B
1220 define i32 @xor_andn_commute4(i32 %pa, i32 %pb) {
1221 ; CHECK-LABEL: @xor_andn_commute4(
1222 ; CHECK-NEXT: [[A:%.*]] = udiv i32 42, [[PA:%.*]]
1223 ; CHECK-NEXT: [[B:%.*]] = udiv i32 42, [[PB:%.*]]
1224 ; CHECK-NEXT: [[Z:%.*]] = or i32 [[A]], [[B]]
1225 ; CHECK-NEXT: ret i32 [[Z]]
1227 %a = udiv i32 42, %pa ; thwart complexity-based canonicalization
1228 %b = udiv i32 42, %pb ; thwart complexity-based canonicalization
1229 %nota = xor i32 %a, -1
1230 %r = and i32 %b, %nota