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