310 lines · plain
1; REQUIRES: asserts && x86-registered-target2; 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 %s3; 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-FUNC4 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 main10; CHECK: The similarity between new_foo(IR) and foo(profile) is 0.7511; CHECK: Function:new_foo matches profile:foo12; CHECK: Run stale profile matching for cold_func13; CHECK: The checksums for new_block_only(IR) and block_only(Profile) match.14; CHECK: Function:new_block_only matches profile:block_only15; CHECK: Run stale profile matching for test_noninline16; CHECK: Run stale profile matching for baz17; CHECK: Run stale profile matching for bar18 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.624; 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 5528 29; TINY-FUNC-NOT: Function:new_foo matches profile:foo30; TINY-FUNC-NOT: Function:new_block_only matches profile:block_only31 32 33@x = dso_local global i32 0, align 4, !dbg !034 35; Function Attrs: noinline nounwind uwtable36define dso_local i32 @bar(i32 noundef %x) #0 !dbg !22 {37entry:38 #dbg_value(i32 %x, !26, !DIExpression(), !27)39 call void @llvm.pseudoprobe(i64 -2012135647395072713, i64 1, i32 0, i64 -1), !dbg !2840 %add = add nsw i32 %x, 1, !dbg !2941 ret i32 %add, !dbg !3042}43 44; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)45declare void @llvm.dbg.declare(metadata, metadata, metadata) #146 47; Function Attrs: nounwind uwtable48define dso_local void @new_block_only() #2 !dbg !31 {49entry:50 call void @llvm.pseudoprobe(i64 2964250471062803127, i64 1, i32 0, i64 -1), !dbg !3451 %0 = load volatile i32, ptr @x, align 4, !dbg !34, !tbaa !3652 %cmp = icmp eq i32 %0, 9999, !dbg !4053 br i1 %cmp, label %if.then, label %if.else, !dbg !4154 55if.then: ; preds = %entry56 call void @llvm.pseudoprobe(i64 2964250471062803127, i64 2, i32 0, i64 -1), !dbg !4257 %1 = load volatile i32, ptr @x, align 4, !dbg !42, !tbaa !3658 %add = add nsw i32 %1, 1000, !dbg !4259 store volatile i32 %add, ptr @x, align 4, !dbg !42, !tbaa !3660 br label %if.end10, !dbg !4361 62if.else: ; preds = %entry63 call void @llvm.pseudoprobe(i64 2964250471062803127, i64 3, i32 0, i64 -1), !dbg !4464 %2 = load volatile i32, ptr @x, align 4, !dbg !44, !tbaa !3665 %cmp1 = icmp eq i32 %2, 999, !dbg !4666 br i1 %cmp1, label %if.then2, label %if.else4, !dbg !4767 68if.then2: ; preds = %if.else69 call void @llvm.pseudoprobe(i64 2964250471062803127, i64 4, i32 0, i64 -1), !dbg !4870 %3 = load volatile i32, ptr @x, align 4, !dbg !48, !tbaa !3671 %add3 = add nsw i32 %3, 100, !dbg !4872 store volatile i32 %add3, ptr @x, align 4, !dbg !48, !tbaa !3673 br label %if.end10, !dbg !4974 75if.else4: ; preds = %if.else76 call void @llvm.pseudoprobe(i64 2964250471062803127, i64 5, i32 0, i64 -1), !dbg !5077 %4 = load volatile i32, ptr @x, align 4, !dbg !50, !tbaa !3678 %cmp5 = icmp eq i32 %4, 99, !dbg !5279 br i1 %cmp5, label %if.then6, label %if.else8, !dbg !5380 81if.then6: ; preds = %if.else482 call void @llvm.pseudoprobe(i64 2964250471062803127, i64 6, i32 0, i64 -1), !dbg !5483 %5 = load volatile i32, ptr @x, align 4, !dbg !54, !tbaa !3684 %add7 = add nsw i32 %5, 10, !dbg !5485 store volatile i32 %add7, ptr @x, align 4, !dbg !54, !tbaa !3686 br label %if.end10, !dbg !5587 88if.else8: ; preds = %if.else489 call void @llvm.pseudoprobe(i64 2964250471062803127, i64 7, i32 0, i64 -1), !dbg !5690 %6 = load volatile i32, ptr @x, align 4, !dbg !56, !tbaa !3691 %inc = add nsw i32 %6, 1, !dbg !5692 store volatile i32 %inc, ptr @x, align 4, !dbg !56, !tbaa !3693 br label %if.end1094 95if.end10: ; preds = %if.then2, %if.else8, %if.then6, %if.then96 call void @llvm.pseudoprobe(i64 2964250471062803127, i64 10, i32 0, i64 -1), !dbg !5797 ret void, !dbg !5798}99 100; Function Attrs: nounwind uwtable101define dso_local void @baz() #2 !dbg !58 {102entry:103 call void @llvm.pseudoprobe(i64 7546896869197086323, i64 1, i32 0, i64 -1), !dbg !59104 call void @new_block_only(), !dbg !60105 ret void, !dbg !62106}107 108; Function Attrs: nounwind uwtable109define dso_local void @new_foo() #2 !dbg !63 {110entry:111 call void @llvm.pseudoprobe(i64 5381804724291869009, i64 1, i32 0, i64 -1), !dbg !64112 %0 = load volatile i32, ptr @x, align 4, !dbg !64, !tbaa !36113 %call = call i32 @bar(i32 noundef %0), !dbg !65114 %1 = load volatile i32, ptr @x, align 4, !dbg !67, !tbaa !36115 %add = add nsw i32 %1, %call, !dbg !67116 store volatile i32 %add, ptr @x, align 4, !dbg !67, !tbaa !36117 call void @baz(), !dbg !68118 %2 = load volatile i32, ptr @x, align 4, !dbg !70, !tbaa !36119 %call1 = call i32 @bar(i32 noundef %2), !dbg !71120 %3 = load volatile i32, ptr @x, align 4, !dbg !73, !tbaa !36121 %add2 = add nsw i32 %3, %call1, !dbg !73122 store volatile i32 %add2, ptr @x, align 4, !dbg !73, !tbaa !36123 ret void, !dbg !74124}125 126; Function Attrs: noinline nounwind uwtable127define dso_local void @test_noninline() #0 !dbg !75 {128entry:129 call void @llvm.pseudoprobe(i64 -5610330892148506720, i64 1, i32 0, i64 -1), !dbg !76130 call void @new_foo(), !dbg !77131 ret void, !dbg !79132}133 134; Function Attrs: nounwind uwtable135define dso_local void @cold_func() #2 !dbg !80 {136entry:137 call void @llvm.pseudoprobe(i64 2711072140522378707, i64 1, i32 0, i64 -1), !dbg !81138 call void @new_block_only(), !dbg !82139 ret void, !dbg !84140}141 142; Function Attrs: nounwind uwtable143define dso_local i32 @main() #2 !dbg !85 {144entry:145 call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 1, i32 0, i64 -1), !dbg !91146 #dbg_value(i32 0, !89, !DIExpression(), !92)147 br label %for.cond, !dbg !93148 149for.cond: ; preds = %for.body, %entry150 %i.0 = phi i32 [ 0, %entry ], [ %inc, %for.body ], !dbg !94151 #dbg_value(i32 %i.0, !89, !DIExpression(), !92)152 call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 2, i32 0, i64 -1), !dbg !95153 %cmp = icmp slt i32 %i.0, 1000000, !dbg !97154 br i1 %cmp, label %for.body, label %for.cond.cleanup, !dbg !98155 156for.cond.cleanup: ; preds = %for.cond157 call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 3, i32 0, i64 -1), !dbg !99158 call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 9, i32 0, i64 -1), !dbg !100159 call void @cold_func(), !dbg !101160 ret i32 0, !dbg !103161 162for.body: ; preds = %for.cond163 call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 4, i32 0, i64 -1), !dbg !104164 call void @new_foo(), !dbg !106165 call void @baz(), !dbg !108166 call void @test_noninline(), !dbg !110167 call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 8, i32 0, i64 -1), !dbg !112168 %inc = add nsw i32 %i.0, 1, !dbg !112169 #dbg_value(i32 %inc, !89, !DIExpression(), !92)170 br label %for.cond, !dbg !113, !llvm.loop !114171}172 173; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)174declare void @llvm.lifetime.start.p0(ptr nocapture) #3175 176; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)177declare void @llvm.lifetime.end.p0(ptr nocapture) #3178 179; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: readwrite)180declare void @llvm.pseudoprobe(i64, i64, i32, i64) #4181 182attributes #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" }183attributes #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }184attributes #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" }185attributes #3 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }186attributes #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"}310