1 ; RUN: llc -O2 -o - %s | FileCheck %s
2 target datalayout = "e-m:e-i64:64-n32:64"
3 target triple = "powerpc64le-grtev4-linux-gnu"
6 ; The code for tail-duplication during layout will produce the layout:
9 ; body1 (with copy of test2)
13 ;CHECK-LABEL: tail_dup_break_cfg:
14 ;CHECK: mr [[TAGREG:[0-9]+]], 3
15 ;CHECK: andi. {{[0-9]+}}, [[TAGREG]], 1
16 ;CHECK-NEXT: bc 12, 1, [[BODY1LABEL:[._0-9A-Za-z]+]]
18 ;CHECK-NEXT: andi. {{[0-9]+}}, [[TAGREG]], 2
19 ;CHECK-NEXT: bne 0, [[BODY2LABEL:[._0-9A-Za-z]+]]
20 ;CHECK: [[EXITLABEL:[._0-9A-Za-z]+]]: # %exit
22 ;CHECK-NEXT: [[BODY1LABEL]]
23 ;CHECK: andi. {{[0-9]+}}, [[TAGREG]], 2
24 ;CHECK-NEXT: beq 0, [[EXITLABEL]]
25 ;CHECK-NEXT: [[BODY2LABEL:[._0-9A-Za-z]+]]:
26 ;CHECK: b [[EXITLABEL]]
27 define void @tail_dup_break_cfg(i32 %tag) {
31 %tagbit1 = and i32 %tag, 1
32 %tagbit1eq0 = icmp eq i32 %tagbit1, 0
33 br i1 %tagbit1eq0, label %test2, label %body1, !prof !1 ; %test2 more likely
41 %tagbit2 = and i32 %tag, 2
42 %tagbit2eq0 = icmp eq i32 %tagbit2, 0
43 br i1 %tagbit2eq0, label %exit, label %body2, !prof !1 ; %exit more likely
54 ; The branch weights here hint that we shouldn't tail duplicate in this case.
55 ;CHECK-LABEL: tail_dup_dont_break_cfg:
56 ;CHECK: mr [[TAGREG:[0-9]+]], 3
57 ;CHECK: andi. {{[0-9]+}}, [[TAGREG]], 1
58 ;CHECK-NEXT: bc 4, 1, [[TEST2LABEL:[._0-9A-Za-z]+]]
60 ;CHECK: [[TEST2LABEL]]: # %test2
61 ;CHECK-NEXT: andi. {{[0-9]+}}, [[TAGREG]], 2
62 ;CHECK-NEXT: beq 0, [[EXITLABEL:[._0-9A-Za-z]+]]
64 ;CHECK: [[EXITLABEL:[._0-9A-Za-z]+]]: # %exit
66 define void @tail_dup_dont_break_cfg(i32 %tag) {
70 %tagbit1 = and i32 %tag, 1
71 %tagbit1eq0 = icmp eq i32 %tagbit1, 0
72 br i1 %tagbit1eq0, label %test2, label %body1, !prof !1 ; %test2 more likely
80 %tagbit2 = and i32 %tag, 2
81 %tagbit2eq0 = icmp ne i32 %tagbit2, 0
82 br i1 %tagbit2eq0, label %body2, label %exit, !prof !3 ; %body2 more likely
97 ; This function arranges for the successors of %succ to have already been laid
98 ; out. When we consider whether to lay out succ after bb and to tail-duplicate
99 ; it, v and ret have already been placed, so we tail-duplicate as it removes a
100 ; branch and strictly increases fallthrough
101 ; CHECK-LABEL: tail_dup_no_succ
109 ; CHECK: andi. {{[0-9]+}}, {{[0-9]+}}, 4
112 define void @tail_dup_no_succ(i32 %tag) {
114 %tagbit1 = and i32 %tag, 1
115 %tagbit1eq0 = icmp eq i32 %tagbit1, 0
116 br i1 %tagbit1eq0, label %v, label %bb, !prof !2 ; %v very much more likely
118 %tagbit2 = and i32 %tag, 2
119 %tagbit2eq0 = icmp eq i32 %tagbit2, 0
120 br i1 %tagbit2eq0, label %succ, label %c, !prof !3 ; %succ more likely
126 %tagbit3 = and i32 %tag, 4
127 %tagbit3eq0 = icmp eq i32 %tagbit3, 0
128 br i1 %tagbit3eq0, label %ret, label %v, !prof !1 ; %u more likely
138 !1 = !{!"branch_weights", i32 5, i32 3}
139 !2 = !{!"branch_weights", i32 95, i32 5}
140 !3 = !{!"branch_weights", i32 8, i32 3}