1; REQUIRES: x86_64-linux 2; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/pseudo-probe-profile-mismatch.prof -report-profile-staleness -persist-profile-staleness -S 2>%t -o %t.ll 3; RUN: FileCheck %s --input-file %t 4; RUN: FileCheck %s --input-file %t.ll -check-prefix=CHECK-MD 5; RUN: llc < %t.ll -filetype=obj -o %t.obj 6; RUN: llvm-objdump --section-headers %t.obj | FileCheck %s --check-prefix=CHECK-OBJ 7; RUN: llc < %t.ll -filetype=asm -o - | FileCheck %s --check-prefix=CHECK-ASM 8 9; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/pseudo-probe-profile-mismatch-nested.prof -report-profile-staleness -persist-profile-staleness -S 2>&1 | FileCheck %s --check-prefix=CHECK-NESTED 10 11 12; CHECK: (2/3) of functions' profile are invalid and (40/50) of samples are discarded due to function hash mismatch. 13; CHECK: (2/3) of callsites' profile are invalid and (20/50) of samples are discarded due to callsite location mismatch. 14; CHECK: (1/2) of callsites and (10/20) of samples are recovered by stale profile matching. 15 16; CHECK-MD: ![[#]] = !{!"NumStaleProfileFunc", i64 2, !"TotalProfiledFunc", i64 3, !"MismatchedFunctionSamples", i64 40, !"TotalFunctionSamples", i64 50, !"NumMismatchedCallsites", i64 1, !"NumRecoveredCallsites", i64 1, !"TotalProfiledCallsites", i64 3, !"MismatchedCallsiteSamples", i64 10, !"RecoveredCallsiteSamples", i64 10} 17 18 19; CHECK-OBJ: .llvm_stats 20 21; CHECK-ASM: .section .llvm_stats,"",@progbits 22; CHECK-ASM: .byte 19 23; CHECK-ASM: .ascii "NumStaleProfileFunc" 24; CHECK-ASM: .byte 4 25; CHECK-ASM: .ascii "Mg==" 26; CHECK-ASM: .byte 17 27; CHECK-ASM: .ascii "TotalProfiledFunc" 28; CHECK-ASM: .byte 4 29; CHECK-ASM: .ascii "Mw==" 30; CHECK-ASM: .byte 25 31; CHECK-ASM: .ascii "MismatchedFunctionSamples" 32; CHECK-ASM: .byte 4 33; CHECK-ASM: .ascii "NDA=" 34; CHECK-ASM: .byte 20 35; CHECK-ASM: .ascii "TotalFunctionSamples" 36; CHECK-ASM: .byte 4 37; CHECK-ASM: .ascii "NTA=" 38; CHECK-ASM: .byte 22 39; CHECK-ASM: .ascii "NumMismatchedCallsites" 40; CHECK-ASM: .byte 4 41; CHECK-ASM: .ascii "MQ==" 42; CHECK-ASM: .byte 21 43; CHECK-ASM: .ascii "NumRecoveredCallsites" 44; CHECK-ASM: .byte 4 45; CHECK-ASM: .ascii "MQ==" 46; CHECK-ASM: .byte 22 47; CHECK-ASM: .ascii "TotalProfiledCallsites" 48; CHECK-ASM: .byte 4 49; CHECK-ASM: .ascii "Mw==" 50; CHECK-ASM: .byte 25 51; CHECK-ASM: .ascii "MismatchedCallsiteSamples" 52; CHECK-ASM: .byte 4 53; CHECK-ASM: .ascii "MTA=" 54; CHECK-ASM: .byte 24 55; CHECK-ASM: .ascii "RecoveredCallsiteSamples" 56; CHECK-ASM: .byte 4 57; CHECK-ASM: .ascii "MTA=" 58 59 60; CHECK-NESTED: (1/2) of functions' profile are invalid and (211/311) of samples are discarded due to function hash mismatch. 61 62 63target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 64target triple = "x86_64-unknown-linux-gnu" 65 66@x = dso_local global i32 0, align 4, !dbg !0 67 68; Function Attrs: nounwind uwtable 69define dso_local i32 @foo(i32 noundef %x) #0 !dbg !16 { 70entry: 71 %y = alloca i32, align 4 72 call void @llvm.dbg.value(metadata i32 %x, metadata !20, metadata !DIExpression()), !dbg !22 73 call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %y), !dbg !23 74 call void @llvm.dbg.declare(metadata ptr %y, metadata !21, metadata !DIExpression()), !dbg !24 75 call void @llvm.pseudoprobe(i64 6699318081062747564, i64 1, i32 0, i64 -1), !dbg !25 76 %add = add nsw i32 %x, 1, !dbg !26 77 store volatile i32 %add, ptr %y, align 4, !dbg !24, !tbaa !27 78 %y.0. = load volatile i32, ptr %y, align 4, !dbg !31, !tbaa !27 79 %add1 = add nsw i32 %y.0., 1, !dbg !32 80 call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %y), !dbg !33 81 ret i32 %add1, !dbg !34 82} 83 84; Function Attrs: mustprogress nocallback nofree nosync nounwind readnone speculatable willreturn 85declare void @llvm.dbg.declare(metadata, metadata, metadata) #1 86 87; Function Attrs: argmemonly mustprogress nocallback nofree nosync nounwind willreturn 88declare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2 89 90; Function Attrs: argmemonly mustprogress nocallback nofree nosync nounwind willreturn 91declare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2 92 93; Function Attrs: noinline nounwind uwtable 94define dso_local i32 @bar(i32 noundef %x) #3 !dbg !35 { 95entry: 96 call void @llvm.dbg.value(metadata i32 %x, metadata !37, metadata !DIExpression()), !dbg !38 97 call void @llvm.pseudoprobe(i64 -2012135647395072713, i64 1, i32 0, i64 -1), !dbg !39 98 %add = add nsw i32 %x, 2, !dbg !40 99 ret i32 %add, !dbg !41 100} 101 102; Function Attrs: noinline nounwind uwtable 103define dso_local i32 @matched(i32 noundef %x) #3 !dbg !42 { 104entry: 105 call void @llvm.dbg.value(metadata i32 %x, metadata !44, metadata !DIExpression()), !dbg !45 106 call void @llvm.pseudoprobe(i64 -5844448289301669773, i64 1, i32 0, i64 -1), !dbg !46 107 %add = add nsw i32 %x, 3, !dbg !47 108 ret i32 %add, !dbg !48 109} 110 111; Function Attrs: nounwind uwtable 112define dso_local i32 @main() #0 !dbg !49 { 113entry: 114 call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 1, i32 0, i64 -1), !dbg !59 115 call void @llvm.dbg.value(metadata i32 0, metadata !53, metadata !DIExpression()), !dbg !60 116 br label %for.cond, !dbg !61 117 118for.cond: ; preds = %for.cond.cleanup3, %entry 119 %i.0 = phi i32 [ 0, %entry ], [ %inc8, %for.cond.cleanup3 ], !dbg !60 120 call void @llvm.dbg.value(metadata i32 %i.0, metadata !53, metadata !DIExpression()), !dbg !60 121 call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 2, i32 0, i64 -1), !dbg !62 122 %cmp = icmp ult i32 %i.0, 1000, !dbg !64 123 br i1 %cmp, label %for.body, label %for.cond.cleanup, !dbg !65 124 125for.cond.cleanup: ; preds = %for.cond 126 call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 3, i32 0, i64 -1), !dbg !67 127 call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 11, i32 0, i64 -1), !dbg !68 128 ret i32 0, !dbg !68 129 130for.body: ; preds = %for.cond 131 call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 4, i32 0, i64 -1), !dbg !69 132 call void @llvm.dbg.value(metadata i32 0, metadata !55, metadata !DIExpression()), !dbg !70 133 br label %for.cond1, !dbg !71 134 135for.cond1: ; preds = %for.body4, %for.body 136 %a.0 = phi i32 [ 0, %for.body ], [ %inc, %for.body4 ], !dbg !70 137 call void @llvm.dbg.value(metadata i32 %a.0, metadata !55, metadata !DIExpression()), !dbg !70 138 call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 5, i32 0, i64 -1), !dbg !72 139 %cmp2 = icmp ult i32 %a.0, 10000, !dbg !75 140 br i1 %cmp2, label %for.body4, label %for.cond.cleanup3, !dbg !76 141 142for.cond.cleanup3: ; preds = %for.cond1 143 call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 6, i32 0, i64 -1), !dbg !67 144 call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 9, i32 0, i64 -1), !dbg !78 145 call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 10, i32 0, i64 -1), !dbg !79 146 %inc8 = add nuw nsw i32 %i.0, 1, !dbg !79 147 call void @llvm.dbg.value(metadata i32 %inc8, metadata !53, metadata !DIExpression()), !dbg !60 148 br label %for.cond, !dbg !81, !llvm.loop !82 149 150for.body4: ; preds = %for.cond1 151 call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 7, i32 0, i64 -1), !dbg !86 152 %0 = load volatile i32, ptr @x, align 4, !dbg !86, !tbaa !27 153 %call = call i32 @matched(i32 noundef %0), !dbg !88 154 store volatile i32 %call, ptr @x, align 4, !dbg !90, !tbaa !27 155 %1 = load volatile i32, ptr @x, align 4, !dbg !91, !tbaa !27 156 %call5 = call i32 @foo(i32 noundef %1), !dbg !92 157 store volatile i32 %call5, ptr @x, align 4, !dbg !94, !tbaa !27 158 %2 = load volatile i32, ptr @x, align 4, !dbg !95, !tbaa !27 159 %call6 = call i32 @bar(i32 noundef %2), !dbg !96 160 store volatile i32 %call6, ptr @x, align 4, !dbg !98, !tbaa !27 161 call void @llvm.pseudoprobe(i64 -2624081020897602054, i64 8, i32 0, i64 -1), !dbg !99 162 %inc = add nuw nsw i32 %a.0, 1, !dbg !99 163 call void @llvm.dbg.value(metadata i32 %inc, metadata !55, metadata !DIExpression()), !dbg !70 164 br label %for.cond1, !dbg !101, !llvm.loop !102 165} 166 167; Function Attrs: inaccessiblememonly mustprogress nocallback nofree nosync nounwind willreturn 168declare void @llvm.pseudoprobe(i64, i64, i32, i64) #4 169 170; Function Attrs: nocallback nofree nosync nounwind readnone speculatable willreturn 171declare void @llvm.dbg.value(metadata, metadata, metadata) #5 172 173attributes #0 = { nounwind uwtable "frame-pointer"="none" "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" } 174attributes #1 = { mustprogress nocallback nofree nosync nounwind readnone speculatable willreturn } 175attributes #2 = { argmemonly mustprogress nocallback nofree nosync nounwind willreturn } 176attributes #3 = { noinline nounwind uwtable "frame-pointer"="none" "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" } 177attributes #4 = { inaccessiblememonly mustprogress nocallback nofree nosync nounwind willreturn } 178attributes #5 = { nocallback nofree nosync nounwind readnone speculatable willreturn } 179 180!llvm.dbg.cu = !{!2} 181!llvm.module.flags = !{!7, !8, !9, !10} 182!llvm.ident = !{!11} 183!llvm.pseudo_probe_desc = !{!12, !13, !14, !15} 184 185!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) 186!1 = distinct !DIGlobalVariable(name: "x", scope: !2, file: !3, line: 1, type: !5, isLocal: false, isDefinition: true) 187!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, globals: !4, splitDebugInlining: false, debugInfoForProfiling: true, nameTableKind: None) 188!3 = !DIFile(filename: "test.c", directory: "") 189!4 = !{!0} 190!5 = !DIDerivedType(tag: DW_TAG_volatile_type, baseType: !6) 191!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 192!7 = !{i32 7, !"Dwarf Version", i32 5} 193!8 = !{i32 2, !"Debug Info Version", i32 3} 194!9 = !{i32 1, !"wchar_size", i32 4} 195!10 = !{i32 7, !"uwtable", i32 2} 196!11 = !{!""} 197!12 = !{i64 6699318081062747564, i64 4294967295, !"foo"} 198!13 = !{i64 -2012135647395072713, i64 4294967295, !"bar"} 199!14 = !{i64 -5844448289301669773, i64 4294967295, !"matched"} 200!15 = !{i64 -2624081020897602054, i64 844635331715433, !"main"} 201!16 = distinct !DISubprogram(name: "foo", scope: !3, file: !3, line: 2, type: !17, scopeLine: 2, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !19) 202!17 = !DISubroutineType(types: !18) 203!18 = !{!6, !6} 204!19 = !{!20, !21} 205!20 = !DILocalVariable(name: "x", arg: 1, scope: !16, file: !3, line: 2, type: !6) 206!21 = !DILocalVariable(name: "y", scope: !16, file: !3, line: 3, type: !5) 207!22 = !DILocation(line: 0, scope: !16) 208!23 = !DILocation(line: 3, column: 3, scope: !16) 209!24 = !DILocation(line: 3, column: 16, scope: !16) 210!25 = !DILocation(line: 3, column: 20, scope: !16) 211!26 = !DILocation(line: 3, column: 22, scope: !16) 212!27 = !{!28, !28, i64 0} 213!28 = !{!"int", !29, i64 0} 214!29 = !{!"omnipotent char", !30, i64 0} 215!30 = !{!"Simple C/C++ TBAA"} 216!31 = !DILocation(line: 4, column: 10, scope: !16) 217!32 = !DILocation(line: 4, column: 12, scope: !16) 218!33 = !DILocation(line: 5, column: 1, scope: !16) 219!34 = !DILocation(line: 4, column: 3, scope: !16) 220!35 = distinct !DISubprogram(name: "bar", scope: !3, file: !3, line: 7, type: !17, scopeLine: 7, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !36) 221!36 = !{!37} 222!37 = !DILocalVariable(name: "x", arg: 1, scope: !35, file: !3, line: 7, type: !6) 223!38 = !DILocation(line: 0, scope: !35) 224!39 = !DILocation(line: 8, column: 10, scope: !35) 225!40 = !DILocation(line: 8, column: 12, scope: !35) 226!41 = !DILocation(line: 8, column: 3, scope: !35) 227!42 = distinct !DISubprogram(name: "matched", scope: !3, file: !3, line: 11, type: !17, scopeLine: 11, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !43) 228!43 = !{!44} 229!44 = !DILocalVariable(name: "x", arg: 1, scope: !42, file: !3, line: 11, type: !6) 230!45 = !DILocation(line: 0, scope: !42) 231!46 = !DILocation(line: 12, column: 10, scope: !42) 232!47 = !DILocation(line: 12, column: 12, scope: !42) 233!48 = !DILocation(line: 12, column: 3, scope: !42) 234!49 = distinct !DISubprogram(name: "main", scope: !3, file: !3, line: 15, type: !50, scopeLine: 15, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !52) 235!50 = !DISubroutineType(types: !51) 236!51 = !{!6} 237!52 = !{!53, !55} 238!53 = !DILocalVariable(name: "i", scope: !54, file: !3, line: 16, type: !6) 239!54 = distinct !DILexicalBlock(scope: !49, file: !3, line: 16, column: 3) 240!55 = !DILocalVariable(name: "a", scope: !56, file: !3, line: 17, type: !6) 241!56 = distinct !DILexicalBlock(scope: !57, file: !3, line: 17, column: 5) 242!57 = distinct !DILexicalBlock(scope: !58, file: !3, line: 16, column: 34) 243!58 = distinct !DILexicalBlock(scope: !54, file: !3, line: 16, column: 3) 244!59 = !DILocation(line: 16, column: 12, scope: !54) 245!60 = !DILocation(line: 0, scope: !54) 246!61 = !DILocation(line: 16, column: 8, scope: !54) 247!62 = !DILocation(line: 16, column: 19, scope: !63) 248!63 = !DILexicalBlockFile(scope: !58, file: !3, discriminator: 0) 249!64 = !DILocation(line: 16, column: 21, scope: !63) 250!65 = !DILocation(line: 16, column: 3, scope: !66) 251!66 = !DILexicalBlockFile(scope: !54, file: !3, discriminator: 0) 252!67 = !DILocation(line: 0, scope: !49) 253!68 = !DILocation(line: 23, column: 1, scope: !49) 254!69 = !DILocation(line: 17, column: 14, scope: !56) 255!70 = !DILocation(line: 0, scope: !56) 256!71 = !DILocation(line: 17, column: 10, scope: !56) 257!72 = !DILocation(line: 17, column: 21, scope: !73) 258!73 = !DILexicalBlockFile(scope: !74, file: !3, discriminator: 0) 259!74 = distinct !DILexicalBlock(scope: !56, file: !3, line: 17, column: 5) 260!75 = !DILocation(line: 17, column: 23, scope: !73) 261!76 = !DILocation(line: 17, column: 5, scope: !77) 262!77 = !DILexicalBlockFile(scope: !56, file: !3, discriminator: 0) 263!78 = !DILocation(line: 22, column: 3, scope: !57) 264!79 = !DILocation(line: 16, column: 30, scope: !80) 265!80 = !DILexicalBlockFile(scope: !58, file: !3, discriminator: 0) 266!81 = !DILocation(line: 16, column: 3, scope: !80) 267!82 = distinct !{!82, !83, !84, !85} 268!83 = !DILocation(line: 16, column: 3, scope: !54) 269!84 = !DILocation(line: 22, column: 3, scope: !54) 270!85 = !{!"llvm.loop.mustprogress"} 271!86 = !DILocation(line: 18, column: 19, scope: !87) 272!87 = distinct !DILexicalBlock(scope: !74, file: !3, line: 17, column: 37) 273!88 = !DILocation(line: 18, column: 11, scope: !89) 274!89 = !DILexicalBlockFile(scope: !87, file: !3, discriminator: 186646631) 275!90 = !DILocation(line: 18, column: 9, scope: !87) 276!91 = !DILocation(line: 19, column: 15, scope: !87) 277!92 = !DILocation(line: 19, column: 11, scope: !93) 278!93 = !DILexicalBlockFile(scope: !87, file: !3, discriminator: 186646639) 279!94 = !DILocation(line: 19, column: 9, scope: !87) 280!95 = !DILocation(line: 20, column: 15, scope: !87) 281!96 = !DILocation(line: 20, column: 11, scope: !97) 282!97 = !DILexicalBlockFile(scope: !87, file: !3, discriminator: 186646647) 283!98 = !DILocation(line: 20, column: 9, scope: !87) 284!99 = !DILocation(line: 17, column: 33, scope: !100) 285!100 = !DILexicalBlockFile(scope: !74, file: !3, discriminator: 0) 286!101 = !DILocation(line: 17, column: 5, scope: !100) 287!102 = distinct !{!102, !103, !104, !85} 288!103 = !DILocation(line: 17, column: 5, scope: !56) 289!104 = !DILocation(line: 21, column: 5, scope: !56) 290