1 ; RUN: opt < %s -passes='print<block-freq>' -disable-output 2>&1 | FileCheck %s
3 ; CHECK-LABEL: Printing analysis {{.*}} for function 'double_exit':
4 ; CHECK-NEXT: block-frequency-info: double_exit
5 define i32 @double_exit(i32 %N) {
8 ; CHECK-NEXT: entry: float = 1.0, int = [[ENTRY:[0-9]+]]
13 ; Backedge mass = 1/3, exit mass = 2/3
17 ; Frequency = 1*3/2*1 = 3/2
18 ; CHECK-NEXT: outer: float = 1.5,
20 %I.0 = phi i32 [ 0, %entry ], [ %inc6, %outer.inc ]
21 %Return.0 = phi i32 [ 0, %entry ], [ %Return.1, %outer.inc ]
22 %cmp = icmp slt i32 %I.0, %N
23 br i1 %cmp, label %inner, label %exit, !prof !2 ; 2:1
26 ; Backedge mass = 3/5, exit mass = 2/5
28 ; Pseudo-edges = outer.inc @ 1/5, exit @ 1/5
30 ; Frequency = 3/2*1*5/2*2/3 = 5/2
31 ; CHECK-NEXT: inner: float = 2.5,
33 %Return.1 = phi i32 [ %Return.0, %outer ], [ %call4, %inner.inc ]
34 %J.0 = phi i32 [ %I.0, %outer ], [ %inc, %inner.inc ]
35 %cmp2 = icmp slt i32 %J.0, %N
36 br i1 %cmp2, label %inner.body, label %outer.inc, !prof !1 ; 4:1
39 ; Frequency = 5/2*4/5 = 2
40 ; CHECK-NEXT: inner.body: float = 2.0,
42 %call = call i32 @c2(i32 %I.0, i32 %J.0)
43 %tobool = icmp ne i32 %call, 0
44 br i1 %tobool, label %exit, label %inner.inc, !prof !0 ; 3:1
47 ; Frequency = 5/2*3/5 = 3/2
48 ; CHECK-NEXT: inner.inc: float = 1.5,
50 %call4 = call i32 @logic2(i32 %Return.1, i32 %I.0, i32 %J.0)
51 %inc = add nsw i32 %J.0, 1
55 ; Frequency = 3/2*1/3 = 1/2
56 ; CHECK-NEXT: outer.inc: float = 0.5,
58 %inc6 = add nsw i32 %I.0, 1
63 ; CHECK-NEXT: exit: float = 1.0, int = [[ENTRY]]
65 %Return.2 = phi i32 [ %Return.1, %inner.body ], [ %Return.0, %outer ]
69 !0 = !{!"branch_weights", i32 1, i32 3}
70 !1 = !{!"branch_weights", i32 4, i32 1}
71 !2 = !{!"branch_weights", i32 2, i32 1}
73 declare i32 @c2(i32, i32)
74 declare i32 @logic2(i32, i32, i32)
76 ; CHECK-LABEL: Printing analysis {{.*}} for function 'double_exit_in_loop':
77 ; CHECK-NEXT: block-frequency-info: double_exit_in_loop
78 define i32 @double_exit_in_loop(i32 %N) {
81 ; CHECK-NEXT: entry: float = 1.0, int = [[ENTRY:[0-9]+]]
86 ; Backedge mass = 1/2, exit mass = 1/2
90 ; Frequency = 1*2*1 = 2
91 ; CHECK-NEXT: outer: float = 2.0,
93 %I.0 = phi i32 [ 0, %entry ], [ %inc12, %outer.inc ]
94 %Return.0 = phi i32 [ 0, %entry ], [ %Return.3, %outer.inc ]
95 %cmp = icmp slt i32 %I.0, %N
96 br i1 %cmp, label %middle, label %exit, !prof !3 ; 1:1
99 ; Backedge mass = 1/3, exit mass = 2/3
101 ; Pseudo-edges = outer.inc
103 ; Frequency = 2*1*3/2*1/2 = 3/2
104 ; CHECK-NEXT: middle: float = 1.5,
106 %J.0 = phi i32 [ %I.0, %outer ], [ %inc9, %middle.inc ]
107 %Return.1 = phi i32 [ %Return.0, %outer ], [ %Return.2, %middle.inc ]
108 %cmp2 = icmp slt i32 %J.0, %N
109 br i1 %cmp2, label %inner, label %outer.inc, !prof !2 ; 2:1
112 ; Backedge mass = 3/5, exit mass = 2/5
114 ; Pseudo-edges = middle.inc @ 1/5, outer.inc @ 1/5
116 ; Frequency = 3/2*1*5/2*2/3 = 5/2
117 ; CHECK-NEXT: inner: float = 2.5,
119 %Return.2 = phi i32 [ %Return.1, %middle ], [ %call7, %inner.inc ]
120 %K.0 = phi i32 [ %J.0, %middle ], [ %inc, %inner.inc ]
121 %cmp5 = icmp slt i32 %K.0, %N
122 br i1 %cmp5, label %inner.body, label %middle.inc, !prof !1 ; 4:1
125 ; Frequency = 5/2*4/5 = 2
126 ; CHECK-NEXT: inner.body: float = 2.0,
128 %call = call i32 @c3(i32 %I.0, i32 %J.0, i32 %K.0)
129 %tobool = icmp ne i32 %call, 0
130 br i1 %tobool, label %outer.inc, label %inner.inc, !prof !0 ; 3:1
133 ; Frequency = 5/2*3/5 = 3/2
134 ; CHECK-NEXT: inner.inc: float = 1.5,
136 %call7 = call i32 @logic3(i32 %Return.2, i32 %I.0, i32 %J.0, i32 %K.0)
137 %inc = add nsw i32 %K.0, 1
141 ; Frequency = 3/2*1/3 = 1/2
142 ; CHECK-NEXT: middle.inc: float = 0.5,
144 %inc9 = add nsw i32 %J.0, 1
148 ; Frequency = 2*1/2 = 1
149 ; CHECK-NEXT: outer.inc: float = 1.0,
151 %Return.3 = phi i32 [ %Return.2, %inner.body ], [ %Return.1, %middle ]
152 %inc12 = add nsw i32 %I.0, 1
157 ; CHECK-NEXT: exit: float = 1.0, int = [[ENTRY]]
162 !3 = !{!"branch_weights", i32 1, i32 1}
164 declare i32 @c3(i32, i32, i32)
165 declare i32 @logic3(i32, i32, i32, i32)