118df04c9Swlei; REQUIRES: x86_64-linux 262a3f6c9Swlei; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/profile-mismatch.prof -report-profile-staleness -persist-profile-staleness -S 2>%t -o %t.ll 3d6a0585dSwlei; RUN: FileCheck %s --input-file %t 447b07580Swlei; RUN: FileCheck %s --input-file %t.ll -check-prefix=CHECK-MD 547b07580Swlei; RUN: llc < %t.ll -filetype=obj -o %t.obj 647b07580Swlei; RUN: llvm-objdump --section-headers %t.obj | FileCheck %s --check-prefix=CHECK-OBJ 797e2aeabSwlei; RUN: llc < %t.ll -filetype=asm -o - | FileCheck %s --check-prefix=CHECK-ASM 8d6a0585dSwlei 9*c98da372SLei Wang; CHECK: (1/3) of callsites' profile are invalid and (15/50) of samples are discarded due to callsite location mismatch. 10d6a0585dSwlei 11*c98da372SLei Wang; CHECK-MD: ![[#]] = !{!"NumMismatchedCallsites", i64 1, !"NumRecoveredCallsites", i64 0, !"TotalProfiledCallsites", i64 3, !"MismatchedCallsiteSamples", i64 15, !"RecoveredCallsiteSamples", i64 0} 1247b07580Swlei 1347b07580Swlei; CHECK-OBJ: .llvm_stats 1447b07580Swlei 1597e2aeabSwlei; CHECK-ASM: .ascii "NumMismatchedCallsites" 1697e2aeabSwlei; CHECK-ASM: .byte 4 17*c98da372SLei Wang; CHECK-ASM: .ascii "MQ==" 18*c98da372SLei Wang; CHECK-ASM: .byte 21 19*c98da372SLei Wang; CHECK-ASM: .ascii "NumRecoveredCallsites" 20*c98da372SLei Wang; CHECK-ASM: .byte 4 21*c98da372SLei Wang; CHECK-ASM: .ascii "MA==" 2297e2aeabSwlei; CHECK-ASM: .byte 22 2397e2aeabSwlei; CHECK-ASM: .ascii "TotalProfiledCallsites" 2497e2aeabSwlei; CHECK-ASM: .byte 4 2597e2aeabSwlei; CHECK-ASM: .ascii "Mw==" 2697e2aeabSwlei; CHECK-ASM: .byte 25 2797e2aeabSwlei; CHECK-ASM: .ascii "MismatchedCallsiteSamples" 2897e2aeabSwlei; CHECK-ASM: .byte 4 29*c98da372SLei Wang; CHECK-ASM: .ascii "MTU=" 30*c98da372SLei Wang; CHECK-ASM: .byte 24 31*c98da372SLei Wang; CHECK-ASM: .ascii "RecoveredCallsiteSamples" 3297e2aeabSwlei; CHECK-ASM: .byte 4 33*c98da372SLei Wang; CHECK-ASM: .ascii "MA==" 34*c98da372SLei Wang 3597e2aeabSwlei 36d6a0585dSwleitarget datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16:32:64-S128" 37d6a0585dSwleitarget triple = "x86_64-unknown-linux-gnu" 38d6a0585dSwlei 39d6a0585dSwlei@x = dso_local global i32 0, align 4, !dbg !0 40d6a0585dSwlei 41d6a0585dSwlei; Function Attrs: nounwind uwtable 42d6a0585dSwleidefine dso_local i32 @foo(i32 noundef %x) #0 !dbg !12 { 43d6a0585dSwleientry: 44d6a0585dSwlei %y = alloca i32, align 4 45d6a0585dSwlei call void @llvm.dbg.value(metadata i32 %x, metadata !16, metadata !DIExpression()), !dbg !18 46d6a0585dSwlei call void @llvm.lifetime.start.p0(i64 4, ptr nonnull %y), !dbg !19 47d6a0585dSwlei call void @llvm.dbg.declare(metadata ptr %y, metadata !17, metadata !DIExpression()), !dbg !20 48d6a0585dSwlei %add = add nsw i32 %x, 1, !dbg !21 49d6a0585dSwlei store volatile i32 %add, ptr %y, align 4, !dbg !20, !tbaa !22 50d6a0585dSwlei %y.0. = load volatile i32, ptr %y, align 4, !dbg !26, !tbaa !22 51d6a0585dSwlei %add1 = add nsw i32 %y.0., 1, !dbg !27 52d6a0585dSwlei call void @llvm.lifetime.end.p0(i64 4, ptr nonnull %y), !dbg !28 53d6a0585dSwlei ret i32 %add1, !dbg !29 54d6a0585dSwlei} 55d6a0585dSwlei 56d6a0585dSwlei; Function Attrs: mustprogress nocallback nofree nosync nounwind readnone speculatable willreturn 57d6a0585dSwleideclare void @llvm.dbg.declare(metadata, metadata, metadata) #1 58d6a0585dSwlei 59d6a0585dSwlei; Function Attrs: argmemonly mustprogress nocallback nofree nosync nounwind willreturn 60d6a0585dSwleideclare void @llvm.lifetime.start.p0(i64 immarg, ptr nocapture) #2 61d6a0585dSwlei 62d6a0585dSwlei; Function Attrs: argmemonly mustprogress nocallback nofree nosync nounwind willreturn 63d6a0585dSwleideclare void @llvm.lifetime.end.p0(i64 immarg, ptr nocapture) #2 64d6a0585dSwlei 65d6a0585dSwlei; Function Attrs: noinline nounwind uwtable 66d6a0585dSwleidefine dso_local i32 @bar(i32 noundef %x) #3 !dbg !30 { 67d6a0585dSwleientry: 68d6a0585dSwlei call void @llvm.dbg.value(metadata i32 %x, metadata !32, metadata !DIExpression()), !dbg !33 69d6a0585dSwlei %add = add nsw i32 %x, 2, !dbg !34 70d6a0585dSwlei ret i32 %add, !dbg !35 71d6a0585dSwlei} 72d6a0585dSwlei 73d6a0585dSwlei; Function Attrs: noinline nounwind uwtable 74d6a0585dSwleidefine dso_local i32 @matched(i32 noundef %x) #3 !dbg !36 { 75d6a0585dSwleientry: 76d6a0585dSwlei call void @llvm.dbg.value(metadata i32 %x, metadata !38, metadata !DIExpression()), !dbg !39 77d6a0585dSwlei %add = add nsw i32 %x, 3, !dbg !40 78d6a0585dSwlei ret i32 %add, !dbg !41 79d6a0585dSwlei} 80d6a0585dSwlei 81d6a0585dSwlei; Function Attrs: nounwind uwtable 82d6a0585dSwleidefine dso_local i32 @main() #0 !dbg !42 { 83d6a0585dSwleientry: 84d6a0585dSwlei call void @llvm.dbg.value(metadata i32 0, metadata !46, metadata !DIExpression()), !dbg !52 85d6a0585dSwlei br label %for.cond, !dbg !53 86d6a0585dSwlei 87d6a0585dSwleifor.cond: ; preds = %for.cond.cleanup3, %entry 88d6a0585dSwlei %i.0 = phi i32 [ 0, %entry ], [ %inc8, %for.cond.cleanup3 ], !dbg !52 89d6a0585dSwlei call void @llvm.dbg.value(metadata i32 %i.0, metadata !46, metadata !DIExpression()), !dbg !52 90d6a0585dSwlei %cmp = icmp ult i32 %i.0, 1000, !dbg !54 91d6a0585dSwlei br i1 %cmp, label %for.body, label %for.cond.cleanup, !dbg !56 92d6a0585dSwlei 93d6a0585dSwleifor.cond.cleanup: ; preds = %for.cond 94d6a0585dSwlei ret i32 0, !dbg !58 95d6a0585dSwlei 96d6a0585dSwleifor.body: ; preds = %for.cond 97d6a0585dSwlei call void @llvm.dbg.value(metadata i32 0, metadata !48, metadata !DIExpression()), !dbg !59 98d6a0585dSwlei br label %for.cond1, !dbg !60 99d6a0585dSwlei 100d6a0585dSwleifor.cond1: ; preds = %for.body4, %for.body 101d6a0585dSwlei %a.0 = phi i32 [ 0, %for.body ], [ %inc, %for.body4 ], !dbg !59 102d6a0585dSwlei call void @llvm.dbg.value(metadata i32 %a.0, metadata !48, metadata !DIExpression()), !dbg !59 103d6a0585dSwlei %cmp2 = icmp ult i32 %a.0, 10000, !dbg !61 104d6a0585dSwlei br i1 %cmp2, label %for.body4, label %for.cond.cleanup3, !dbg !64 105d6a0585dSwlei 106d6a0585dSwleifor.cond.cleanup3: ; preds = %for.cond1 107d6a0585dSwlei %inc8 = add nuw nsw i32 %i.0, 1, !dbg !66 108d6a0585dSwlei call void @llvm.dbg.value(metadata i32 %inc8, metadata !46, metadata !DIExpression()), !dbg !52 109d6a0585dSwlei br label %for.cond, !dbg !68, !llvm.loop !69 110d6a0585dSwlei 111d6a0585dSwleifor.body4: ; preds = %for.cond1 112d6a0585dSwlei %0 = load volatile i32, ptr @x, align 4, !dbg !73, !tbaa !22 113d6a0585dSwlei %call = call i32 @matched(i32 noundef %0), !dbg !75 114d6a0585dSwlei store volatile i32 %call, ptr @x, align 4, !dbg !76, !tbaa !22 115d6a0585dSwlei %1 = load volatile i32, ptr @x, align 4, !dbg !77, !tbaa !22 116d6a0585dSwlei %call5 = call i32 @foo(i32 noundef %1), !dbg !78 117d6a0585dSwlei store volatile i32 %call5, ptr @x, align 4, !dbg !79, !tbaa !22 118d6a0585dSwlei %2 = load volatile i32, ptr @x, align 4, !dbg !80, !tbaa !22 119d6a0585dSwlei %call6 = call i32 @bar(i32 noundef %2), !dbg !81 120d6a0585dSwlei store volatile i32 %call6, ptr @x, align 4, !dbg !82, !tbaa !22 121d6a0585dSwlei %inc = add nuw nsw i32 %a.0, 1, !dbg !83 122d6a0585dSwlei call void @llvm.dbg.value(metadata i32 %inc, metadata !48, metadata !DIExpression()), !dbg !59 123d6a0585dSwlei br label %for.cond1, !dbg !85, !llvm.loop !86 124d6a0585dSwlei} 125d6a0585dSwlei 126d6a0585dSwlei; Function Attrs: nocallback nofree nosync nounwind readnone speculatable willreturn 127d6a0585dSwleideclare void @llvm.dbg.value(metadata, metadata, metadata) #4 128d6a0585dSwlei 129d6a0585dSwleiattributes #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" } 130d6a0585dSwleiattributes #1 = { mustprogress nocallback nofree nosync nounwind readnone speculatable willreturn } 131d6a0585dSwleiattributes #2 = { argmemonly mustprogress nocallback nofree nosync nounwind willreturn } 132d6a0585dSwleiattributes #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" } 133d6a0585dSwleiattributes #4 = { nocallback nofree nosync nounwind readnone speculatable willreturn } 134d6a0585dSwlei 135d6a0585dSwlei!llvm.dbg.cu = !{!2} 136d6a0585dSwlei!llvm.module.flags = !{!7, !8, !9, !10} 137d6a0585dSwlei!llvm.ident = !{!11} 138d6a0585dSwlei 139d6a0585dSwlei!0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) 140d6a0585dSwlei!1 = distinct !DIGlobalVariable(name: "x", scope: !2, file: !3, line: 1, type: !5, isLocal: false, isDefinition: true) 141d6a0585dSwlei!2 = distinct !DICompileUnit(language: DW_LANG_C99, file: !3, producer: "clang", isOptimized: true, runtimeVersion: 0, emissionKind: FullDebug, globals: !4, splitDebugInlining: false, debugInfoForProfiling: true, nameTableKind: None) 142d6a0585dSwlei!3 = !DIFile(filename: "test.c", directory: "test") 143d6a0585dSwlei!4 = !{!0} 144d6a0585dSwlei!5 = !DIDerivedType(tag: DW_TAG_volatile_type, baseType: !6) 145d6a0585dSwlei!6 = !DIBasicType(name: "int", size: 32, encoding: DW_ATE_signed) 146d6a0585dSwlei!7 = !{i32 7, !"Dwarf Version", i32 5} 147d6a0585dSwlei!8 = !{i32 2, !"Debug Info Version", i32 3} 148d6a0585dSwlei!9 = !{i32 1, !"wchar_size", i32 4} 149d6a0585dSwlei!10 = !{i32 7, !"uwtable", i32 2} 150d6a0585dSwlei!11 = !{!""} 151d6a0585dSwlei!12 = distinct !DISubprogram(name: "foo", scope: !3, file: !3, line: 2, type: !13, scopeLine: 2, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !15) 152d6a0585dSwlei!13 = !DISubroutineType(types: !14) 153d6a0585dSwlei!14 = !{!6, !6} 154d6a0585dSwlei!15 = !{!16, !17} 155d6a0585dSwlei!16 = !DILocalVariable(name: "x", arg: 1, scope: !12, file: !3, line: 2, type: !6) 156d6a0585dSwlei!17 = !DILocalVariable(name: "y", scope: !12, file: !3, line: 3, type: !5) 157d6a0585dSwlei!18 = !DILocation(line: 0, scope: !12) 158d6a0585dSwlei!19 = !DILocation(line: 3, column: 3, scope: !12) 159d6a0585dSwlei!20 = !DILocation(line: 3, column: 16, scope: !12) 160d6a0585dSwlei!21 = !DILocation(line: 3, column: 22, scope: !12) 161d6a0585dSwlei!22 = !{!23, !23, i64 0} 162d6a0585dSwlei!23 = !{!"int", !24, i64 0} 163d6a0585dSwlei!24 = !{!"omnipotent char", !25, i64 0} 164d6a0585dSwlei!25 = !{!"Simple C/C++ TBAA"} 165d6a0585dSwlei!26 = !DILocation(line: 4, column: 10, scope: !12) 166d6a0585dSwlei!27 = !DILocation(line: 4, column: 12, scope: !12) 167d6a0585dSwlei!28 = !DILocation(line: 5, column: 1, scope: !12) 168d6a0585dSwlei!29 = !DILocation(line: 4, column: 3, scope: !12) 169d6a0585dSwlei!30 = distinct !DISubprogram(name: "bar", scope: !3, file: !3, line: 7, type: !13, scopeLine: 7, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !31) 170d6a0585dSwlei!31 = !{!32} 171d6a0585dSwlei!32 = !DILocalVariable(name: "x", arg: 1, scope: !30, file: !3, line: 7, type: !6) 172d6a0585dSwlei!33 = !DILocation(line: 0, scope: !30) 173d6a0585dSwlei!34 = !DILocation(line: 8, column: 12, scope: !30) 174d6a0585dSwlei!35 = !DILocation(line: 8, column: 3, scope: !30) 175d6a0585dSwlei!36 = distinct !DISubprogram(name: "matched", scope: !3, file: !3, line: 11, type: !13, scopeLine: 11, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !37) 176d6a0585dSwlei!37 = !{!38} 177d6a0585dSwlei!38 = !DILocalVariable(name: "x", arg: 1, scope: !36, file: !3, line: 11, type: !6) 178d6a0585dSwlei!39 = !DILocation(line: 0, scope: !36) 179d6a0585dSwlei!40 = !DILocation(line: 12, column: 12, scope: !36) 180d6a0585dSwlei!41 = !DILocation(line: 12, column: 3, scope: !36) 181d6a0585dSwlei!42 = distinct !DISubprogram(name: "main", scope: !3, file: !3, line: 15, type: !43, scopeLine: 15, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !2, retainedNodes: !45) 182d6a0585dSwlei!43 = !DISubroutineType(types: !44) 183d6a0585dSwlei!44 = !{!6} 184d6a0585dSwlei!45 = !{!46, !48} 185d6a0585dSwlei!46 = !DILocalVariable(name: "i", scope: !47, file: !3, line: 16, type: !6) 186d6a0585dSwlei!47 = distinct !DILexicalBlock(scope: !42, file: !3, line: 16, column: 3) 187d6a0585dSwlei!48 = !DILocalVariable(name: "a", scope: !49, file: !3, line: 17, type: !6) 188d6a0585dSwlei!49 = distinct !DILexicalBlock(scope: !50, file: !3, line: 17, column: 5) 189d6a0585dSwlei!50 = distinct !DILexicalBlock(scope: !51, file: !3, line: 16, column: 34) 190d6a0585dSwlei!51 = distinct !DILexicalBlock(scope: !47, file: !3, line: 16, column: 3) 191d6a0585dSwlei!52 = !DILocation(line: 0, scope: !47) 192d6a0585dSwlei!53 = !DILocation(line: 16, column: 8, scope: !47) 193d6a0585dSwlei!54 = !DILocation(line: 16, column: 21, scope: !55) 194d6a0585dSwlei!55 = !DILexicalBlockFile(scope: !51, file: !3, discriminator: 2) 195d6a0585dSwlei!56 = !DILocation(line: 16, column: 3, scope: !57) 196d6a0585dSwlei!57 = !DILexicalBlockFile(scope: !47, file: !3, discriminator: 2) 197d6a0585dSwlei!58 = !DILocation(line: 23, column: 1, scope: !42) 198d6a0585dSwlei!59 = !DILocation(line: 0, scope: !49) 199d6a0585dSwlei!60 = !DILocation(line: 17, column: 10, scope: !49) 200d6a0585dSwlei!61 = !DILocation(line: 17, column: 23, scope: !62) 201d6a0585dSwlei!62 = !DILexicalBlockFile(scope: !63, file: !3, discriminator: 2) 202d6a0585dSwlei!63 = distinct !DILexicalBlock(scope: !49, file: !3, line: 17, column: 5) 203d6a0585dSwlei!64 = !DILocation(line: 17, column: 5, scope: !65) 204d6a0585dSwlei!65 = !DILexicalBlockFile(scope: !49, file: !3, discriminator: 2) 205d6a0585dSwlei!66 = !DILocation(line: 16, column: 30, scope: !67) 206d6a0585dSwlei!67 = !DILexicalBlockFile(scope: !51, file: !3, discriminator: 4) 207d6a0585dSwlei!68 = !DILocation(line: 16, column: 3, scope: !67) 208d6a0585dSwlei!69 = distinct !{!69, !70, !71, !72} 209d6a0585dSwlei!70 = !DILocation(line: 16, column: 3, scope: !47) 210d6a0585dSwlei!71 = !DILocation(line: 22, column: 3, scope: !47) 211d6a0585dSwlei!72 = !{!"llvm.loop.mustprogress"} 212d6a0585dSwlei!73 = !DILocation(line: 18, column: 19, scope: !74) 213d6a0585dSwlei!74 = distinct !DILexicalBlock(scope: !63, file: !3, line: 17, column: 37) 214d6a0585dSwlei!75 = !DILocation(line: 18, column: 11, scope: !74) 215d6a0585dSwlei!76 = !DILocation(line: 18, column: 9, scope: !74) 216d6a0585dSwlei!77 = !DILocation(line: 19, column: 15, scope: !74) 217d6a0585dSwlei!78 = !DILocation(line: 19, column: 11, scope: !74) 218d6a0585dSwlei!79 = !DILocation(line: 19, column: 9, scope: !74) 219d6a0585dSwlei!80 = !DILocation(line: 20, column: 15, scope: !74) 220d6a0585dSwlei!81 = !DILocation(line: 20, column: 11, scope: !74) 221d6a0585dSwlei!82 = !DILocation(line: 20, column: 9, scope: !74) 222d6a0585dSwlei!83 = !DILocation(line: 17, column: 33, scope: !84) 223d6a0585dSwlei!84 = !DILexicalBlockFile(scope: !63, file: !3, discriminator: 4) 224d6a0585dSwlei!85 = !DILocation(line: 17, column: 5, scope: !84) 225d6a0585dSwlei!86 = distinct !{!86, !87, !88, !72} 226d6a0585dSwlei!87 = !DILocation(line: 17, column: 5, scope: !49) 227d6a0585dSwlei!88 = !DILocation(line: 21, column: 5, scope: !49) 228