1 ; RUN: llvm-profdata merge --sample -profile-isfs -o %t0.afdo %S/Inputs/fsloader.afdo
2 ; RUN: llc -enable-fs-discriminator -improved-fs-discriminator=false -fs-profile-file=%t0.afdo -disable-ra-fsprofile-loader=false -disable-layout-fsprofile-loader=false -print-machine-bfi -print-bfi-func-name=foo -print-before=fs-profile-loader -stop-after=fs-profile-loader < %s 2>&1 | FileCheck %s --check-prefixes=BFI,BFIV0
3 ; RUN: llvm-profdata merge --sample -profile-isfs -o %t1.afdo %S/Inputs/fsloader_v1.afdo
4 ; RUN: llc -enable-fs-discriminator -improved-fs-discriminator=true -fs-profile-file=%t1.afdo -disable-ra-fsprofile-loader=false -disable-layout-fsprofile-loader=false -print-machine-bfi -print-bfi-func-name=foo -print-before=fs-profile-loader -stop-after=fs-profile-loader < %s 2>&1 | FileCheck %s --check-prefixes=BFI,BFIV1
7 ;; C source code for the test (compiler at -O3):
8 ;; // A test case for loop unroll.
10 ;; __attribute__((noinline)) int bar(int i){
17 ;; __attribute__((noinline)) void work(int i){
24 ;; __attribute__((noinline)) void foo(){
26 ;; for (j = 0; j < 48; j++)
27 ;; for (i = 0; i < 4; i++) {
28 ;; int ii = bar(i+j*48);
38 ;; for (i = 0; i < 10000000; i++) {
43 ;; Check BFI before and after
45 ; BFI: block-frequency-info: foo
46 ; BFI: - BB0[entry]: float = 1.0, int = {{.*}}, count = 4268
47 ; BFI: - BB1[for.cond1.preheader]: float = 59.967, int = {{.*}}, count = 255941
48 ; BFI: - BB2[if.then]: float = 2.5405, int = {{.*}}, count = 10843
49 ; BFI: - BB3[if.end]: float = 59.967, int = {{.*}}, count = 255941
50 ; BFI: - BB4[if.then7]: float = 2.5405, int = {{.*}}, count = 10843
51 ; BFI: - BB5[if.end9]: float = 59.967, int = {{.*}}, count = 255941
52 ; BFI: - BB6[if.then.1]: float = 2.5405, int = {{.*}}, count = 10843
53 ; BFI: - BB7[if.end.1]: float = 59.967, int = {{.*}}, count = 255941
54 ; BFI: - BB8[if.then7.1]: float = 2.5405, int = {{.*}}, count = 10843
55 ; BFI: - BB9[if.end9.1]: float = 59.967, int = {{.*}}, count = 255941
56 ; BFI: - BB10[if.then.2]: float = 2.5405, int = {{.*}}, count = 10843
57 ; BFI: - BB11[if.end.2]: float = 59.967, int = {{.*}}, count = 255941
58 ; BFI: - BB12[if.then7.2]: float = 2.5405, int = {{.*}}, count = 10843
59 ; BFI: - BB13[if.end9.2]: float = 59.967, int = {{.*}}, count = 255941
60 ; BFI: - BB14[if.then.3]: float = 2.5405, int = {{.*}}, count = 10843
61 ; BFI: - BB15[if.end.3]: float = 59.967, int = {{.*}}, count = 255941
62 ; BFI: - BB16[if.then7.3]: float = 2.5405, int = {{.*}}, count = 10843
63 ; BFI: - BB17[if.end9.3]: float = 59.967, int = {{.*}}, count = 255941
64 ; BFI: - BB18[for.end12]: float = 1.0, int = {{.*}}, count = 4268
66 ; BFI: # *** IR Dump Before SampleFDO loader in MIR (fs-profile-loader) ***:
67 ; BFI: # End machine code for function foo.
69 ; BFI: block-frequency-info: foo
70 ; BFI: - BB0[entry]: float = 1.0, int = {{.*}}, count = 4268
71 ; BFI: - BB1[for.cond1.preheader]: float = 66.446, int = {{.*}}, count = 283590
72 ; BFI: - BB2[if.then]: float = 2.7041, int = {{.*}}, count = 11541
73 ; BFI: - BB3[if.end]: float = 66.446, int = {{.*}}, count = 283590
74 ; BFI: - BB4[if.then7]: float = 2.7041, int = {{.*}}, count = 11541
75 ; BFI: - BB5[if.end9]: float = 66.446, int = {{.*}}, count = 283590
76 ; BFI: - BB6[if.then.1]: float = 65.351, int = {{.*}}, count = 278916
77 ; BFI: - BB7[if.end.1]: float = 66.446, int = {{.*}}, count = 283590
78 ; BFI: - BB8[if.then7.1]: float = 66.446, int = {{.*}}, count = 283590
79 ; BFI: - BB9[if.end9.1]: float = 66.446, int = {{.*}}, count = 283590
80 ; BFIV0: - BB10[if.then.2]: float = 2.7041, int = {{.*}}, count = 11541
81 ; BFIV1: - BB10[if.then.2]: float = 61.075, int = {{.*}}, count = 260670
82 ; BFI: - BB11[if.end.2]: float = 66.446, int = {{.*}}, count = 283590
83 ; BFI: - BB12[if.then7.2]: float = 65.405, int = {{.*}}, count = 279149
84 ; BFI: - BB13[if.end9.2]: float = 66.446, int = {{.*}}, count = 283590
85 ; BFIV0: - BB14[if.then.3]: float = 61.075, int = {{.*}}, count = 260670
86 ; BFIV1: - BB14[if.then.3]: float = 2.7041, int = {{.*}}, count = 11541
87 ; BFI: - BB15[if.end.3]: float = 66.446, int = {{.*}}, count = 283590
88 ; BFI: - BB16[if.then7.3]: float = 54.846, int = {{.*}}, count = 234082
89 ; BFI: - BB17[if.end9.3]: float = 66.446, int = {{.*}}, count = 283590
90 ; BFI: - BB18[for.end12]: float = 1.0, int = {{.*}}, count = 4268
92 target triple = "x86_64-unknown-linux-gnu"
94 @sum = dso_local local_unnamed_addr global i32 0, align 4
96 declare i32 @bar(i32 %i) #0
97 declare void @work(i32 %i) #2
98 declare i32 @main() #3
100 define dso_local void @foo() local_unnamed_addr #0 !dbg !61 !prof !62 {
102 br label %for.cond1.preheader, !dbg !63
105 %j.024 = phi i32 [ 0, %entry ], [ %inc11, %if.end9.3 ]
106 %mul = mul nuw nsw i32 %j.024, 48
107 %call = tail call i32 @bar(i32 %mul), !dbg !65, !prof !66
108 %0 = and i32 %call, 1, !dbg !67
109 %tobool.not = icmp eq i32 %0, 0, !dbg !67
110 br i1 %tobool.not, label %if.end, label %if.then, !dbg !68, !prof !69
113 %mul4 = shl nsw i32 %call, 1, !dbg !70
114 tail call void @work(i32 %mul4), !dbg !71, !prof !72
115 br label %if.end, !dbg !71
118 %1 = and i32 %call, 3, !dbg !73
119 %tobool6.not = icmp eq i32 %1, 0, !dbg !73
120 br i1 %tobool6.not, label %if.end9, label %if.then7, !dbg !74, !prof !69
123 %mul8 = mul nsw i32 %call, 3, !dbg !75
124 tail call void @work(i32 %mul8), !dbg !76, !prof !72
125 br label %if.end9, !dbg !76
128 %add.1 = or i32 %mul, 1, !dbg !77
129 %call.1 = tail call i32 @bar(i32 %add.1), !dbg !65, !prof !66
130 %2 = and i32 %call.1, 1, !dbg !67
131 %tobool.not.1 = icmp eq i32 %2, 0, !dbg !67
132 br i1 %tobool.not.1, label %if.end.1, label %if.then.1, !dbg !68, !prof !69
135 %mul4.1 = shl nsw i32 %call.1, 1, !dbg !70
136 tail call void @work(i32 %mul4.1), !dbg !71, !prof !72
137 br label %if.end.1, !dbg !71
140 %3 = and i32 %call.1, 3, !dbg !73
141 %tobool6.not.1 = icmp eq i32 %3, 0, !dbg !73
142 br i1 %tobool6.not.1, label %if.end9.1, label %if.then7.1, !dbg !74, !prof !69
145 %mul8.1 = mul nsw i32 %call.1, 3, !dbg !75
146 tail call void @work(i32 %mul8.1), !dbg !76, !prof !72
147 br label %if.end9.1, !dbg !76
150 %add.2 = or i32 %mul, 2, !dbg !77
151 %call.2 = tail call i32 @bar(i32 %add.2), !dbg !65, !prof !66
152 %4 = and i32 %call.2, 1, !dbg !67
153 %tobool.not.2 = icmp eq i32 %4, 0, !dbg !67
154 br i1 %tobool.not.2, label %if.end.2, label %if.then.2, !dbg !68, !prof !69
157 %mul4.2 = shl nsw i32 %call.2, 1, !dbg !70
158 tail call void @work(i32 %mul4.2), !dbg !71, !prof !72
159 br label %if.end.2, !dbg !71
162 %5 = and i32 %call.2, 3, !dbg !73
163 %tobool6.not.2 = icmp eq i32 %5, 0, !dbg !73
164 br i1 %tobool6.not.2, label %if.end9.2, label %if.then7.2, !dbg !74, !prof !69
167 %mul8.2 = mul nsw i32 %call.2, 3, !dbg !75
168 tail call void @work(i32 %mul8.2), !dbg !76, !prof !72
169 br label %if.end9.2, !dbg !76
172 %add.3 = or i32 %mul, 3, !dbg !77
173 %call.3 = tail call i32 @bar(i32 %add.3), !dbg !65, !prof !66
174 %6 = and i32 %call.3, 1, !dbg !67
175 %tobool.not.3 = icmp eq i32 %6, 0, !dbg !67
176 br i1 %tobool.not.3, label %if.end.3, label %if.then.3, !dbg !68, !prof !69
179 %mul4.3 = shl nsw i32 %call.3, 1, !dbg !70
180 tail call void @work(i32 %mul4.3), !dbg !71, !prof !72
181 br label %if.end.3, !dbg !71
184 %7 = and i32 %call.3, 3, !dbg !73
185 %tobool6.not.3 = icmp eq i32 %7, 0, !dbg !73
186 br i1 %tobool6.not.3, label %if.end9.3, label %if.then7.3, !dbg !74, !prof !69
189 %mul8.3 = mul nsw i32 %call.3, 3, !dbg !75
190 tail call void @work(i32 %mul8.3), !dbg !76, !prof !72
191 br label %if.end9.3, !dbg !76
194 %inc11 = add nuw nsw i32 %j.024, 1, !dbg !78
195 %exitcond.not = icmp eq i32 %inc11, 48, !dbg !80
196 br i1 %exitcond.not, label %for.end12, label %for.cond1.preheader, !dbg !63, !prof !81, !llvm.loop !82
202 attributes #0 = { nofree noinline nounwind uwtable "frame-pointer"="none" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" "use-sample-profile" }
203 attributes #1 = { argmemonly mustprogress nofree nosync nounwind willreturn }
204 attributes #2 = { mustprogress nofree noinline norecurse nosync nounwind uwtable willreturn "frame-pointer"="none" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" "use-sample-profile" }
205 attributes #3 = { nofree nounwind uwtable "frame-pointer"="none" "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" "use-sample-profile" }
208 !llvm.module.flags = !{!2, !3, !4, !5, !6, !35}
211 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, producer: "clang version 14.0.0 (https://github.com/llvm/llvm-project.git 755f5e23159796d727c3d95d60894a52eb675b1b)", isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, splitDebugInlining: false, debugInfoForProfiling: true, nameTableKind: None)
212 !1 = !DIFile(filename: "/tmp/aaa.c", directory: "/mnt/ssd/xur/llvm_dev/gitwork/llvm-project/rel")
213 !2 = !{i32 7, !"Dwarf Version", i32 4}
214 !3 = !{i32 2, !"Debug Info Version", i32 3}
215 !4 = !{i32 1, !"wchar_size", i32 4}
216 !5 = !{i32 7, !"uwtable", i32 1}
217 !6 = !{i32 1, !"ProfileSummary", !7}
218 !7 = !{!8, !9, !10, !11, !12, !13, !14, !15, !16, !17}
219 !8 = !{!"ProfileFormat", !"SampleProfile"}
220 !9 = !{!"TotalCount", i64 9484871}
221 !10 = !{!"MaxCount", i64 1246499}
222 !11 = !{!"MaxInternalCount", i64 0}
223 !12 = !{!"MaxFunctionCount", i64 1346190}
224 !13 = !{!"NumCounts", i64 31}
225 !14 = !{!"NumFunctions", i64 4}
226 !15 = !{!"IsPartialProfile", i64 0}
227 !16 = !{!"PartialProfileRatio", double 0.000000e+00}
228 !17 = !{!"DetailedSummary", !18}
229 !18 = !{!19, !20, !21, !22, !23, !24, !25, !26, !27, !28, !29, !30, !31, !32, !33, !34}
230 !19 = !{i32 10000, i64 1246499, i32 2}
231 !20 = !{i32 100000, i64 1246499, i32 2}
232 !21 = !{i32 200000, i64 1246499, i32 2}
233 !22 = !{i32 300000, i64 1056020, i32 4}
234 !23 = !{i32 400000, i64 1056020, i32 4}
235 !24 = !{i32 500000, i64 283590, i32 6}
236 !25 = !{i32 600000, i64 279149, i32 9}
237 !26 = !{i32 700000, i64 278916, i32 12}
238 !27 = !{i32 800000, i64 269485, i32 15}
239 !28 = !{i32 900000, i64 260670, i32 19}
240 !29 = !{i32 950000, i64 234082, i32 22}
241 !30 = !{i32 990000, i64 234082, i32 22}
242 !31 = !{i32 999000, i64 4156, i32 27}
243 !32 = !{i32 999900, i64 4045, i32 29}
244 !33 = !{i32 999990, i64 4045, i32 29}
245 !34 = !{i32 999999, i64 4045, i32 29}
246 !35 = !{i32 5, !"CG Profile", !36}
247 !36 = !{!37, !38, !39}
248 !37 = !{ptr @foo, ptr @bar, i64 1022188}
249 !38 = !{ptr @foo, ptr @work, i64 85360}
250 !39 = !{ptr @main, ptr @foo, i64 2080}
251 !40 = !{!"clang version 14.0.0 (https://github.com/llvm/llvm-project.git 755f5e23159796d727c3d95d60894a52eb675b1b)"}
252 !41 = distinct !DISubprogram(name: "bar", scope: !42, file: !42, line: 3, type: !43, scopeLine: 3, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !44)
253 !42 = !DIFile(filename: "/tmp/aaa.c", directory: "")
254 !43 = !DISubroutineType(types: !44)
256 !45 = !{!"function_entry_count", i64 1076806}
257 !46 = !DILocation(line: 4, column: 3, scope: !41)
258 !47 = !DILocation(line: 5, column: 5, scope: !41)
259 !48 = !{!49, !49, i64 0}
260 !49 = !{!"int", !50, i64 0}
261 !50 = !{!"omnipotent char", !51, i64 0}
262 !51 = !{!"Simple C/C++ TBAA"}
263 !52 = !DILocation(line: 6, column: 10, scope: !41)
264 !53 = !DILocation(line: 7, column: 1, scope: !41)
265 !54 = !DILocation(line: 6, column: 3, scope: !41)
266 !55 = distinct !DISubprogram(name: "work", scope: !42, file: !42, line: 10, type: !43, scopeLine: 10, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !44)
267 !56 = !{!"function_entry_count", i64 1346191}
268 !57 = !DILocation(line: 11, column: 7, scope: !55)
269 !58 = !DILocation(line: 11, column: 11, scope: !55)
270 !59 = !DILocation(line: 0, scope: !55)
271 !60 = !DILocation(line: 15, column: 1, scope: !55)
272 !61 = distinct !DISubprogram(name: "foo", scope: !42, file: !42, line: 17, type: !43, scopeLine: 17, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !44)
273 !62 = !{!"function_entry_count", i64 4268}
274 !63 = !DILocation(line: 19, column: 3, scope: !64)
275 !64 = !DILexicalBlockFile(scope: !61, file: !42, discriminator: 1)
276 !65 = !DILocation(line: 21, column: 16, scope: !61)
277 !66 = !{!"branch_weights", i32 272442}
278 !67 = !DILocation(line: 22, column: 14, scope: !61)
279 !68 = !DILocation(line: 22, column: 11, scope: !61)
280 !69 = !{!"branch_weights", i32 260902, i32 11542}
281 !70 = !DILocation(line: 23, column: 16, scope: !61)
282 !71 = !DILocation(line: 23, column: 9, scope: !61)
283 !72 = !{!"branch_weights", i32 11541}
284 !73 = !DILocation(line: 24, column: 14, scope: !61)
285 !74 = !DILocation(line: 24, column: 11, scope: !61)
286 !75 = !DILocation(line: 25, column: 16, scope: !61)
287 !76 = !DILocation(line: 25, column: 9, scope: !61)
288 !77 = !DILocation(line: 21, column: 21, scope: !61)
289 !78 = !DILocation(line: 19, column: 24, scope: !79)
290 !79 = !DILexicalBlockFile(scope: !61, file: !42, discriminator: 2)
291 !80 = !DILocation(line: 19, column: 17, scope: !64)
292 !81 = !{!"branch_weights", i32 4269, i32 251732}
293 !82 = distinct !{!82, !83, !84, !85}
294 !83 = !DILocation(line: 19, column: 3, scope: !61)
295 !84 = !DILocation(line: 26, column: 3, scope: !61)
296 !85 = !{!"llvm.loop.mustprogress"}
297 !86 = !DILocation(line: 27, column: 1, scope: !61)
298 !87 = distinct !DISubprogram(name: "main", scope: !42, file: !42, line: 29, type: !43, scopeLine: 29, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !44)
299 !88 = !{!"function_entry_count", i64 1}
300 !89 = !DILocation(line: 31, column: 3, scope: !90)
301 !90 = !DILexicalBlockFile(scope: !87, file: !42, discriminator: 1)
302 !91 = !DILocation(line: 32, column: 5, scope: !87)
303 !92 = !{!"branch_weights", i32 4156}
304 !93 = !DILocation(line: 31, column: 30, scope: !94)
305 !94 = !DILexicalBlockFile(scope: !87, file: !42, discriminator: 2)
306 !95 = !DILocation(line: 31, column: 17, scope: !90)
307 !96 = !{!"branch_weights", i32 2, i32 4157}
308 !97 = distinct !{!97, !98, !99, !85}
309 !98 = !DILocation(line: 31, column: 3, scope: !87)
310 !99 = !DILocation(line: 33, column: 3, scope: !87)
311 !100 = !DILocation(line: 34, column: 1, scope: !87)