xref: /llvm-project/llvm/test/Analysis/BlockFrequencyInfo/irreducible_pgo.ll (revision 1aee1e1f4c4b504becc06521546de992a662694b)
1; RUN: opt < %s -passes='print<block-freq>' -disable-output 2>&1 | FileCheck %s
2
3; Function Attrs: noinline norecurse nounwind readnone uwtable
4define i32 @_Z11irreducibleii(i32 %iter_outer, i32 %iter_inner) local_unnamed_addr !prof !27 {
5entry:
6  %cmp24 = icmp sgt i32 %iter_outer, 0
7  br i1 %cmp24, label %for.body, label %entry.for.cond.cleanup_crit_edge, !prof !28
8
9entry.for.cond.cleanup_crit_edge:                 ; preds = %entry
10  br label %for.cond.cleanup
11
12for.cond.cleanup:                                 ; preds = %for.end, %entry.for.cond.cleanup_crit_edge
13  %sum.0.lcssa = phi i32 [ 0, %entry.for.cond.cleanup_crit_edge ], [ %sum.1, %for.end ]
14  ret i32 %sum.0.lcssa
15
16for.body:                                         ; preds = %for.end, %entry
17  %k.026 = phi i32 [ %inc12, %for.end ], [ 0, %entry ]
18  %sum.025 = phi i32 [ %sum.1, %for.end ], [ 0, %entry ]
19  %rem23 = and i32 %k.026, 1
20  %cmp1 = icmp eq i32 %rem23, 0
21  br i1 %cmp1, label %entry8, label %for.cond2, !prof !29
22
23for.cond2:                                        ; preds = %if.end9, %for.body
24  %sum.1 = phi i32 [ %add10, %if.end9 ], [ %sum.025, %for.body ]
25  %i.0 = phi i32 [ %inc, %if.end9 ], [ 0, %for.body ]
26  %cmp3 = icmp slt i32 %i.0, %iter_inner
27  br i1 %cmp3, label %for.body4, label %for.end, !prof !30, !irr_loop !31
28
29for.body4:                                        ; preds = %for.cond2
30  %rem5 = srem i32 %k.026, 3
31  %cmp6 = icmp eq i32 %rem5, 0
32  br i1 %cmp6, label %entry8, label %if.end9, !prof !32
33
34entry8:                                           ; preds = %for.body4, %for.body
35  %sum.2 = phi i32 [ %sum.025, %for.body ], [ %sum.1, %for.body4 ]
36  %i.1 = phi i32 [ 0, %for.body ], [ %i.0, %for.body4 ]
37  %add = add nsw i32 %sum.2, 4
38  br label %if.end9, !irr_loop !33
39
40if.end9:                                          ; preds = %entry8, %for.body4
41  %sum.3 = phi i32 [ %add, %entry8 ], [ %sum.1, %for.body4 ]
42  %i.2 = phi i32 [ %i.1, %entry8 ], [ %i.0, %for.body4 ]
43  %add10 = add nsw i32 %sum.3, 1
44  %inc = add nsw i32 %i.2, 1
45  br label %for.cond2, !irr_loop !34
46
47for.end:                                          ; preds = %for.cond2
48  %inc12 = add nuw nsw i32 %k.026, 1
49  %exitcond = icmp eq i32 %inc12, %iter_outer
50  br i1 %exitcond, label %for.cond.cleanup, label %for.body, !prof !35
51}
52
53!27 = !{!"function_entry_count", i64 1}
54!28 = !{!"branch_weights", i32 1, i32 0}
55!29 = !{!"branch_weights", i32 50, i32 50}
56!30 = !{!"branch_weights", i32 950, i32 100}
57!31 = !{!"loop_header_weight", i64 1050}
58!32 = !{!"branch_weights", i32 323, i32 627}
59!33 = !{!"loop_header_weight", i64 373}
60!34 = !{!"loop_header_weight", i64 1000}
61!35 = !{!"branch_weights", i32 1, i32 99}
62
63; CHECK-LABEL: Printing analysis {{.*}} for function '_Z11irreducibleii':
64; CHECK-NEXT: block-frequency-info: _Z11irreducibleii
65; CHECK-NEXT: - entry: {{.*}} count = 1
66; CHECK-NEXT: - entry.for.cond.cleanup_crit_edge: {{.*}} count = 0
67; CHECK-NEXT: - for.cond.cleanup: {{.*}} count = 1
68; CHECK-NEXT: - for.body: {{.*}} count = 100
69; CHECK-NEXT: - for.cond2: {{.*}} count = 1050, irr_loop_header_weight = 1050
70; CHECK-NEXT: - for.body4: {{.*}} count = 950
71; CHECK-NEXT: - entry8: {{.*}} count = 373, irr_loop_header_weight = 373
72; CHECK-NEXT: - if.end9: {{.*}} count = 1000, irr_loop_header_weight = 1000
73; CHECK-NEXT: - for.end: {{.*}} count = 100
74
75@targets = local_unnamed_addr global [256 x ptr] zeroinitializer, align 16
76@tracing = local_unnamed_addr global i32 0, align 4
77
78; Function Attrs: noinline norecurse nounwind uwtable
79define i32 @_Z11irreduciblePh(ptr nocapture readonly %p) !prof !27 {
80entry:
81  %0 = load i32, ptr @tracing, align 4
82  %1 = trunc i32 %0 to i8
83  %tobool = icmp eq i32 %0, 0
84  br label %for.cond1
85
86for.cond1:                                        ; preds = %sw.default, %entry
87  br label %dispatch_op
88
89dispatch_op:                                      ; preds = %sw.bb6, %for.cond1
90  switch i8 %1, label %sw.default [
91    i8 0, label %sw.bb
92    i8 1, label %dispatch_op.sw.bb6_crit_edge
93    i8 2, label %sw.bb15
94  ], !prof !36
95
96dispatch_op.sw.bb6_crit_edge:                     ; preds = %dispatch_op
97  br label %sw.bb6
98
99sw.bb:                                            ; preds = %indirectgoto, %dispatch_op
100  br label %exit
101
102TARGET_1:                                         ; preds = %indirectgoto
103  br label %sw.bb6
104
105sw.bb6:                                           ; preds = %TARGET_1, %dispatch_op.sw.bb6_crit_edge
106  br i1 %tobool, label %dispatch_op, label %if.then, !prof !37, !irr_loop !38
107
108if.then:                                          ; preds = %sw.bb6
109  br label %indirectgoto
110
111TARGET_2:                                         ; preds = %indirectgoto
112  br label %sw.bb15
113
114sw.bb15:                                          ; preds = %TARGET_2, %dispatch_op
115  br i1 %tobool, label %if.then18, label %exit, !prof !39, !irr_loop !40
116
117if.then18:                                        ; preds = %sw.bb15
118  br label %indirectgoto
119
120unknown_op:                                       ; preds = %indirectgoto
121  br label %sw.default
122
123sw.default:                                       ; preds = %unknown_op, %dispatch_op
124  br label %for.cond1
125
126exit:                                             ; preds = %sw.bb15, %sw.bb
127  ret i32 0
128
129indirectgoto:                                     ; preds = %if.then18, %if.then
130  %idxprom21 = zext i32 %0 to i64
131  %arrayidx22 = getelementptr inbounds [256 x ptr], ptr @targets, i64 0, i64 %idxprom21
132  %target = load ptr, ptr %arrayidx22, align 8
133  indirectbr ptr %target, [label %unknown_op, label %sw.bb, label %TARGET_1, label %TARGET_2], !prof !41, !irr_loop !42
134}
135
136!36 = !{!"branch_weights", i32 0, i32 0, i32 201, i32 1}
137!37 = !{!"branch_weights", i32 201, i32 300}
138!38 = !{!"loop_header_weight", i64 501}
139!39 = !{!"branch_weights", i32 100, i32 0}
140!40 = !{!"loop_header_weight", i64 100}
141!41 = !{!"branch_weights", i32 0, i32 1, i32 300, i32 99}
142!42 = !{!"loop_header_weight", i64 400}
143
144; CHECK-LABEL: Printing analysis {{.*}} for function '_Z11irreduciblePh':
145; CHECK-NEXT: block-frequency-info: _Z11irreduciblePh
146; CHECK-NEXT: - entry: {{.*}} count = 1
147; CHECK-NEXT: - for.cond1: {{.*}} count = 1
148; CHECK-NEXT: - dispatch_op: {{.*}} count = 202
149; CHECK-NEXT: - dispatch_op.sw.bb6_crit_edge: {{.*}} count = 201
150; CHECK-NEXT: - sw.bb: {{.*}} count = 1
151; CHECK-NEXT: - TARGET_1: {{.*}} count = 300
152; CHECK-NEXT: - sw.bb6: {{.*}} count = 501, irr_loop_header_weight = 501
153; CHECK-NEXT: - if.then: {{.*}} count = 300
154; CHECK-NEXT: - TARGET_2: {{.*}} count = 99
155; CHECK-NEXT: - sw.bb15: {{.*}} count = 100, irr_loop_header_weight = 100
156; CHECK-NEXT: - if.then18: {{.*}} count = 100
157; CHECK-NEXT: - unknown_op: {{.*}} count = 0
158; CHECK-NEXT: - sw.default: {{.*}} count = 0
159; CHECK-NEXT: - exit: {{.*}} count = 1
160; CHECK-NEXT: - indirectgoto: {{.*}} count = 400, irr_loop_header_weight = 400
161
162; Missing some irr loop annotations.
163; Function Attrs: noinline norecurse nounwind uwtable
164define i32 @_Z11irreduciblePh2(ptr nocapture readonly %p) !prof !27 {
165entry:
166  %0 = load i32, ptr @tracing, align 4
167  %1 = trunc i32 %0 to i8
168  %tobool = icmp eq i32 %0, 0
169  br label %for.cond1
170
171for.cond1:                                        ; preds = %sw.default, %entry
172  br label %dispatch_op
173
174dispatch_op:                                      ; preds = %sw.bb6, %for.cond1
175switch i8 %1, label %sw.default [
176    i8 0, label %sw.bb
177    i8 1, label %dispatch_op.sw.bb6_crit_edge
178    i8 2, label %sw.bb15
179  ], !prof !36
180
181dispatch_op.sw.bb6_crit_edge:                     ; preds = %dispatch_op
182  br label %sw.bb6
183
184sw.bb:                                            ; preds = %indirectgoto, %dispatch_op
185  br label %exit
186
187TARGET_1:                                         ; preds = %indirectgoto
188  br label %sw.bb6
189
190sw.bb6:                                           ; preds = %TARGET_1, %dispatch_op.sw.bb6_crit_edge
191  br i1 %tobool, label %dispatch_op, label %if.then, !prof !37  ; Missing !irr_loop !38
192
193if.then:                                          ; preds = %sw.bb6
194  br label %indirectgoto
195
196TARGET_2:                                         ; preds = %indirectgoto
197  br label %sw.bb15
198
199sw.bb15:                                          ; preds = %TARGET_2, %dispatch_op
200  br i1 %tobool, label %if.then18, label %exit, !prof !39, !irr_loop !40
201
202if.then18:                                        ; preds = %sw.bb15
203  br label %indirectgoto
204
205unknown_op:                                       ; preds = %indirectgoto
206  br label %sw.default
207
208sw.default:                                       ; preds = %unknown_op, %dispatch_op
209  br label %for.cond1
210
211exit:                                             ; preds = %sw.bb15, %sw.bb
212  ret i32 0
213
214indirectgoto:                                     ; preds = %if.then18, %if.then
215  %idxprom21 = zext i32 %0 to i64
216  %arrayidx22 = getelementptr inbounds [256 x ptr], ptr @targets, i64 0, i64 %idxprom21
217  %target = load ptr, ptr %arrayidx22, align 8
218  indirectbr ptr %target, [label %unknown_op, label %sw.bb, label %TARGET_1, label %TARGET_2], !prof !41, !irr_loop !42
219}
220
221; CHECK-LABEL: Printing analysis {{.*}} for function '_Z11irreduciblePh2':
222; CHECK: block-frequency-info: _Z11irreduciblePh2
223; CHECK: - sw.bb6: {{.*}} count = 100
224; CHECK: - sw.bb15: {{.*}} count = 100, irr_loop_header_weight = 100
225; CHECK: - indirectgoto: {{.*}} count = 400, irr_loop_header_weight = 400
226