1 ; Test that compares are omitted if CC already has the right value
4 ; RUN: llc < %s -mtriple=s390x-linux-gnu -mcpu=z10 -no-integrated-as \
5 ; RUN: -verify-machineinstrs| FileCheck %s
9 ; Addition provides enough for equality comparisons with zero. First teest
11 define i32 @f1(i32 %a, i32 %b, i32 *%dest) {
13 ; CHECK: afi %r2, 1000000
14 ; CHECK-NEXT: ber %r14
17 %res = add i32 %a, 1000000
18 %cmp = icmp eq i32 %res, 0
19 br i1 %cmp, label %exit, label %store
22 store i32 %b, i32 *%dest
29 ; ...and again with NE.
30 define i32 @f2(i32 %a, i32 %b, i32 *%dest) {
32 ; CHECK: afi %r2, 1000000
33 ; CHECK-NEXT: bner %r14
36 %res = add i32 %a, 1000000
37 %cmp = icmp ne i32 %res, 0
38 br i1 %cmp, label %exit, label %store
41 store i32 %b, i32 *%dest
48 ; SLT requires a comparison.
49 define i32 @f3(i32 %a, i32 %b, i32 *%dest) {
51 ; CHECK: afi %r2, 1000000
52 ; CHECK-NEXT: cibl %r2, 0, 0(%r14)
55 %res = add i32 %a, 1000000
56 %cmp = icmp slt i32 %res, 0
57 br i1 %cmp, label %exit, label %store
60 store i32 %b, i32 *%dest
68 define i32 @f4(i32 %a, i32 %b, i32 *%dest) {
70 ; CHECK: afi %r2, 1000000
71 ; CHECK-NEXT: cible %r2, 0, 0(%r14)
74 %res = add i32 %a, 1000000
75 %cmp = icmp sle i32 %res, 0
76 br i1 %cmp, label %exit, label %store
79 store i32 %b, i32 *%dest
87 define i32 @f5(i32 %a, i32 %b, i32 *%dest) {
89 ; CHECK: afi %r2, 1000000
90 ; CHECK-NEXT: cibh %r2, 0, 0(%r14)
93 %res = add i32 %a, 1000000
94 %cmp = icmp sgt i32 %res, 0
95 br i1 %cmp, label %exit, label %store
98 store i32 %b, i32 *%dest
106 define i32 @f6(i32 %a, i32 %b, i32 *%dest) {
108 ; CHECK: afi %r2, 1000000
109 ; CHECK-NEXT: cibhe %r2, 0, 0(%r14)
112 %res = add i32 %a, 1000000
113 %cmp = icmp sge i32 %res, 0
114 br i1 %cmp, label %exit, label %store
117 store i32 %b, i32 *%dest
124 ; Subtraction also provides enough for equality comparisons with zero.
125 define i32 @f7(i32 %a, i32 %b, i32 *%dest) {
127 ; CHECK: s %r2, 0(%r4)
128 ; CHECK-NEXT: bner %r14
131 %cur = load i32, i32 *%dest
132 %res = sub i32 %a, %cur
133 %cmp = icmp ne i32 %res, 0
134 br i1 %cmp, label %exit, label %store
137 store i32 %b, i32 *%dest
144 ; ...but not for ordered comparisons.
145 define i32 @f8(i32 %a, i32 %b, i32 *%dest) {
147 ; CHECK: s %r2, 0(%r4)
148 ; CHECK-NEXT: cibl %r2, 0, 0(%r14)
151 %cur = load i32, i32 *%dest
152 %res = sub i32 %a, %cur
153 %cmp = icmp slt i32 %res, 0
154 br i1 %cmp, label %exit, label %store
157 store i32 %b, i32 *%dest
164 ; Logic register-register instructions also provide enough for equality
165 ; comparisons with zero.
166 define i32 @f9(i32 %a, i32 %b, i32 *%dest) {
169 ; CHECK-NEXT: blr %r14
172 %res = and i32 %a, %b
173 %cmp = icmp ne i32 %res, 0
174 br i1 %cmp, label %exit, label %store
177 store i32 %b, i32 *%dest
184 ; ...but not for ordered comparisons.
185 define i32 @f10(i32 %a, i32 %b, i32 *%dest) {
188 ; CHECK-NEXT: cibl %r2, 0, 0(%r14)
191 %res = and i32 %a, %b
192 %cmp = icmp slt i32 %res, 0
193 br i1 %cmp, label %exit, label %store
196 store i32 %b, i32 *%dest
203 ; Logic register-immediate instructions also provide enough for equality
204 ; comparisons with zero if the immediate covers the whole register.
205 define i32 @f11(i32 %a, i32 %b, i32 *%dest) {
207 ; CHECK: nilf %r2, 100000001
208 ; CHECK-NEXT: blr %r14
211 %res = and i32 %a, 100000001
212 %cmp = icmp ne i32 %res, 0
213 br i1 %cmp, label %exit, label %store
216 store i32 %b, i32 *%dest
223 ; Partial logic register-immediate instructions do not provide simple
225 define i32 @f12(i32 %a, i32 %b, i32 *%dest) {
227 ; CHECK: nill %r2, 65436
228 ; CHECK-NEXT: ciblh %r2, 0, 0(%r14)
231 %res = and i32 %a, -100
232 %cmp = icmp ne i32 %res, 0
233 br i1 %cmp, label %exit, label %store
236 store i32 %b, i32 *%dest
243 ; SRA provides the same CC result as a comparison with zero.
244 define i32 @f13(i32 %a, i32 %b, i32 *%dest) {
246 ; CHECK: sra %r2, 0(%r3)
247 ; CHECK-NEXT: ber %r14
250 %res = ashr i32 %a, %b
251 %cmp = icmp eq i32 %res, 0
252 br i1 %cmp, label %exit, label %store
255 store i32 %b, i32 *%dest
262 ; ...and again with NE.
263 define i32 @f14(i32 %a, i32 %b, i32 *%dest) {
265 ; CHECK: sra %r2, 0(%r3)
266 ; CHECK-NEXT: blhr %r14
269 %res = ashr i32 %a, %b
270 %cmp = icmp ne i32 %res, 0
271 br i1 %cmp, label %exit, label %store
274 store i32 %b, i32 *%dest
282 define i32 @f15(i32 %a, i32 %b, i32 *%dest) {
284 ; CHECK: sra %r2, 0(%r3)
285 ; CHECK-NEXT: blr %r14
288 %res = ashr i32 %a, %b
289 %cmp = icmp slt i32 %res, 0
290 br i1 %cmp, label %exit, label %store
293 store i32 %b, i32 *%dest
301 define i32 @f16(i32 %a, i32 %b, i32 *%dest) {
303 ; CHECK: sra %r2, 0(%r3)
304 ; CHECK-NEXT: bler %r14
307 %res = ashr i32 %a, %b
308 %cmp = icmp sle i32 %res, 0
309 br i1 %cmp, label %exit, label %store
312 store i32 %b, i32 *%dest
320 define i32 @f17(i32 %a, i32 %b, i32 *%dest) {
322 ; CHECK: sra %r2, 0(%r3)
323 ; CHECK-NEXT: bhr %r14
326 %res = ashr i32 %a, %b
327 %cmp = icmp sgt i32 %res, 0
328 br i1 %cmp, label %exit, label %store
331 store i32 %b, i32 *%dest
339 define i32 @f18(i32 %a, i32 %b, i32 *%dest) {
341 ; CHECK: sra %r2, 0(%r3)
342 ; CHECK-NEXT: bher %r14
345 %res = ashr i32 %a, %b
346 %cmp = icmp sge i32 %res, 0
347 br i1 %cmp, label %exit, label %store
350 store i32 %b, i32 *%dest
357 ; RISBG provides the same result as a comparison against zero.
359 define i64 @f19(i64 %a, i64 %b, i64 *%dest) {
361 ; CHECK: risbg %r2, %r3, 0, 190, 0
362 ; CHECK-NEXT: ber %r14
365 %res = and i64 %b, -2
366 %cmp = icmp eq i64 %res, 0
367 br i1 %cmp, label %exit, label %store
370 store i64 %b, i64 *%dest
377 ; ...and the SLT case.
378 define i64 @f20(i64 %a, i64 %b, i64 *%dest) {
380 ; CHECK: risbg %r2, %r3, 0, 190, 0
381 ; CHECK-NEXT: blr %r14
384 %res = and i64 %b, -2
385 %cmp = icmp slt i64 %res, 0
386 br i1 %cmp, label %exit, label %store
389 store i64 %b, i64 *%dest
396 ; Test a case where the register we're testing is set by a non-CC-clobbering
398 define i32 @f21(i32 %a, i32 %b, i32 *%dest) {
400 ; CHECK: afi %r2, 1000000
402 ; CHECK-NEXT: blah %r2
403 ; CHECK-NEXT: #NO_APP
404 ; CHECK-NEXT: cibe %r2, 0, 0(%r14)
407 %add = add i32 %a, 1000000
408 %res = call i32 asm "blah $0", "=r,0" (i32 %add)
409 %cmp = icmp eq i32 %res, 0
410 br i1 %cmp, label %exit, label %store
413 store i32 %b, i32 *%dest
420 ; ...and again with a CC-clobbering instruction.
421 define i32 @f22(i32 %a, i32 %b, i32 *%dest) {
423 ; CHECK: afi %r2, 1000000
425 ; CHECK-NEXT: blah %r2
426 ; CHECK-NEXT: #NO_APP
427 ; CHECK-NEXT: cibe %r2, 0, 0(%r14)
430 %add = add i32 %a, 1000000
431 %res = call i32 asm "blah $0", "=r,0,~{cc}" (i32 %add)
432 %cmp = icmp eq i32 %res, 0
433 br i1 %cmp, label %exit, label %store
436 store i32 %b, i32 *%dest
443 ; Check that stores do not interfere.
444 define i32 @f23(i32 %a, i32 %b, i32 *%dest1, i32 *%dest2) {
446 ; CHECK: afi %r2, 1000000
447 ; CHECK-NEXT: st %r2, 0(%r4)
448 ; CHECK-NEXT: bner %r14
451 %res = add i32 %a, 1000000
452 store i32 %res, i32 *%dest1
453 %cmp = icmp ne i32 %res, 0
454 br i1 %cmp, label %exit, label %store
457 store i32 %b, i32 *%dest2
464 ; Check that calls do interfere.
465 define void @f24(i32 *%ptr) {
467 ; CHECK: afi [[REG:%r[0-9]+]], 1000000
468 ; CHECK-NEXT: brasl %r14, foo@PLT
469 ; CHECK-NEXT: cijlh [[REG]], 0, .L{{.*}}
472 %val = load i32, i32 *%ptr
473 %xor = xor i32 %val, 1
474 %add = add i32 %xor, 1000000
476 %cmp = icmp eq i32 %add, 0
477 br i1 %cmp, label %store, label %exit, !prof !1
480 store i32 %add, i32 *%ptr
487 ; Check that inline asms don't interfere if they don't clobber CC.
488 define void @f25(i32 %a, i32 *%ptr) {
490 ; CHECK: afi %r2, 1000000
493 ; CHECK-NEXT: #NO_APP
494 ; CHECK-NEXT: bner %r14
497 %add = add i32 %a, 1000000
498 call void asm sideeffect "blah", "r"(i32 %add)
499 %cmp = icmp ne i32 %add, 0
500 br i1 %cmp, label %exit, label %store
503 store i32 %add, i32 *%ptr
510 ; ...but do interfere if they do clobber CC.
511 define void @f26(i32 %a, i32 *%ptr) {
513 ; CHECK: afi %r2, 1000000
516 ; CHECK-NEXT: #NO_APP
517 ; CHECK-NEXT: ciblh %r2, 0, 0(%r14)
520 %add = add i32 %a, 1000000
521 call void asm sideeffect "blah", "r,~{cc}"(i32 %add)
522 %cmp = icmp ne i32 %add, 0
523 br i1 %cmp, label %exit, label %store
526 store i32 %add, i32 *%ptr
533 ; Test a case where CC is set based on a different register from the
535 define i32 @f27(i32 %a, i32 %b, i32 *%dest1, i32 *%dest2) {
537 ; CHECK: afi %r2, 1000000
538 ; CHECK-NEXT: sr %r3, %r2
539 ; CHECK-NEXT: st %r3, 0(%r4)
540 ; CHECK-NEXT: cibe %r2, 0, 0(%r14)
543 %add = add i32 %a, 1000000
544 %sub = sub i32 %b, %add
545 store i32 %sub, i32 *%dest1
546 %cmp = icmp eq i32 %add, 0
547 br i1 %cmp, label %exit, label %store
550 store i32 %sub, i32 *%dest2
557 ; Make sure that we don't confuse a base register for a destination.
558 define void @f28(i64 %a, i64 *%dest) {
560 ; CHECK: xi 0(%r2), 15
561 ; CHECK: cgibe %r2, 0, 0(%r14)
564 %ptr = inttoptr i64 %a to i8 *
565 %val = load i8, i8 *%ptr
566 %xor = xor i8 %val, 15
567 store i8 %xor, i8 *%ptr
568 %cmp = icmp eq i64 %a, 0
569 br i1 %cmp, label %exit, label %store
572 store i64 %a, i64 *%dest
579 ; Test that L gets converted to LT where useful.
580 define i32 @f29(i64 %base, i64 %index, i32 *%dest) {
582 ; CHECK: lt %r2, 0({{%r2,%r3|%r3,%r2}})
583 ; CHECK-NEXT: bler %r14
586 %add = add i64 %base, %index
587 %ptr = inttoptr i64 %add to i32 *
588 %res = load i32, i32 *%ptr
589 %cmp = icmp sle i32 %res, 0
590 br i1 %cmp, label %exit, label %store
593 store i32 %res, i32 *%dest
600 ; Test that LY gets converted to LT where useful.
601 define i32 @f30(i64 %base, i64 %index, i32 *%dest) {
603 ; CHECK: lt %r2, 100000({{%r2,%r3|%r3,%r2}})
604 ; CHECK-NEXT: bler %r14
607 %add1 = add i64 %base, %index
608 %add2 = add i64 %add1, 100000
609 %ptr = inttoptr i64 %add2 to i32 *
610 %res = load i32, i32 *%ptr
611 %cmp = icmp sle i32 %res, 0
612 br i1 %cmp, label %exit, label %store
615 store i32 %res, i32 *%dest
622 ; Test that LG gets converted to LTG where useful.
623 define i64 @f31(i64 %base, i64 %index, i64 *%dest) {
625 ; CHECK: ltg %r2, 0({{%r2,%r3|%r3,%r2}})
626 ; CHECK-NEXT: bher %r14
629 %add = add i64 %base, %index
630 %ptr = inttoptr i64 %add to i64 *
631 %res = load i64, i64 *%ptr
632 %cmp = icmp sge i64 %res, 0
633 br i1 %cmp, label %exit, label %store
636 store i64 %res, i64 *%dest
643 ; Test that LGF gets converted to LTGF where useful.
644 define i64 @f32(i64 %base, i64 %index, i64 *%dest) {
646 ; CHECK: ltgf %r2, 0({{%r2,%r3|%r3,%r2}})
647 ; CHECK-NEXT: bhr %r14
650 %add = add i64 %base, %index
651 %ptr = inttoptr i64 %add to i32 *
652 %val = load i32, i32 *%ptr
653 %res = sext i32 %val to i64
654 %cmp = icmp sgt i64 %res, 0
655 br i1 %cmp, label %exit, label %store
658 store i64 %res, i64 *%dest
665 ; Test that LR gets converted to LTR where useful.
666 define i32 @f33(i32 %dummy, i32 %val, i32 *%dest) {
668 ; CHECK: ltr %r2, %r3
670 ; CHECK-NEXT: blah %r2
671 ; CHECK-NEXT: #NO_APP
672 ; CHECK-NEXT: blr %r14
675 call void asm sideeffect "blah $0", "{r2}"(i32 %val)
676 %cmp = icmp slt i32 %val, 0
677 br i1 %cmp, label %exit, label %store
680 store i32 %val, i32 *%dest
687 ; Test that LGR gets converted to LTGR where useful.
688 define i64 @f34(i64 %dummy, i64 %val, i64 *%dest) {
690 ; CHECK: ltgr %r2, %r3
692 ; CHECK-NEXT: blah %r2
693 ; CHECK-NEXT: #NO_APP
694 ; CHECK-NEXT: bhr %r14
697 call void asm sideeffect "blah $0", "{r2}"(i64 %val)
698 %cmp = icmp sgt i64 %val, 0
699 br i1 %cmp, label %exit, label %store
702 store i64 %val, i64 *%dest
709 ; Test that LGFR gets converted to LTGFR where useful.
710 define i64 @f35(i64 %dummy, i32 %val, i64 *%dest) {
712 ; CHECK: ltgfr %r2, %r3
714 ; CHECK-NEXT: blah %r2
715 ; CHECK-NEXT: #NO_APP
716 ; CHECK-NEXT: bhr %r14
719 %ext = sext i32 %val to i64
720 call void asm sideeffect "blah $0", "{r2}"(i64 %ext)
721 %cmp = icmp sgt i64 %ext, 0
722 br i1 %cmp, label %exit, label %store
725 store i64 %ext, i64 *%dest
732 ; Test a case where it is the source rather than destination of LR that
734 define i32 @f36(i32 %val, i32 %dummy, i32 *%dest) {
736 ; CHECK: ltr %r3, %r2
738 ; CHECK-NEXT: blah %r3
739 ; CHECK-NEXT: #NO_APP
740 ; CHECK-NEXT: blr %r14
743 call void asm sideeffect "blah $0", "{r3}"(i32 %val)
744 %cmp = icmp slt i32 %val, 0
745 br i1 %cmp, label %exit, label %store
748 store i32 %val, i32 *%dest
755 ; Test a case where it is the source rather than destination of LGR that
757 define i64 @f37(i64 %val, i64 %dummy, i64 *%dest) {
759 ; CHECK: ltgr %r3, %r2
761 ; CHECK-NEXT: blah %r3
762 ; CHECK-NEXT: #NO_APP
763 ; CHECK-NEXT: blr %r14
766 call void asm sideeffect "blah $0", "{r3}"(i64 %val)
767 %cmp = icmp slt i64 %val, 0
768 br i1 %cmp, label %exit, label %store
771 store i64 %val, i64 *%dest
778 ; Test a case where it is the source rather than destination of LGFR that
780 define i32 @f38(i32 %val, i64 %dummy, i32 *%dest) {
782 ; CHECK: ltgfr %r3, %r2
784 ; CHECK-NEXT: blah %r3
785 ; CHECK-NEXT: #NO_APP
786 ; CHECK-NEXT: blr %r14
789 %ext = sext i32 %val to i64
790 call void asm sideeffect "blah $0", "{r3}"(i64 %ext)
791 %cmp = icmp slt i32 %val, 0
792 br i1 %cmp, label %exit, label %store
795 store i32 %val, i32 *%dest
802 ; Test f35 for in-register extensions.
803 define i64 @f39(i64 %dummy, i64 %a, i64 *%dest) {
805 ; CHECK: ltgfr %r2, %r3
807 ; CHECK-NEXT: blah %r2
808 ; CHECK-NEXT: #NO_APP
809 ; CHECK-NEXT: bhr %r14
812 %val = trunc i64 %a to i32
813 %ext = sext i32 %val to i64
814 call void asm sideeffect "blah $0", "{r2}"(i64 %ext)
815 %cmp = icmp sgt i64 %ext, 0
816 br i1 %cmp, label %exit, label %store
819 store i64 %ext, i64 *%dest
826 ; ...and again with what InstCombine would produce for f40.
827 define i64 @f40(i64 %dummy, i64 %a, i64 *%dest) {
829 ; CHECK: ltgfr %r2, %r3
831 ; CHECK-NEXT: blah %r2
832 ; CHECK-NEXT: #NO_APP
833 ; CHECK-NEXT: bhr %r14
836 %shl = shl i64 %a, 32
837 %ext = ashr i64 %shl, 32
838 call void asm sideeffect "blah $0", "{r2}"(i64 %ext)
839 %cmp = icmp sgt i64 %shl, 0
840 br i1 %cmp, label %exit, label %store
843 store i64 %ext, i64 *%dest
850 ; Try a form of f7 in which the subtraction operands are compared directly.
851 define i32 @f41(i32 %a, i32 %b, i32 *%dest) {
853 ; CHECK: s %r2, 0(%r4)
854 ; CHECK-NEXT: bner %r14
857 %cur = load i32, i32 *%dest
858 %res = sub i32 %a, %cur
859 %cmp = icmp ne i32 %a, %cur
860 br i1 %cmp, label %exit, label %store
863 store i32 %b, i32 *%dest
870 ; A version of f32 that tests the unextended value.
871 define i64 @f42(i64 %base, i64 %index, i64 *%dest) {
873 ; CHECK: ltgf %r2, 0({{%r2,%r3|%r3,%r2}})
874 ; CHECK-NEXT: bhr %r14
877 %add = add i64 %base, %index
878 %ptr = inttoptr i64 %add to i32 *
879 %val = load i32, i32 *%ptr
880 %res = sext i32 %val to i64
881 %cmp = icmp sgt i32 %val, 0
882 br i1 %cmp, label %exit, label %store
885 store i64 %res, i64 *%dest
892 !1 = !{!"branch_weights", i32 2, i32 1}