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