xref: /llvm-project/llvm/test/Transforms/SampleProfile/pseudo-probe-stale-profile-toplev-func.ll (revision 6e60330af55bfdf5b34aed4c9197cd3afbf00498)
1*6e60330aSLei Wang; REQUIRES: x86_64-linux
2*6e60330aSLei Wang; REQUIRES: asserts
3*6e60330aSLei Wang; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/pseudo-probe-stale-profile-toplev-func.prof --salvage-stale-profile --salvage-unused-profile -report-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 --load-func-profile-for-cg-matching 2>&1 | FileCheck %s -check-prefix=CHECK-TEXT
4*6e60330aSLei Wang; RUN: llvm-profdata merge --sample %S/Inputs/pseudo-probe-stale-profile-toplev-func.prof -extbinary -o %t.extbinary
5*6e60330aSLei Wang; RUN: opt < %s -passes=sample-profile -sample-profile-file=%t.extbinary --salvage-stale-profile --salvage-unused-profile -report-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 --load-func-profile-for-cg-matching 2>&1 | FileCheck %s -check-prefix=CHECK-EXTBIN
6*6e60330aSLei Wang
7*6e60330aSLei Wang; CHECK-TEXT: Run stale profile matching for main
8*6e60330aSLei Wang; CHECK-TEXT-NOT: Read top-level function foo for call-graph matching
9*6e60330aSLei Wang; CHECK-TEXT: The checksums for foo_rename(IR) and foo(Profile) match.
10*6e60330aSLei Wang; CHECK-TEXT: Function:foo_rename matches profile:foo
11*6e60330aSLei Wang; CHECK-TEXT: Run stale profile matching for foo_rename
12*6e60330aSLei Wang; CHECK-TEXT: (1/3) of functions' profile are matched and (2724522/3177413) of samples are reused by call graph matching.
13*6e60330aSLei Wang
14*6e60330aSLei Wang; CHECK-TEXT: Processing Function main
15*6e60330aSLei Wang; CHECK-TEXT:     5:  call void @foo_rename(), !dbg ![[#]] - weight: 51
16*6e60330aSLei Wang; CHECK-TEXT: Processing Function foo_rename
17*6e60330aSLei Wang; CHECK-TEXT:     2:  %call = call i32 @bar(i32 noundef %0), !dbg ![[#]] - weight: 452674
18*6e60330aSLei Wang
19*6e60330aSLei Wang
20*6e60330aSLei Wang; CHECK-EXTBIN: Run stale profile matching for main
21*6e60330aSLei Wang; CHECK-EXTBIN: Read top-level function foo for call-graph matching
22*6e60330aSLei Wang; CHECK-EXTBIN: The checksums for foo_rename(IR) and foo(Profile) match.
23*6e60330aSLei Wang; CHECK-EXTBIN: Function:foo_rename matches profile:foo
24*6e60330aSLei Wang; CHECK-EXTBIN: Run stale profile matching for foo_rename
25*6e60330aSLei Wang; CHECK-EXTBIN: (1/3) of functions' profile are matched and (2724522/3177413) of samples are reused by call graph matching.
26*6e60330aSLei Wang
27*6e60330aSLei Wang; CHECK-EXTBIN: Processing Function main
28*6e60330aSLei Wang; CHECK-EXTBIN:     5:  call void @foo_rename(), !dbg ![[#]] - weight: 51
29*6e60330aSLei Wang; CHECK-EXTBIN: Processing Function foo_rename
30*6e60330aSLei Wang; CHECK-EXTBIN:     2:  %call = call i32 @bar(i32 noundef %0), !dbg ![[#]] - weight: 452674
31*6e60330aSLei Wang
32*6e60330aSLei Wang
33*6e60330aSLei Wangtarget datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-i128:128-f80:128-n8:16:32:64-S128"
34*6e60330aSLei Wangtarget triple = "x86_64-unknown-linux-gnu"
35*6e60330aSLei Wang
36*6e60330aSLei Wang@x = dso_local global i32 0, align 4, !dbg !0
37*6e60330aSLei Wang
38*6e60330aSLei Wang; Function Attrs: noinline nounwind uwtable
39*6e60330aSLei Wangdefine dso_local i32 @bar(i32 noundef %x) #0 !dbg !18 {
40*6e60330aSLei Wangentry:
41*6e60330aSLei Wang    #dbg_value(i32 %x, !22, !DIExpression(), !23)
42*6e60330aSLei Wang  call void @llvm.pseudoprobe(i64 -2012135647395072713, i64 1, i32 0, i64 -1), !dbg !24
43*6e60330aSLei Wang  %add = add nsw i32 %x, 1, !dbg !25
44*6e60330aSLei Wang  ret i32 %add, !dbg !26
45*6e60330aSLei Wang}
46*6e60330aSLei Wang
47*6e60330aSLei Wang; Function Attrs: noinline nounwind uwtable
48*6e60330aSLei Wangdefine dso_local void @foo_rename() #0 !dbg !27 {
49*6e60330aSLei Wangentry:
50*6e60330aSLei Wang  call void @llvm.pseudoprobe(i64 -2115950948644264162, i64 1, i32 0, i64 -1), !dbg !30
51*6e60330aSLei Wang  %0 = load volatile i32, ptr @x, align 4, !dbg !30, !tbaa !31
52*6e60330aSLei Wang  %call = call i32 @bar(i32 noundef %0), !dbg !35
53*6e60330aSLei Wang  %1 = load volatile i32, ptr @x, align 4, !dbg !37, !tbaa !31
54*6e60330aSLei Wang  %add = add nsw i32 %1, %call, !dbg !37
55*6e60330aSLei Wang  store volatile i32 %add, ptr @x, align 4, !dbg !37, !tbaa !31
56*6e60330aSLei Wang  ret void, !dbg !38
57*6e60330aSLei Wang}
58*6e60330aSLei Wang
59*6e60330aSLei Wang; Function Attrs: nounwind uwtable
60*6e60330aSLei Wangdefine dso_local i32 @main() #1 !dbg !39 {
61*6e60330aSLei Wangentry:
62*6e60330aSLei Wang  call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 1, i32 0, i64 -1), !dbg !45
63*6e60330aSLei Wang    #dbg_value(i32 0, !43, !DIExpression(), !46)
64*6e60330aSLei Wang  br label %for.cond, !dbg !47
65*6e60330aSLei Wang
66*6e60330aSLei Wangfor.cond:                                         ; preds = %for.body, %entry
67*6e60330aSLei Wang  %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.body ], !dbg !48
68*6e60330aSLei Wang    #dbg_value(i32 %i.0, !43, !DIExpression(), !46)
69*6e60330aSLei Wang  call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 2, i32 0, i64 -1), !dbg !49
70*6e60330aSLei Wang  %cmp = icmp slt i32 %i.0, 100000, !dbg !51
71*6e60330aSLei Wang  br i1 %cmp, label %for.body, label %for.cond.cleanup, !dbg !52
72*6e60330aSLei Wang
73*6e60330aSLei Wangfor.cond.cleanup:                                 ; preds = %for.cond
74*6e60330aSLei Wang  call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 3, i32 0, i64 -1), !dbg !53
75*6e60330aSLei Wang  call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 7, i32 0, i64 -1), !dbg !54
76*6e60330aSLei Wang  ret i32 0, !dbg !54
77*6e60330aSLei Wang
78*6e60330aSLei Wangfor.body:                                         ; preds = %for.cond
79*6e60330aSLei Wang  call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 4, i32 0, i64 -1), !dbg !55
80*6e60330aSLei Wang  call void @foo_rename(), !dbg !57
81*6e60330aSLei Wang  call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 6, i32 0, i64 -1), !dbg !59
82*6e60330aSLei Wang  %inc = add nsw i32 %i.0, 1, !dbg !59
83*6e60330aSLei Wang    #dbg_value(i32 %inc, !43, !DIExpression(), !46)
84*6e60330aSLei Wang  br label %for.cond, !dbg !60, !llvm.loop !61
85*6e60330aSLei Wang}
86*6e60330aSLei Wang
87*6e60330aSLei Wang; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
88*6e60330aSLei Wangdeclare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2
89*6e60330aSLei Wang
90*6e60330aSLei Wang; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)
91*6e60330aSLei Wangdeclare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2
92*6e60330aSLei Wang
93*6e60330aSLei Wang; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: readwrite)
94*6e60330aSLei Wangdeclare void @llvm.pseudoprobe(i64, i64, i32, i64) #3
95*6e60330aSLei Wang
96*6e60330aSLei Wangattributes #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" }
97*6e60330aSLei Wangattributes #1 = { 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" }
98*6e60330aSLei Wangattributes #2 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }
99*6e60330aSLei Wangattributes #3 = { mustprogress nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: readwrite) }
100*6e60330aSLei Wang
101*6e60330aSLei Wang!llvm.dbg.cu = !{!2}
102*6e60330aSLei Wang!llvm.module.flags = !{!7, !8, !9, !10, !11, !12, !13}
103*6e60330aSLei Wang!llvm.ident = !{!14}
104*6e60330aSLei Wang!llvm.pseudo_probe_desc = !{!15, !16, !17}
105*6e60330aSLei Wang
106*6e60330aSLei Wang!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())
107*6e60330aSLei Wang!1 = distinct !DIGlobalVariable(name: "x", scope: !2, file: !3, line: 1, type: !5, isLocal: false, isDefinition: true)
108*6e60330aSLei Wang!2 = distinct !DICompileUnit(language: DW_LANG_C11, file: !3, producer: "clang version 20.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, globals: !4, splitDebugInlining: false, nameTableKind: None)
109*6e60330aSLei Wang!3 = !DIFile(filename: "test_rename.c", directory: "/home", checksumkind: CSK_MD5, checksum: "11a33a83e4d190ebda0792d0610f0c67")
110*6e60330aSLei Wang!4 = !{!0}
111*6e60330aSLei Wang!5 = !DIDerivedType(tag: DW_TAG_volatile_type, baseType: !6)
112*6e60330aSLei Wang!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)
113*6e60330aSLei Wang!7 = !{i32 7, !"Dwarf Version", i32 5}
114*6e60330aSLei Wang!8 = !{i32 2, !"Debug Info Version", i32 3}
115*6e60330aSLei Wang!9 = !{i32 1, !"wchar_size", i32 4}
116*6e60330aSLei Wang!10 = !{i32 8, !"PIC Level", i32 2}
117*6e60330aSLei Wang!11 = !{i32 7, !"PIE Level", i32 2}
118*6e60330aSLei Wang!12 = !{i32 7, !"uwtable", i32 2}
119*6e60330aSLei Wang!13 = !{i32 7, !"debug-info-assignment-tracking", i1 true}
120*6e60330aSLei Wang!14 = !{!"clang version 20.0.0"}
121*6e60330aSLei Wang!15 = !{i64 -2012135647395072713, i64 4294967295, !"bar"}
122*6e60330aSLei Wang!16 = !{i64 -2115950948644264162, i64 281479271677951, !"foo_rename"}
123*6e60330aSLei Wang!17 = !{i64 -2624081020897602054, i64 281582264815352, !"main"}
124*6e60330aSLei Wang!18 = distinct !DISubprogram(name: "bar", scope: !3, file: !3, line: 3, type: !19, scopeLine: 3, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !21)
125*6e60330aSLei Wang!19 = !DISubroutineType(types: !20)
126*6e60330aSLei Wang!20 = !{!6, !6}
127*6e60330aSLei Wang!21 = !{!22}
128*6e60330aSLei Wang!22 = !DILocalVariable(name: "x", arg: 1, scope: !18, file: !3, line: 3, type: !6)
129*6e60330aSLei Wang!23 = !DILocation(line: 0, scope: !18)
130*6e60330aSLei Wang!24 = !DILocation(line: 4, column: 10, scope: !18)
131*6e60330aSLei Wang!25 = !DILocation(line: 4, column: 12, scope: !18)
132*6e60330aSLei Wang!26 = !DILocation(line: 4, column: 3, scope: !18)
133*6e60330aSLei Wang!27 = distinct !DISubprogram(name: "foo_rename", scope: !3, file: !3, line: 7, type: !28, scopeLine: 7, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2)
134*6e60330aSLei Wang!28 = !DISubroutineType(types: !29)
135*6e60330aSLei Wang!29 = !{null}
136*6e60330aSLei Wang!30 = !DILocation(line: 8, column: 15, scope: !27)
137*6e60330aSLei Wang!31 = !{!32, !32, i64 0}
138*6e60330aSLei Wang!32 = !{!"int", !33, i64 0}
139*6e60330aSLei Wang!33 = !{!"omnipotent char", !34, i64 0}
140*6e60330aSLei Wang!34 = !{!"Simple C/C++ TBAA"}
141*6e60330aSLei Wang!35 = !DILocation(line: 8, column: 11, scope: !36)
142*6e60330aSLei Wang!36 = !DILexicalBlockFile(scope: !27, file: !3, discriminator: 455082007)
143*6e60330aSLei Wang!37 = !DILocation(line: 8, column: 8, scope: !27)
144*6e60330aSLei Wang!38 = !DILocation(line: 9, column: 1, scope: !27)
145*6e60330aSLei Wang!39 = distinct !DISubprogram(name: "main", scope: !3, file: !3, line: 11, type: !40, scopeLine: 11, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !42)
146*6e60330aSLei Wang!40 = !DISubroutineType(types: !41)
147*6e60330aSLei Wang!41 = !{!6}
148*6e60330aSLei Wang!42 = !{!43}
149*6e60330aSLei Wang!43 = !DILocalVariable(name: "i", scope: !44, file: !3, line: 12, type: !6)
150*6e60330aSLei Wang!44 = distinct !DILexicalBlock(scope: !39, file: !3, line: 12, column: 3)
151*6e60330aSLei Wang!45 = !DILocation(line: 12, column: 12, scope: !44)
152*6e60330aSLei Wang!46 = !DILocation(line: 0, scope: !44)
153*6e60330aSLei Wang!47 = !DILocation(line: 12, column: 8, scope: !44)
154*6e60330aSLei Wang!48 = !DILocation(line: 12, scope: !44)
155*6e60330aSLei Wang!49 = !DILocation(line: 12, column: 19, scope: !50)
156*6e60330aSLei Wang!50 = distinct !DILexicalBlock(scope: !44, file: !3, line: 12, column: 3)
157*6e60330aSLei Wang!51 = !DILocation(line: 12, column: 21, scope: !50)
158*6e60330aSLei Wang!52 = !DILocation(line: 12, column: 3, scope: !44)
159*6e60330aSLei Wang!53 = !DILocation(line: 0, scope: !39)
160*6e60330aSLei Wang!54 = !DILocation(line: 15, column: 1, scope: !39)
161*6e60330aSLei Wang!55 = !DILocation(line: 13, column: 7, scope: !56)
162*6e60330aSLei Wang!56 = distinct !DILexicalBlock(scope: !50, file: !3, line: 12, column: 40)
163*6e60330aSLei Wang!57 = !DILocation(line: 13, column: 7, scope: !58)
164*6e60330aSLei Wang!58 = !DILexicalBlockFile(scope: !56, file: !3, discriminator: 455082031)
165*6e60330aSLei Wang!59 = !DILocation(line: 12, column: 36, scope: !50)
166*6e60330aSLei Wang!60 = !DILocation(line: 12, column: 3, scope: !50)
167*6e60330aSLei Wang!61 = distinct !{!61, !52, !62, !63}
168*6e60330aSLei Wang!62 = !DILocation(line: 14, column: 3, scope: !44)
169*6e60330aSLei Wang!63 = !{!"llvm.loop.mustprogress"}
170