Debian Codegraph @

llvm/test/Transforms/SampleProfile/pseudo-probe-stale-profile-renaming.ll

raw
1 ; REQUIRES: asserts && x86-registered-target
2 ; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/pseudo-probe-stale-profile-renaming.prof --salvage-stale-profile --salvage-unused-profile -report-profile-staleness -persist-profile-staleness -S --debug-only=sample-profile,sample-profile-matcher,sample-profile-impl -pass-remarks=inline --min-call-count-for-cg-matching=0 --min-func-count-for-cg-matching=0 --func-profile-similarity-threshold=70 2>&1 | FileCheck %s
3 ; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/pseudo-probe-stale-profile-renaming.prof --salvage-stale-profile --salvage-unused-profile -S --debug-only=sample-profile,sample-profile-matcher,sample-profile-impl --min-call-count-for-cg-matching=10 --min-func-count-for-cg-matching=10 2>&1 | FileCheck %s --check-prefix=TINY-FUNC
4
5 ; Verify find new IR functions.
6 ; CHECK: Function new_block_only is not in profile or profile symbol list.
7 ; CHECK: Function new_foo is not in profile or profile symbol list.
8
9 ; CHECK: Run stale profile matching for main
10 ; CHECK: The similarity between new_foo(IR) and foo(profile) is 0.75
11 ; CHECK: Function:new_foo matches profile:foo
12 ; CHECK: Run stale profile matching for cold_func
13 ; CHECK: The checksums for new_block_only(IR) and block_only(Profile) match.
14 ; CHECK: Function:new_block_only matches profile:block_only
15 ; CHECK: Run stale profile matching for test_noninline
16 ; CHECK: Run stale profile matching for baz
17 ; CHECK: Run stale profile matching for bar
18
19 ; CHECK: (2/3) of functions' profile are matched and (55/81) of samples are reused by call graph matching.
20
21 ; Verify the matched function is updated correctly by checking the inlining.
22 ; CHECK: 'new_foo' inlined into 'main' to match profiling context with (cost=110, threshold=3000) at callsite main:2:7.5;
23 ; CHECK: 'new_block_only' inlined into 'main' to match profiling context with (cost=75, threshold=3000) at callsite baz:1:3.2 @ main:3:7.6
24 ; CHECK: 'new_block_only' inlined into 'main' to match profiling context with (cost=75, threshold=3000) at callsite baz:1:3.2 @ new_foo:2:3.3 @ main:2:7.5;
25 ; CHECK: 'new_foo' inlined into 'test_noninline' to match profiling context with (cost=110, threshold=3000) at callsite test_noninline:1:3.2;
26
27 ; CHECK: !"NumCallGraphRecoveredProfiledFunc", i64 2, !"NumCallGraphRecoveredFuncSamples", i64 55
28
29 ; TINY-FUNC-NOT: Function:new_foo matches profile:foo
30 ; TINY-FUNC-NOT: Function:new_block_only matches profile:block_only
31
32
33 @x = dso_local global i32 0, align 4, !dbg !0
34
35 ; Function Attrs: noinline nounwind uwtable
36 define dso_local i32 @bar(i32 noundef %x) #0 !dbg !22 {
37 entry:
38 #dbg_value(i32 %x, !26, !DIExpression(), !27)
39 call void @llvm.pseudoprobe(i64 -2012135647395072713, i64 1, i32 0, i64 -1), !dbg !28
40 %add = add nsw i32 %x, 1, !dbg !29
41 ret i32 %add, !dbg !30
42 }
43
44 ; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)
45 declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
46
47 ; Function Attrs: nounwind uwtable
48 define dso_local void @new_block_only() #2 !dbg !31 {
49 entry:
50 call void @llvm.pseudoprobe(i64 2964250471062803127, i64 1, i32 0, i64 -1), !dbg !34
51 %0 = load volatile i32, ptr @x, align 4, !dbg !34, !tbaa !36
52 %cmp = icmp eq i32 %0, 9999, !dbg !40
53 br i1 %cmp, label %if.then, label %if.else, !dbg !41
54
55 if.then: ; preds = %entry
56 call void @llvm.pseudoprobe(i64 2964250471062803127, i64 2, i32 0, i64 -1), !dbg !42
57 %1 = load volatile i32, ptr @x, align 4, !dbg !42, !tbaa !36
58 %add = add nsw i32 %1, 1000, !dbg !42
59 store volatile i32 %add, ptr @x, align 4, !dbg !42, !tbaa !36
60 br label %if.end10, !dbg !43
61
62 if.else: ; preds = %entry
63 call void @llvm.pseudoprobe(i64 2964250471062803127, i64 3, i32 0, i64 -1), !dbg !44
64 %2 = load volatile i32, ptr @x, align 4, !dbg !44, !tbaa !36
65 %cmp1 = icmp eq i32 %2, 999, !dbg !46
66 br i1 %cmp1, label %if.then2, label %if.else4, !dbg !47
67
68 if.then2: ; preds = %if.else
69 call void @llvm.pseudoprobe(i64 2964250471062803127, i64 4, i32 0, i64 -1), !dbg !48
70 %3 = load volatile i32, ptr @x, align 4, !dbg !48, !tbaa !36
71 %add3 = add nsw i32 %3, 100, !dbg !48
72 store volatile i32 %add3, ptr @x, align 4, !dbg !48, !tbaa !36
73 br label %if.end10, !dbg !49
74
75 if.else4: ; preds = %if.else
76 call void @llvm.pseudoprobe(i64 2964250471062803127, i64 5, i32 0, i64 -1), !dbg !50
77 %4 = load volatile i32, ptr @x, align 4, !dbg !50, !tbaa !36
78 %cmp5 = icmp eq i32 %4, 99, !dbg !52
79 br i1 %cmp5, label %if.then6, label %if.else8, !dbg !53
80
81 if.then6: ; preds = %if.else4
82 call void @llvm.pseudoprobe(i64 2964250471062803127, i64 6, i32 0, i64 -1), !dbg !54
83 %5 = load volatile i32, ptr @x, align 4, !dbg !54, !tbaa !36
84 %add7 = add nsw i32 %5, 10, !dbg !54
85 store volatile i32 %add7, ptr @x, align 4, !dbg !54, !tbaa !36
86 br label %if.end10, !dbg !55
87
88 if.else8: ; preds = %if.else4
89 call void @llvm.pseudoprobe(i64 2964250471062803127, i64 7, i32 0, i64 -1), !dbg !56
90 %6 = load volatile i32, ptr @x, align 4, !dbg !56, !tbaa !36
91 %inc = add nsw i32 %6, 1, !dbg !56
92 store volatile i32 %inc, ptr @x, align 4, !dbg !56, !tbaa !36
93 br label %if.end10
94
95 if.end10: ; preds = %if.then2, %if.else8, %if.then6, %if.then
96 call void @llvm.pseudoprobe(i64 2964250471062803127, i64 10, i32 0, i64 -1), !dbg !57
97 ret void, !dbg !57
98 }
99
100 ; Function Attrs: nounwind uwtable
101 define dso_local void @baz() #2 !dbg !58 {
102 entry:
103 call void @llvm.pseudoprobe(i64 7546896869197086323, i64 1, i32 0, i64 -1), !dbg !59
104 call void @new_block_only(), !dbg !60
105 ret void, !dbg !62
106 }
107
108 ; Function Attrs: nounwind uwtable
109 define dso_local void @new_foo() #2 !dbg !63 {
110 entry:
111 call void @llvm.pseudoprobe(i64 5381804724291869009, i64 1, i32 0, i64 -1), !dbg !64
112 %0 = load volatile i32, ptr @x, align 4, !dbg !64, !tbaa !36
113 %call = call i32 @bar(i32 noundef %0), !dbg !65
114 %1 = load volatile i32, ptr @x, align 4, !dbg !67, !tbaa !36
115 %add = add nsw i32 %1, %call, !dbg !67
116 store volatile i32 %add, ptr @x, align 4, !dbg !67, !tbaa !36
117 call void @baz(), !dbg !68
118 %2 = load volatile i32, ptr @x, align 4, !dbg !70, !tbaa !36
119 %call1 = call i32 @bar(i32 noundef %2), !dbg !71
120 %3 = load volatile i32, ptr @x, align 4, !dbg !73, !tbaa !36
121 %add2 = add nsw i32 %3, %call1, !dbg !73
122 store volatile i32 %add2, ptr @x, align 4, !dbg !73, !tbaa !36
123 ret void, !dbg !74
124 }
125
126 ; Function Attrs: noinline nounwind uwtable
127 define dso_local void @test_noninline() #0 !dbg !75 {
128 entry:
129 call void @llvm.pseudoprobe(i64 -5610330892148506720, i64 1, i32 0, i64 -1), !dbg !76
130 call void @new_foo(), !dbg !77
131 ret void, !dbg !79
132 }
133
134 ; Function Attrs: nounwind uwtable
135 define dso_local void @cold_func() #2 !dbg !80 {
136 entry:
137 call void @llvm.pseudoprobe(i64 2711072140522378707, i64 1, i32 0, i64 -1), !dbg !81
138 call void @new_block_only(), !dbg !82
139 ret void, !dbg !84
140 }
141
142 ; Function Attrs: nounwind uwtable
143 define dso_local i32 @main() #2 !dbg !85 {
144 entry:
145 call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 1, i32 0, i64 -1), !dbg !91
146 #dbg_value(i32 0, !89, !DIExpression(), !92)
147 br label %for.cond, !dbg !93
148
149 for.cond: ; preds = %for.body, %entry
150 %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.body ], !dbg !94
151 #dbg_value(i32 %i.0, !89, !DIExpression(), !92)
152 call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 2, i32 0, i64 -1), !dbg !95
153 %cmp = icmp slt i32 %i.0, 1000000, !dbg !97
154 br i1 %cmp, label %for.body, label %for.cond.cleanup, !dbg !98
155
156 for.cond.cleanup: ; preds = %for.cond
157 call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 3, i32 0, i64 -1), !dbg !99
158 call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 9, i32 0, i64 -1), !dbg !100
159 call void @cold_func(), !dbg !101
160 ret i32 0, !dbg !103
161
162 for.body: ; preds = %for.cond
163 call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 4, i32 0, i64 -1), !dbg !104
164 call void @new_foo(), !dbg !106
165 call void @baz(), !dbg !108
166 call void @test_noninline(), !dbg !110
167 call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 8, i32 0, i64 -1), !dbg !112
168 %inc = add nsw i32 %i.0, 1, !dbg !112
169 #dbg_value(i32 %inc, !89, !DIExpression(), !92)
170 br label %for.cond, !dbg !113, !llvm.loop !114
171 }
172
173 ; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
174 declare void @llvm.lifetime.start.p0(ptr nocapture) #3
175
176 ; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
177 declare void @llvm.lifetime.end.p0(ptr nocapture) #3
178
179 ; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: readwrite)
180 declare void @llvm.pseudoprobe(i64, i64, i32, i64) #4
181
182 attributes #0 = { noinline nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" "use-sample-profile" }
183 attributes #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }
184 attributes #2 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cmov,+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" "use-sample-profile" }
185 attributes #3 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
186 attributes #4 = { mustprogress nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: readwrite) }
187
188 !llvm.dbg.cu = !{!2}
189 !llvm.module.flags = !{!7, !8, !9, !10, !11, !12, !13}
190 !llvm.ident = !{!14}
191 !llvm.pseudo_probe_desc = !{!15, !16, !17, !18, !19, !20, !21}
192
193 !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
194 !1 = distinct !DIGlobalVariable(name: "x", scope: !2, file: !3, line: 1, type: !5, isLocal: false, isDefinition: true)
195 !2 = distinct !DICompileUnit(language: DW_LANG_C11, file: !3, producer: "clang version 19.0.0git (https://github.com/llvm/llvm-project.git 2e1509152224d8ffbeac84c489920dcbaeefc2b2)", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, globals: !4, splitDebugInlining: false, nameTableKind: None)
196 !3 = !DIFile(filename: "test_rename.c", directory: "/home/wlei/local/toytest/rename", checksumkind: CSK_MD5, checksum: "b07f600b3cdefd40bd44932bc13c33f5")
197 !4 = !{!0}
198 !5 = !DIDerivedType(tag: DW_TAG_volatile_type, baseType: !6)
199 !6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
200 !7 = !{i32 7, !"Dwarf Version", i32 5}
201 !8 = !{i32 2, !"Debug Info Version", i32 3}
202 !9 = !{i32 1, !"wchar_size", i32 4}
203 !10 = !{i32 8, !"PIC Level", i32 2}
204 !11 = !{i32 7, !"PIE Level", i32 2}
205 !12 = !{i32 7, !"uwtable", i32 2}
206 !13 = !{i32 7, !"debug-info-assignment-tracking", i1 true}
207 !14 = !{!"clang version 19.0.0git (https://github.com/llvm/llvm-project.git 2e1509152224d8ffbeac84c489920dcbaeefc2b2)"}
208 !15 = !{i64 -2012135647395072713, i64 4294967295, !"bar"}
209 !16 = !{i64 2964250471062803127, i64 206551239323, !"new_block_only"}
210 !17 = !{i64 7546896869197086323, i64 281479271677951, !"baz"}
211 !18 = !{i64 5381804724291869009, i64 844429225099263, !"new_foo"}
212 !19 = !{i64 -5610330892148506720, i64 281479271677951, !"test_noninline"}
213 !20 = !{i64 2711072140522378707, i64 281479271677951, !"cold_func"}
214 !21 = !{i64 -2624081020897602054, i64 1126003093360596, !"main"}
215 !22 = distinct !DISubprogram(name: "bar", scope: !3, file: !3, line: 3, type: !23, scopeLine: 3, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !25)
216 !23 = !DISubroutineType(types: !24)
217 !24 = !{!6, !6}
218 !25 = !{!26}
219 !26 = !DILocalVariable(name: "x", arg: 1, scope: !22, file: !3, line: 3, type: !6)
220 !27 = !DILocation(line: 0, scope: !22)
221 !28 = !DILocation(line: 4, column: 10, scope: !22)
222 !29 = !DILocation(line: 4, column: 12, scope: !22)
223 !30 = !DILocation(line: 4, column: 3, scope: !22)
224 !31 = distinct !DISubprogram(name: "new_block_only", scope: !3, file: !3, line: 7, type: !32, scopeLine: 7, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2)
225 !32 = !DISubroutineType(types: !33)
226 !33 = !{null}
227 !34 = !DILocation(line: 8, column: 6, scope: !35)
228 !35 = distinct !DILexicalBlock(scope: !31, file: !3, line: 8, column: 6)
229 !36 = !{!37, !37, i64 0}
230 !37 = !{!"int", !38, i64 0}
231 !38 = !{!"omnipotent char", !39, i64 0}
232 !39 = !{!"Simple C/C++ TBAA"}
233 !40 = !DILocation(line: 8, column: 8, scope: !35)
234 !41 = !DILocation(line: 8, column: 6, scope: !31)
235 !42 = !DILocation(line: 9, column: 7, scope: !35)
236 !43 = !DILocation(line: 9, column: 5, scope: !35)
237 !44 = !DILocation(line: 10, column: 12, scope: !45)
238 !45 = distinct !DILexicalBlock(scope: !35, file: !3, line: 10, column: 12)
239 !46 = !DILocation(line: 10, column: 14, scope: !45)
240 !47 = !DILocation(line: 10, column: 12, scope: !35)
241 !48 = !DILocation(line: 11, column: 7, scope: !45)
242 !49 = !DILocation(line: 11, column: 5, scope: !45)
243 !50 = !DILocation(line: 12, column: 12, scope: !51)
244 !51 = distinct !DILexicalBlock(scope: !45, file: !3, line: 12, column: 12)
245 !52 = !DILocation(line: 12, column: 14, scope: !51)
246 !53 = !DILocation(line: 12, column: 12, scope: !45)
247 !54 = !DILocation(line: 13, column: 7, scope: !51)
248 !55 = !DILocation(line: 13, column: 5, scope: !51)
249 !56 = !DILocation(line: 15, column: 6, scope: !51)
250 !57 = !DILocation(line: 16, column: 1, scope: !31)
251 !58 = distinct !DISubprogram(name: "baz", scope: !3, file: !3, line: 18, type: !32, scopeLine: 18, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2)
252 !59 = !DILocation(line: 19, column: 3, scope: !58)
253 !60 = !DILocation(line: 19, column: 3, scope: !61)
254 !61 = !DILexicalBlockFile(scope: !58, file: !3, discriminator: 186646551)
255 !62 = !DILocation(line: 20, column: 1, scope: !58)
256 !63 = distinct !DISubprogram(name: "new_foo", scope: !3, file: !3, line: 22, type: !32, scopeLine: 22, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2)
257 !64 = !DILocation(line: 23, column: 12, scope: !63)
258 !65 = !DILocation(line: 23, column: 8, scope: !66)
259 !66 = !DILexicalBlockFile(scope: !63, file: !3, discriminator: 186646551)
260 !67 = !DILocation(line: 23, column: 5, scope: !63)
261 !68 = !DILocation(line: 24, column: 3, scope: !69)
262 !69 = !DILexicalBlockFile(scope: !63, file: !3, discriminator: 186646559)
263 !70 = !DILocation(line: 25, column: 12, scope: !63)
264 !71 = !DILocation(line: 25, column: 8, scope: !72)
265 !72 = !DILexicalBlockFile(scope: !63, file: !3, discriminator: 186646567)
266 !73 = !DILocation(line: 25, column: 5, scope: !63)
267 !74 = !DILocation(line: 26, column: 1, scope: !63)
268 !75 = distinct !DISubprogram(name: "test_noninline", scope: !3, file: !3, line: 28, type: !32, scopeLine: 28, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2)
269 !76 = !DILocation(line: 29, column: 3, scope: !75)
270 !77 = !DILocation(line: 29, column: 3, scope: !78)
271 !78 = !DILexicalBlockFile(scope: !75, file: !3, discriminator: 186646551)
272 !79 = !DILocation(line: 30, column: 1, scope: !75)
273 !80 = distinct !DISubprogram(name: "cold_func", scope: !3, file: !3, line: 32, type: !32, scopeLine: 32, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2)
274 !81 = !DILocation(line: 32, column: 20, scope: !80)
275 !82 = !DILocation(line: 32, column: 20, scope: !83)
276 !83 = !DILexicalBlockFile(scope: !80, file: !3, discriminator: 186646551)
277 !84 = !DILocation(line: 32, column: 37, scope: !80)
278 !85 = distinct !DISubprogram(name: "main", scope: !3, file: !3, line: 34, type: !86, scopeLine: 34, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !88)
279 !86 = !DISubroutineType(types: !87)
280 !87 = !{!6}
281 !88 = !{!89}
282 !89 = !DILocalVariable(name: "i", scope: !90, file: !3, line: 35, type: !6)
283 !90 = distinct !DILexicalBlock(scope: !85, file: !3, line: 35, column: 3)
284 !91 = !DILocation(line: 35, column: 12, scope: !90)
285 !92 = !DILocation(line: 0, scope: !90)
286 !93 = !DILocation(line: 35, column: 8, scope: !90)
287 !94 = !DILocation(line: 35, scope: !90)
288 !95 = !DILocation(line: 35, column: 19, scope: !96)
289 !96 = distinct !DILexicalBlock(scope: !90, file: !3, line: 35, column: 3)
290 !97 = !DILocation(line: 35, column: 21, scope: !96)
291 !98 = !DILocation(line: 35, column: 3, scope: !90)
292 !99 = !DILocation(line: 0, scope: !85)
293 !100 = !DILocation(line: 40, column: 3, scope: !85)
294 !101 = !DILocation(line: 40, column: 3, scope: !102)
295 !102 = !DILexicalBlockFile(scope: !85, file: !3, discriminator: 186646615)
296 !103 = !DILocation(line: 41, column: 1, scope: !85)
297 !104 = !DILocation(line: 36, column: 7, scope: !105)
298 !105 = distinct !DILexicalBlock(scope: !96, file: !3, line: 35, column: 41)
299 !106 = !DILocation(line: 36, column: 7, scope: !107)
300 !107 = !DILexicalBlockFile(scope: !105, file: !3, discriminator: 186646575)
301 !108 = !DILocation(line: 37, column: 7, scope: !109)
302 !109 = !DILexicalBlockFile(scope: !105, file: !3, discriminator: 186646583)
303 !110 = !DILocation(line: 38, column: 7, scope: !111)
304 !111 = !DILexicalBlockFile(scope: !105, file: !3, discriminator: 186646591)
305 !112 = !DILocation(line: 35, column: 37, scope: !96)
306 !113 = !DILocation(line: 35, column: 3, scope: !96)
307 !114 = distinct !{!114, !98, !115, !116}
308 !115 = !DILocation(line: 39, column: 3, scope: !90)
309 !116 = !{!"llvm.loop.mustprogress"}