1 ; RUN: llc -verify-machineinstrs < %s -mtriple=powerpc64-unknown-linux-gnu | FileCheck %s
2 ; RUN: llc -verify-machineinstrs < %s -mtriple=powerpc64le-unknown-linux-gnu | FileCheck %s
4 ; Test cases for compare elimination in PPCMIPeephole pass
6 define void @func1(i32 signext %a) {
7 ; We should have only one compare instruction
13 %cmp = icmp eq i32 %a, 100
14 br i1 %cmp, label %if.then, label %if.else
17 tail call void @dummy1()
21 %cmp1 = icmp slt i32 %a, 100
22 br i1 %cmp1, label %if.then2, label %if.end3
25 tail call void @dummy2()
33 define void @func2(i32 signext %a) {
39 %cmp = icmp slt i32 %a, 100
40 br i1 %cmp, label %if.then, label %if.else
43 tail call void @dummy1()
47 %cmp1 = icmp eq i32 %a, 100
48 br i1 %cmp1, label %if.end3, label %if.then2
51 tail call void @dummy2()
59 define void @func3(i32 signext %a) {
65 %cmp = icmp sgt i32 %a, 100
66 br i1 %cmp, label %if.then, label %if.else
69 tail call void @dummy1()
73 %cmp1 = icmp eq i32 %a, 100
74 br i1 %cmp1, label %if.then2, label %if.end3
77 tail call void @dummy2()
85 define void @func4(i32 zeroext %a) {
91 %cmp = icmp eq i32 %a, 100
92 br i1 %cmp, label %if.then, label %if.else
95 tail call void @dummy1()
99 %cmp1 = icmp ult i32 %a, 100
100 br i1 %cmp1, label %if.then2, label %if.end3
103 tail call void @dummy2()
111 define void @func5(i32 zeroext %a) {
112 ; CHECK-LABEL: @func5
117 %cmp = icmp ult i32 %a, 100
118 br i1 %cmp, label %if.then, label %if.else
121 tail call void @dummy1()
125 %cmp1 = icmp eq i32 %a, 100
126 br i1 %cmp1, label %if.end3, label %if.then2
129 tail call void @dummy2()
137 define void @func6(i32 zeroext %a) {
138 ; CHECK-LABEL: @func6
143 %cmp = icmp ugt i32 %a, 100
144 br i1 %cmp, label %if.then, label %if.else
147 tail call void @dummy1()
151 %cmp1 = icmp eq i32 %a, 100
152 br i1 %cmp1, label %if.then2, label %if.end3
155 tail call void @dummy2()
163 define void @func7(i64 %a) {
164 ; CHECK-LABEL: @func7
169 %cmp = icmp eq i64 %a, 100
170 br i1 %cmp, label %if.then, label %if.else
173 tail call void @dummy1()
177 %cmp1 = icmp slt i64 %a, 100
178 br i1 %cmp1, label %if.then2, label %if.end3
181 tail call void @dummy2()
189 define void @func8(i64 %a) {
190 ; CHECK-LABEL: @func8
195 %cmp = icmp slt i64 %a, 100
196 br i1 %cmp, label %if.then, label %if.else
199 tail call void @dummy1()
203 %cmp1 = icmp eq i64 %a, 100
204 br i1 %cmp1, label %if.end3, label %if.then2
207 tail call void @dummy2()
215 define void @func9(i64 %a) {
216 ; CHECK-LABEL: @func9
221 %cmp = icmp sgt i64 %a, 100
222 br i1 %cmp, label %if.then, label %if.else
225 tail call void @dummy1()
229 %cmp1 = icmp eq i64 %a, 100
230 br i1 %cmp1, label %if.then2, label %if.end3
233 tail call void @dummy2()
241 define void @func10(i64 %a) {
242 ; CHECK-LABEL: @func10
247 %cmp = icmp eq i64 %a, 100
248 br i1 %cmp, label %if.then, label %if.else
251 tail call void @dummy1()
255 %cmp1 = icmp ult i64 %a, 100
256 br i1 %cmp1, label %if.then2, label %if.end3
259 tail call void @dummy2()
267 define void @func11(i64 %a) {
268 ; CHECK-LABEL: @func11
273 %cmp = icmp ult i64 %a, 100
274 br i1 %cmp, label %if.then, label %if.else
277 tail call void @dummy1()
281 %cmp1 = icmp eq i64 %a, 100
282 br i1 %cmp1, label %if.end3, label %if.then2
285 tail call void @dummy2()
293 define void @func12(i64 %a) {
294 ; CHECK-LABEL: @func12
299 %cmp = icmp ugt i64 %a, 100
300 br i1 %cmp, label %if.then, label %if.else
303 tail call void @dummy1()
307 %cmp1 = icmp eq i64 %a, 100
308 br i1 %cmp1, label %if.then2, label %if.end3
311 tail call void @dummy2()
319 define void @func13(i32 signext %a, i32 signext %b) {
320 ; CHECK-LABEL: @func13
325 %cmp = icmp eq i32 %a, %b
326 br i1 %cmp, label %if.then, label %if.else
329 tail call void @dummy1()
333 %cmp1 = icmp slt i32 %a, %b
334 br i1 %cmp1, label %if.then2, label %if.end3
337 tail call void @dummy2()
345 define void @func14(i32 signext %a, i32 signext %b) {
346 ; CHECK-LABEL: @func14
351 %cmp = icmp slt i32 %a, %b
352 br i1 %cmp, label %if.then, label %if.else
355 tail call void @dummy1()
359 %cmp1 = icmp sgt i32 %a, %b
360 br i1 %cmp1, label %if.then2, label %if.end3
363 tail call void @dummy2()
371 define void @func15(i32 signext %a, i32 signext %b) {
372 ; CHECK-LABEL: @func15
377 %cmp = icmp slt i32 %b, %a
378 br i1 %cmp, label %if.then, label %if.else
381 tail call void @dummy1()
385 %cmp1 = icmp eq i32 %a, %b
386 br i1 %cmp1, label %if.then2, label %if.end3
389 tail call void @dummy2()
397 define void @func16(i32 zeroext %a, i32 zeroext %b) {
398 ; CHECK-LABEL: @func16
403 %cmp = icmp eq i32 %a, %b
404 br i1 %cmp, label %if.then, label %if.else
407 tail call void @dummy1()
411 %cmp1 = icmp ult i32 %a, %b
412 br i1 %cmp1, label %if.then2, label %if.end3
415 tail call void @dummy2()
423 define void @func17(i32 zeroext %a, i32 zeroext %b) {
424 ; CHECK-LABEL: @func17
429 %cmp = icmp ult i32 %a, %b
430 br i1 %cmp, label %if.then, label %if.else
433 tail call void @dummy1()
437 %cmp1 = icmp ugt i32 %a, %b
438 br i1 %cmp1, label %if.then2, label %if.end3
441 tail call void @dummy2()
449 define void @func18(i32 zeroext %a, i32 zeroext %b) {
450 ; CHECK-LABEL: @func18
455 %cmp = icmp ult i32 %b, %a
456 br i1 %cmp, label %if.then, label %if.else
459 tail call void @dummy1()
463 %cmp1 = icmp eq i32 %a, %b
464 br i1 %cmp1, label %if.then2, label %if.end3
467 tail call void @dummy2()
475 define void @func19(i64 %a, i64 %b) {
476 ; CHECK-LABEL: @func19
481 %cmp = icmp eq i64 %a, %b
482 br i1 %cmp, label %if.then, label %if.else
485 tail call void @dummy1()
489 %cmp1 = icmp slt i64 %a, %b
490 br i1 %cmp1, label %if.then2, label %if.end3
493 tail call void @dummy2()
501 define void @func20(i64 %a, i64 %b) {
502 ; CHECK-LABEL: @func20
507 %cmp = icmp slt i64 %a, %b
508 br i1 %cmp, label %if.then, label %if.else
511 tail call void @dummy1()
515 %cmp1 = icmp sgt i64 %a, %b
516 br i1 %cmp1, label %if.then2, label %if.end3
519 tail call void @dummy2()
527 define void @func21(i64 %a, i64 %b) {
528 ; CHECK-LABEL: @func21
533 %cmp = icmp slt i64 %b, %a
534 br i1 %cmp, label %if.then, label %if.else
537 tail call void @dummy1()
541 %cmp1 = icmp eq i64 %a, %b
542 br i1 %cmp1, label %if.then2, label %if.end3
545 tail call void @dummy2()
553 define void @func22(i64 %a, i64 %b) {
554 ; CHECK-LABEL: @func22
559 %cmp = icmp eq i64 %a, %b
560 br i1 %cmp, label %if.then, label %if.else
563 tail call void @dummy1()
567 %cmp1 = icmp ult i64 %a, %b
568 br i1 %cmp1, label %if.then2, label %if.end3
571 tail call void @dummy2()
579 define void @func23(i64 %a, i64 %b) {
580 ; CHECK-LABEL: @func23
585 %cmp = icmp ult i64 %a, %b
586 br i1 %cmp, label %if.then, label %if.else
589 tail call void @dummy1()
593 %cmp1 = icmp ugt i64 %a, %b
594 br i1 %cmp1, label %if.then2, label %if.end3
597 tail call void @dummy2()
605 define void @func24(i64 %a, i64 %b) {
606 ; CHECK-LABEL: @func24
611 %cmp = icmp ult i64 %b, %a
612 br i1 %cmp, label %if.then, label %if.else
615 tail call void @dummy1()
619 %cmp1 = icmp eq i64 %a, %b
620 br i1 %cmp1, label %if.then2, label %if.end3
623 tail call void @dummy2()
631 define void @func25(i64 %a, i64 %b) {
632 ; CHECK-LABEL: @func25
637 %cmp = icmp slt i64 %b, %a
638 br i1 %cmp, label %if.then, label %if.else, !prof !1
641 tail call void @dummy1()
645 %cmp2 = icmp eq i64 %a, %b
646 br i1 %cmp2, label %if.then4, label %if.else5
649 tail call void @dummy2()
653 tail call void @dummy3()
661 define void @func26(i32 signext %a) {
662 ; CHECK-LABEL: @func26
667 %cmp = icmp sgt i32 %a, 0
668 br i1 %cmp, label %if.then, label %if.else, !prof !2
671 tail call void @dummy1()
675 %cmp2 = icmp eq i32 %a, 0
676 br i1 %cmp2, label %if.then7, label %if.else8, !prof !2
679 tail call void @dummy2()
683 tail call void @dummy3()
690 @g1 = external local_unnamed_addr global i32, align 4
691 @g2 = external local_unnamed_addr global i32, align 4
693 define void @func27(i32 signext %a) {
694 ; CHECK-LABEL: @func27
701 %cmp = icmp eq i32 %a, 0
702 br i1 %cmp, label %if.end3.sink.split, label %if.else
705 %cmp1 = icmp slt i32 %a, 0
706 br i1 %cmp1, label %if.end3.sink.split, label %if.end
709 %g2.sink = phi ptr [ @g2, %if.else ], [ @g1, %entry ]
710 store i32 0, ptr %g2.sink, align 4
717 ; partially redundant case
718 define void @func28(i32 signext %a) {
719 ; CHECK-LABEL: @func28
720 ; CHECK: cmplwi [[REG1:[0-9]+]], [[REG2:[0-9]+]]
721 ; CHECK: .[[LABEL2:[A-Z0-9_]+]]:
722 ; CHECK: cmpwi [[REG1]], [[REG2]]
723 ; CHECK: ble 0, .[[LABEL1:[A-Z0-9_]+]]
725 ; CHECK: bne 0, .[[LABEL2]]
727 ; CHECK: b .[[LABEL2]]
728 ; CHECK: .[[LABEL1]]:
734 %a.addr.0 = phi i32 [ %a, %entry ], [ %call, %if.end ]
735 %cmp = icmp eq i32 %a.addr.0, 0
736 br i1 %cmp, label %if.then, label %if.end
739 tail call void @dummy1() #2
743 %call = tail call signext i32 @func(i32 signext %a.addr.0) #2
744 %cmp1 = icmp sgt i32 %call, 0
745 br i1 %cmp1, label %do.body, label %do.end
751 define void @func29(i32 signext %a) {
752 ; We cannot merge two compares due to difference in sign extension behaviors.
753 ; equivalent C code example:
755 ; if (a == -1) dummy1();
756 ; if (a == (uint16_t)-1) dummy2();
758 ; CHECK-LABEL: @func29
763 %cmp = icmp eq i32 %a, -1
764 br i1 %cmp, label %if.then, label %if.else
767 tail call void @dummy1()
771 %cmp1 = icmp eq i32 %a, 65535
772 br i1 %cmp1, label %if.then2, label %if.end3
775 tail call void @dummy2()
782 ;; The result of %cmp may change in a tail call. Don't lift %cmp to the entry block.
783 ; CHECK-LABEL: func_tailrecurse:
788 define fastcc zeroext i32 @func_tailrecurse(i32 zeroext %a, i32 zeroext %b) {
790 br label %tailrecurse
792 tailrecurse: ; preds = %tailrecurse, %entry
793 %a.tr = phi i32 [ %a, %entry ], [ %b.tr, %tailrecurse ]
794 %b.tr = phi i32 [ %b, %entry ], [ %a.tr, %tailrecurse ]
795 %cmp = icmp ult i32 %a.tr, %b.tr
796 %conv = zext i1 %cmp to i32
797 %ignore = call signext i32 (i32) @func(i32 %conv)
798 br i1 %cmp, label %tailrecurse, label %if.end
800 if.end: ; preds = %tailrecurse
801 %sub = sub nsw i32 %a.tr, %b.tr
805 declare void @dummy1()
806 declare void @dummy2()
807 declare void @dummy3()
808 declare signext i32 @func(i32 signext)
810 !1 = !{!"branch_weights", i32 2000, i32 1}
811 !2 = !{!"branch_weights", i32 1, i32 2000}