341 lines · plain
1; REQUIRES: asserts && x86-registered-target2; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/pseudo-probe-stale-profile-matching.prof --salvage-stale-profile -S --debug-only=sample-profile,sample-profile-matcher,sample-profile-impl 2>&1 | FileCheck %s3 4; The profiled source code:5 6; volatile int x = 1;7; __attribute__((noinline)) int bar(int p) {8; return p;9; }10 11; __attribute__((always_inline)) int foo(int i, int p) {12; if (i % 10) return bar(p);13; else return bar(p + 1);14; }15 16; int main() {17; for (int i = 0; i < 1000 * 1000; i++) {18; x += foo(i, x);19; x += bar(x);20; x += foo(i, x);21; x += bar(x);22; }23; }24 25; The source code for the current build:26 27; volatile int x = 1;28; __attribute__((noinline)) int bar(int p) {29; return p;30; }31 32; __attribute__((always_inline)) int foo(int i, int p) {33; if (i % 10) return bar(p);34; else return bar(p + 1);35; }36 37; int main() {38; if (x == 0) // code change39; return 0; // code change40; for (int i = 0; i < 1000 * 1000; i++) {41; x += foo(i, x);42; x += bar(x);43; if (i < 0) // code change44; return 0; // code change45; x += foo(i, x);46; x += bar(x);47; }48; }49 50; Verify not running profile matching for checksum matched function.51; CHECK-NOT: Run stale profile matching for bar52 53; CHECK: Run stale profile matching for main54 55; CHECK: Location is matched from 1 to 156; CHECK: Location is matched from 2 to 257; CHECK: Location is matched from 3 to 358; CHECK: Location is matched from 4 to 459; CHECK: Location is matched from 5 to 560; CHECK: Location is matched from 6 to 661; CHECK: Location is matched from 7 to 762; CHECK: Location is matched from 8 to 863; CHECK: Location is matched from 9 to 964; CHECK: Location is matched from 10 to 1065; CHECK: Location is matched from 11 to 1166 67; CHECK: Callsite with callee:foo is matched from 13 to 668; CHECK: Location is rematched backwards from 7 to 069; CHECK: Location is rematched backwards from 8 to 170; CHECK: Location is rematched backwards from 9 to 271; CHECK: Location is rematched backwards from 10 to 372; CHECK: Location is rematched backwards from 11 to 473; CHECK: Callsite with callee:bar is matched from 14 to 774; CHECK: Callsite with callee:foo is matched from 15 to 875; CHECK: Callsite with callee:bar is matched from 16 to 976 77 78; CHECK: 2: call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 2, i32 0, i64 -1), !dbg ![[#]] - weight: 112 - factor: 1.00)79; CHECK: 3: call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 3, i32 0, i64 -1), !dbg ![[#]] - weight: 112 - factor: 1.00)80; CHECK: 4: call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 4, i32 0, i64 -1), !dbg ![[#]] - weight: 116 - factor: 1.00)81; CHECK: 5: call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 5, i32 0, i64 -1), !dbg ![[#]] - weight: 0 - factor: 1.00)82; CHECK: 1: call void @llvm.pseudoprobe(i64 6699318081062747564, i64 1, i32 0, i64 -1), !dbg ![[#]] - weight: 112 - factor: 1.00)83; CHECK: 2: call void @llvm.pseudoprobe(i64 6699318081062747564, i64 2, i32 0, i64 -1), !dbg ![[#]] - weight: 101 - factor: 1.00)84; CHECK: 5: %call.i8 = call i32 @bar(i32 noundef %1), !dbg ![[#]] - weight: 101 - factor: 1.00)85; CHECK: 3: call void @llvm.pseudoprobe(i64 6699318081062747564, i64 3, i32 0, i64 -1), !dbg ![[#]] - weight: 13 - factor: 1.00)86; CHECK: 6: %call1.i5 = call i32 @bar(i32 noundef %add.i4), !dbg ![[#]] - weight: 13 - factor: 1.00)87; CHECK: 4: call void @llvm.pseudoprobe(i64 6699318081062747564, i64 4, i32 0, i64 -1), !dbg ![[#]] - weight: 112 - factor: 1.00)88; CHECK: 14: %call2 = call i32 @bar(i32 noundef %3), !dbg ![[#]] - weight: 124 - factor: 1.00)89; CHECK: 8: call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 8, i32 0, i64 -1), !dbg ![[#]] - weight: 0 - factor: 1.00)90; CHECK: 1: call void @llvm.pseudoprobe(i64 6699318081062747564, i64 1, i32 0, i64 -1), !dbg ![[#]] - weight: 117 - factor: 1.00)91; CHECK: 2: call void @llvm.pseudoprobe(i64 6699318081062747564, i64 2, i32 0, i64 -1), !dbg ![[#]] - weight: 104 - factor: 1.00)92; CHECK: 5: %call.i = call i32 @bar(i32 noundef %5), !dbg ![[#]] - weight: 104 - factor: 1.00)93; CHECK: 3: call void @llvm.pseudoprobe(i64 6699318081062747564, i64 3, i32 0, i64 -1), !dbg ![[#]] - weight: 13 - factor: 1.00)94; CHECK: 6: %call1.i = call i32 @bar(i32 noundef %add.i), !dbg ![[#]] - weight: 14 - factor: 1.00)95; CHECK: 4: call void @llvm.pseudoprobe(i64 6699318081062747564, i64 4, i32 0, i64 -1), !dbg ![[#]] - weight: 121 - factor: 1.00)96; CHECK: 16: %call9 = call i32 @bar(i32 noundef %7), !dbg ![[#]] - weight: 126 - factor: 1.00)97; CHECK: 9: call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 9, i32 0, i64 -1), !dbg ![[#]] - weight: 112 - factor: 1.00)98; CHECK: 10: call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 10, i32 0, i64 -1), !dbg ![[#]] - weight: 112 - factor: 1.00)99; CHECK: 11: call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 11, i32 0, i64 -1), !dbg ![[#]] - weight: 116 - factor: 1.00)100; CHECK: 1: call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 1, i32 0, i64 -1), !dbg ![[#]] - weight: 0 - factor: 1.00)101 102 103@x = dso_local global i32 1, align 4, !dbg !0104 105; Function Attrs: noinline nounwind uwtable106define dso_local i32 @bar(i32 noundef %p) #0 !dbg !16 {107entry:108 call void @llvm.dbg.value(metadata i32 %p, metadata !20, metadata !DIExpression()), !dbg !21109 call void @llvm.pseudoprobe(i64 -2012135647395072713, i64 1, i32 0, i64 -1), !dbg !22110 ret i32 %p, !dbg !23111}112 113; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)114declare void @llvm.dbg.declare(metadata, metadata, metadata) #1115 116; Function Attrs: alwaysinline nounwind uwtable117define dso_local i32 @foo(i32 noundef %i, i32 noundef %p) #2 !dbg !24 {118entry:119 call void @llvm.dbg.value(metadata i32 %i, metadata !28, metadata !DIExpression()), !dbg !30120 call void @llvm.dbg.value(metadata i32 %p, metadata !29, metadata !DIExpression()), !dbg !30121 call void @llvm.pseudoprobe(i64 6699318081062747564, i64 1, i32 0, i64 -1), !dbg !31122 %rem = srem i32 %i, 10, !dbg !33123 %tobool = icmp ne i32 %rem, 0, !dbg !33124 br i1 %tobool, label %if.then, label %if.else, !dbg !34125 126if.then: ; preds = %entry127 call void @llvm.pseudoprobe(i64 6699318081062747564, i64 2, i32 0, i64 -1), !dbg !35128 %call = call i32 @bar(i32 noundef %p), !dbg !36129 br label %return, !dbg !38130 131if.else: ; preds = %entry132 call void @llvm.pseudoprobe(i64 6699318081062747564, i64 3, i32 0, i64 -1), !dbg !39133 %add = add nsw i32 %p, 1, !dbg !40134 %call1 = call i32 @bar(i32 noundef %add), !dbg !41135 br label %return, !dbg !43136 137return: ; preds = %if.else, %if.then138 %retval.0 = phi i32 [ %call, %if.then ], [ %call1, %if.else ], !dbg !44139 call void @llvm.pseudoprobe(i64 6699318081062747564, i64 4, i32 0, i64 -1), !dbg !45140 ret i32 %retval.0, !dbg !45141}142 143; Function Attrs: nounwind uwtable144define dso_local i32 @main() #3 !dbg !46 {145entry:146 call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 1, i32 0, i64 -1), !dbg !52147 %0 = load volatile i32, ptr @x, align 4, !dbg !52, !tbaa !54148 %cmp = icmp eq i32 %0, 0, !dbg !58149 br i1 %cmp, label %if.then, label %if.end, !dbg !59150 151if.then: ; preds = %entry152 call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 2, i32 0, i64 -1), !dbg !60153 br label %for.end, !dbg !60154 155if.end: ; preds = %entry156 call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 3, i32 0, i64 -1), !dbg !61157 call void @llvm.dbg.value(metadata i32 0, metadata !50, metadata !DIExpression()), !dbg !62158 br label %for.cond, !dbg !63159 160for.cond: ; preds = %if.end6, %if.end161 %i.0 = phi i32 [ 0, %if.end ], [ %inc, %if.end6 ], !dbg !64162 call void @llvm.dbg.value(metadata i32 %i.0, metadata !50, metadata !DIExpression()), !dbg !62163 call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 4, i32 0, i64 -1), !dbg !65164 %cmp1 = icmp slt i32 %i.0, 1000000, !dbg !67165 br i1 %cmp1, label %for.body, label %for.cond.cleanup, !dbg !68166 167for.cond.cleanup: ; preds = %for.cond168 call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 5, i32 0, i64 -1), !dbg !68169 br label %cleanup, !dbg !68170 171for.body: ; preds = %for.cond172 call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 6, i32 0, i64 -1), !dbg !69173 %1 = load volatile i32, ptr @x, align 4, !dbg !71, !tbaa !54174 %call = call i32 @foo(i32 noundef %i.0, i32 noundef %1), !dbg !72175 %2 = load volatile i32, ptr @x, align 4, !dbg !74, !tbaa !54176 %add = add nsw i32 %2, %call, !dbg !74177 store volatile i32 %add, ptr @x, align 4, !dbg !74, !tbaa !54178 %3 = load volatile i32, ptr @x, align 4, !dbg !75, !tbaa !54179 %call2 = call i32 @bar(i32 noundef %3), !dbg !76180 %4 = load volatile i32, ptr @x, align 4, !dbg !78, !tbaa !54181 %add3 = add nsw i32 %4, %call2, !dbg !78182 store volatile i32 %add3, ptr @x, align 4, !dbg !78, !tbaa !54183 br i1 false, label %if.then5, label %if.end6, !dbg !79184 185if.then5: ; preds = %for.body186 call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 7, i32 0, i64 -1), !dbg !80187 br label %cleanup, !dbg !80188 189if.end6: ; preds = %for.body190 call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 8, i32 0, i64 -1), !dbg !82191 %5 = load volatile i32, ptr @x, align 4, !dbg !83, !tbaa !54192 %call7 = call i32 @foo(i32 noundef %i.0, i32 noundef %5), !dbg !84193 %6 = load volatile i32, ptr @x, align 4, !dbg !86, !tbaa !54194 %add8 = add nsw i32 %6, %call7, !dbg !86195 store volatile i32 %add8, ptr @x, align 4, !dbg !86, !tbaa !54196 %7 = load volatile i32, ptr @x, align 4, !dbg !87, !tbaa !54197 %call9 = call i32 @bar(i32 noundef %7), !dbg !88198 %8 = load volatile i32, ptr @x, align 4, !dbg !90, !tbaa !54199 %add10 = add nsw i32 %8, %call9, !dbg !90200 store volatile i32 %add10, ptr @x, align 4, !dbg !90, !tbaa !54201 call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 9, i32 0, i64 -1), !dbg !91202 %inc = add nsw i32 %i.0, 1, !dbg !91203 call void @llvm.dbg.value(metadata i32 %inc, metadata !50, metadata !DIExpression()), !dbg !62204 br label %for.cond, !dbg !92, !llvm.loop !93205 206cleanup: ; preds = %if.then5, %for.cond.cleanup207 call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 10, i32 0, i64 -1), !dbg !96208 br label %for.end209 210for.end: ; preds = %cleanup, %if.then211 call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 11, i32 0, i64 -1), !dbg !97212 ret i32 0, !dbg !97213}214 215; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)216declare void @llvm.lifetime.start.p0(ptr nocapture) #4217 218; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite)219declare void @llvm.lifetime.end.p0(ptr nocapture) #4220 221; Function Attrs: mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none)222declare void @llvm.dbg.assign(metadata, metadata, metadata, metadata, metadata, metadata) #1223 224; Function Attrs: mustprogress nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: readwrite)225declare void @llvm.pseudoprobe(i64, i64, i32, i64) #5226 227; Function Attrs: nocallback nofree nosync nounwind speculatable willreturn memory(none)228declare void @llvm.dbg.value(metadata, metadata, metadata) #6229 230attributes #0 = { noinline nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" "use-sample-profile" }231attributes #1 = { mustprogress nocallback nofree nosync nounwind speculatable willreturn memory(none) }232attributes #2 = { alwaysinline nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" "use-sample-profile" }233attributes #3 = { nounwind uwtable "min-legal-vector-width"="0" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" "use-sample-profile" }234attributes #4 = { mustprogress nocallback nofree nosync nounwind willreturn memory(argmem: readwrite) }235attributes #5 = { mustprogress nocallback nofree nosync nounwind willreturn memory(inaccessiblemem: readwrite) }236attributes #6 = { nocallback nofree nosync nounwind speculatable willreturn memory(none) }237 238!llvm.dbg.cu = !{!2}239!llvm.module.flags = !{!7, !8, !9, !10, !11}240!llvm.ident = !{!12}241!llvm.pseudo_probe_desc = !{!13, !14, !15}242 243!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression())244!1 = distinct !DIGlobalVariable(name: "x", scope: !2, file: !3, line: 1, type: !5, isLocal: false, isDefinition: true)245!2 = distinct !DICompileUnit(language: DW_LANG_C11, file: !3, producer: "clang version 17.0.0", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, globals: !4, splitDebugInlining: false, nameTableKind: None)246!3 = !DIFile(filename: "test.c", directory: "path")247!4 = !{!0}248!5 = !DIDerivedType(tag: DW_TAG_volatile_type, baseType: !6)249!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed)250!7 = !{i32 7, !"Dwarf Version", i32 5}251!8 = !{i32 2, !"Debug Info Version", i32 3}252!9 = !{i32 1, !"wchar_size", i32 4}253!10 = !{i32 7, !"uwtable", i32 2}254!11 = !{i32 7, !"debug-info-assignment-tracking", i1 true}255!12 = !{!"clang version 17.0.0"}256!13 = !{i64 -2012135647395072713, i64 4294967295, !"bar"}257!14 = !{i64 6699318081062747564, i64 563022570642068, !"foo"}258!15 = !{i64 -2624081020897602054, i64 1126158552146340, !"main"}259!16 = distinct !DISubprogram(name: "bar", scope: !3, file: !3, line: 2, type: !17, scopeLine: 2, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !19)260!17 = !DISubroutineType(types: !18)261!18 = !{!6, !6}262!19 = !{!20}263!20 = !DILocalVariable(name: "p", arg: 1, scope: !16, file: !3, line: 2, type: !6)264!21 = !DILocation(line: 0, scope: !16)265!22 = !DILocation(line: 3, column: 10, scope: !16)266!23 = !DILocation(line: 3, column: 3, scope: !16)267!24 = distinct !DISubprogram(name: "foo", scope: !3, file: !3, line: 6, type: !25, scopeLine: 6, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !27)268!25 = !DISubroutineType(types: !26)269!26 = !{!6, !6, !6}270!27 = !{!28, !29}271!28 = !DILocalVariable(name: "i", arg: 1, scope: !24, file: !3, line: 6, type: !6)272!29 = !DILocalVariable(name: "p", arg: 2, scope: !24, file: !3, line: 6, type: !6)273!30 = !DILocation(line: 0, scope: !24)274!31 = !DILocation(line: 7, column: 6, scope: !32)275!32 = distinct !DILexicalBlock(scope: !24, file: !3, line: 7, column: 6)276!33 = !DILocation(line: 7, column: 8, scope: !32)277!34 = !DILocation(line: 7, column: 6, scope: !24)278!35 = !DILocation(line: 7, column: 26, scope: !32)279!36 = !DILocation(line: 7, column: 22, scope: !37)280!37 = !DILexicalBlockFile(scope: !32, file: !3, discriminator: 186646575)281!38 = !DILocation(line: 7, column: 14, scope: !32)282!39 = !DILocation(line: 8, column: 19, scope: !32)283!40 = !DILocation(line: 8, column: 21, scope: !32)284!41 = !DILocation(line: 8, column: 15, scope: !42)285!42 = !DILexicalBlockFile(scope: !32, file: !3, discriminator: 186646583)286!43 = !DILocation(line: 8, column: 8, scope: !32)287!44 = !DILocation(line: 0, scope: !32)288!45 = !DILocation(line: 9, column: 1, scope: !24)289!46 = distinct !DISubprogram(name: "main", scope: !3, file: !3, line: 11, type: !47, scopeLine: 11, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !49)290!47 = !DISubroutineType(types: !48)291!48 = !{!6}292!49 = !{!50}293!50 = !DILocalVariable(name: "i", scope: !51, file: !3, line: 14, type: !6)294!51 = distinct !DILexicalBlock(scope: !46, file: !3, line: 14, column: 3)295!52 = !DILocation(line: 12, column: 6, scope: !53)296!53 = distinct !DILexicalBlock(scope: !46, file: !3, line: 12, column: 6)297!54 = !{!55, !55, i64 0}298!55 = !{!"int", !56, i64 0}299!56 = !{!"omnipotent char", !57, i64 0}300!57 = !{!"Simple C/C++ TBAA"}301!58 = !DILocation(line: 12, column: 8, scope: !53)302!59 = !DILocation(line: 12, column: 6, scope: !46)303!60 = !DILocation(line: 13, column: 5, scope: !53)304!61 = !DILocation(line: 14, column: 11, scope: !51)305!62 = !DILocation(line: 0, scope: !51)306!63 = !DILocation(line: 14, column: 7, scope: !51)307!64 = !DILocation(line: 14, scope: !51)308!65 = !DILocation(line: 14, column: 18, scope: !66)309!66 = distinct !DILexicalBlock(scope: !51, file: !3, line: 14, column: 3)310!67 = !DILocation(line: 14, column: 20, scope: !66)311!68 = !DILocation(line: 14, column: 3, scope: !51)312!69 = !DILocation(line: 15, column: 15, scope: !70)313!70 = distinct !DILexicalBlock(scope: !66, file: !3, line: 14, column: 40)314!71 = !DILocation(line: 15, column: 18, scope: !70)315!72 = !DILocation(line: 15, column: 11, scope: !73)316!73 = !DILexicalBlockFile(scope: !70, file: !3, discriminator: 186646639)317!74 = !DILocation(line: 15, column: 8, scope: !70)318!75 = !DILocation(line: 16, column: 15, scope: !70)319!76 = !DILocation(line: 16, column: 11, scope: !77)320!77 = !DILexicalBlockFile(scope: !70, file: !3, discriminator: 186646647)321!78 = !DILocation(line: 16, column: 8, scope: !70)322!79 = !DILocation(line: 17, column: 9, scope: !70)323!80 = !DILocation(line: 18, column: 8, scope: !81)324!81 = distinct !DILexicalBlock(scope: !70, file: !3, line: 17, column: 9)325!82 = !DILocation(line: 19, column: 15, scope: !70)326!83 = !DILocation(line: 19, column: 18, scope: !70)327!84 = !DILocation(line: 19, column: 11, scope: !85)328!85 = !DILexicalBlockFile(scope: !70, file: !3, discriminator: 186646655)329!86 = !DILocation(line: 19, column: 8, scope: !70)330!87 = !DILocation(line: 20, column: 15, scope: !70)331!88 = !DILocation(line: 20, column: 11, scope: !89)332!89 = !DILexicalBlockFile(scope: !70, file: !3, discriminator: 186646663)333!90 = !DILocation(line: 20, column: 8, scope: !70)334!91 = !DILocation(line: 14, column: 36, scope: !66)335!92 = !DILocation(line: 14, column: 3, scope: !66)336!93 = distinct !{!93, !68, !94, !95}337!94 = !DILocation(line: 21, column: 3, scope: !51)338!95 = !{!"llvm.loop.mustprogress"}339!96 = !DILocation(line: 0, scope: !46)340!97 = !DILocation(line: 22, column: 1, scope: !46)341