15250e7a0SFangrui Song; RUN: opt %s -passes='function(instcombine),sample-profile' -sample-profile-file=%S/Inputs/inline-coverage.prof -sample-profile-check-record-coverage=100 -sample-profile-check-sample-coverage=110 -pass-remarks=sample-profile -pass-remarks-analysis=sample-profile -o /dev/null 2>&1 | FileCheck %s 25250e7a0SFangrui Song; RUN: opt %s -passes="function(instcombine),sample-profile" -sample-profile-file=%S/Inputs/inline-coverage.prof -sample-profile-check-record-coverage=100 -sample-profile-check-sample-coverage=110 -pass-remarks=sample-profile -pass-remarks-analysis=sample-profile -o /dev/null 2>&1 | FileCheck %s 3cee313d2SEric Christopher; 4cee313d2SEric Christopher; Original code: 5cee313d2SEric Christopher; 6cee313d2SEric Christopher; 1 #include <stdlib.h> 7cee313d2SEric Christopher; 2 8cee313d2SEric Christopher; 3 long long int foo(long i) { 9cee313d2SEric Christopher; 4 return rand() * i; 10cee313d2SEric Christopher; 5 } 11cee313d2SEric Christopher; 6 12cee313d2SEric Christopher; 7 int main() { 13cee313d2SEric Christopher; 8 long long int sum = 0; 14cee313d2SEric Christopher; 9 for (int i = 0; i < 200000 * 3000; i++) 15cee313d2SEric Christopher; 10 sum += foo(i); 16cee313d2SEric Christopher; 11 return sum > 0 ? 0 : 1; 17cee313d2SEric Christopher; 12 } 18cee313d2SEric Christopher; 19d275a064SWenlei He; CHECK: remark: coverage.cc:10:12: previous inlining reattempted for hotness: '_Z3fool' into 'main' 20cee313d2SEric Christopher; CHECK: remark: coverage.cc:9:21: Applied 23478 samples from profile (offset: 2.1) 21cee313d2SEric Christopher; CHECK: remark: coverage.cc:10:16: Applied 23478 samples from profile (offset: 3) 22cee313d2SEric Christopher; CHECK: remark: coverage.cc:4:10: Applied 31878 samples from profile (offset: 1) 23cee313d2SEric Christopher; CHECK: remark: coverage.cc:11:10: Applied 0 samples from profile (offset: 4) 24cee313d2SEric Christopher; CHECK: remark: coverage.cc:10:16: most popular destination for conditional branches at coverage.cc:9:3 25cee313d2SEric Christopher; 26cee313d2SEric Christopher; There is one sample record with 0 samples at offset 4 in main() that we never 27cee313d2SEric Christopher; use: 28cee313d2SEric Christopher; CHECK: warning: coverage.cc:7: 4 of 5 available profile records (80%) were applied 29cee313d2SEric Christopher; 30cee313d2SEric Christopher; Since the unused sample record contributes no samples, sample coverage should 31cee313d2SEric Christopher; be 100%. Note that we get this warning because we are requesting an impossible 32cee313d2SEric Christopher; 110% coverage check. 33cee313d2SEric Christopher; CHECK: warning: coverage.cc:7: 78834 of 78834 available profile samples (100%) were applied 34cee313d2SEric Christopher 357a6c8942SWei Midefine i64 @_Z3fool(i64 %i) #0 !dbg !4 { 36cee313d2SEric Christopherentry: 37cee313d2SEric Christopher %i.addr = alloca i64, align 8 38*0271ae65SFangrui Song store i64 %i, ptr %i.addr, align 8 39*0271ae65SFangrui Song call void @llvm.dbg.declare(metadata ptr %i.addr, metadata !16, metadata !17), !dbg !18 40cee313d2SEric Christopher %call = call i32 @rand(), !dbg !19 41cee313d2SEric Christopher %conv = sext i32 %call to i64, !dbg !19 42*0271ae65SFangrui Song %0 = load i64, ptr %i.addr, align 8, !dbg !20 43cee313d2SEric Christopher %mul = mul nsw i64 %conv, %0, !dbg !21 44cee313d2SEric Christopher ret i64 %mul, !dbg !22 45cee313d2SEric Christopher} 46cee313d2SEric Christopher 47cee313d2SEric Christopherdeclare void @llvm.dbg.declare(metadata, metadata, metadata) 48cee313d2SEric Christopher 49cee313d2SEric Christopherdeclare i32 @rand() 50cee313d2SEric Christopher 517a6c8942SWei Midefine i32 @main() #0 !dbg !9 { 52cee313d2SEric Christopherentry: 53cee313d2SEric Christopher %retval = alloca i32, align 4 54cee313d2SEric Christopher %sum = alloca i64, align 8 55cee313d2SEric Christopher %i = alloca i32, align 4 56*0271ae65SFangrui Song store i32 0, ptr %retval, align 4 57*0271ae65SFangrui Song call void @llvm.dbg.declare(metadata ptr %sum, metadata !23, metadata !17), !dbg !24 58*0271ae65SFangrui Song store i64 0, ptr %sum, align 8, !dbg !24 59*0271ae65SFangrui Song call void @llvm.dbg.declare(metadata ptr %i, metadata !25, metadata !17), !dbg !27 60*0271ae65SFangrui Song store i32 0, ptr %i, align 4, !dbg !27 61cee313d2SEric Christopher br label %for.cond, !dbg !28 62cee313d2SEric Christopher 63cee313d2SEric Christopherfor.cond: ; preds = %for.inc, %entry 64*0271ae65SFangrui Song %0 = load i32, ptr %i, align 4, !dbg !29 65cee313d2SEric Christopher %cmp = icmp slt i32 %0, 600000000, !dbg !32 66cee313d2SEric Christopher br i1 %cmp, label %for.body, label %for.end, !dbg !33 67cee313d2SEric Christopher 68cee313d2SEric Christopherfor.body: ; preds = %for.cond 69*0271ae65SFangrui Song %1 = load i32, ptr %i, align 4, !dbg !34 70cee313d2SEric Christopher %conv = sext i32 %1 to i64, !dbg !34 71cee313d2SEric Christopher %call = call i64 @_Z3fool(i64 %conv), !dbg !35 72*0271ae65SFangrui Song %2 = load i64, ptr %sum, align 8, !dbg !36 73cee313d2SEric Christopher %add = add nsw i64 %2, %call, !dbg !36 74*0271ae65SFangrui Song store i64 %add, ptr %sum, align 8, !dbg !36 75cee313d2SEric Christopher br label %for.inc, !dbg !37 76cee313d2SEric Christopher 77cee313d2SEric Christopherfor.inc: ; preds = %for.body 78*0271ae65SFangrui Song %3 = load i32, ptr %i, align 4, !dbg !38 79cee313d2SEric Christopher %inc = add nsw i32 %3, 1, !dbg !38 80*0271ae65SFangrui Song store i32 %inc, ptr %i, align 4, !dbg !38 81cee313d2SEric Christopher br label %for.cond, !dbg !39 82cee313d2SEric Christopher 83cee313d2SEric Christopherfor.end: ; preds = %for.cond 84*0271ae65SFangrui Song %4 = load i64, ptr %sum, align 8, !dbg !40 85cee313d2SEric Christopher %cmp1 = icmp sgt i64 %4, 0, !dbg !41 86cee313d2SEric Christopher %cond = select i1 %cmp1, i32 0, i32 1, !dbg !40 87cee313d2SEric Christopher ret i32 %cond, !dbg !42 88cee313d2SEric Christopher} 89cee313d2SEric Christopher 907a6c8942SWei Miattributes #0 = { "use-sample-profile" } 917a6c8942SWei Mi 92cee313d2SEric Christopher!llvm.dbg.cu = !{!0} 93cee313d2SEric Christopher!llvm.module.flags = !{!13, !14} 94cee313d2SEric Christopher!llvm.ident = !{!15} 95cee313d2SEric Christopher 96cee313d2SEric Christopher!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 3.8.0 (trunk 251738) (llvm/trunk 251737)", isOptimized: false, runtimeVersion: 0, emissionKind: NoDebug, enums: !2) 97cee313d2SEric Christopher!1 = !DIFile(filename: "coverage.cc", directory: ".") 98cee313d2SEric Christopher!2 = !{} 99cee313d2SEric Christopher!4 = distinct !DISubprogram(name: "foo", linkageName: "_Z3fool", scope: !1, file: !1, line: 3, type: !5, isLocal: false, isDefinition: true, scopeLine: 3, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2) 100cee313d2SEric Christopher!5 = !DISubroutineType(types: !6) 101cee313d2SEric Christopher!6 = !{!7, !8} 102cee313d2SEric Christopher!7 = !DIBasicType(name: "long long int", size: 64, align: 64, encoding: DW_ATE_signed) 103cee313d2SEric Christopher!8 = !DIBasicType(name: "long int", size: 64, align: 64, encoding: DW_ATE_signed) 104cee313d2SEric Christopher!9 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 7, type: !10, isLocal: false, isDefinition: true, scopeLine: 7, flags: DIFlagPrototyped, isOptimized: false, unit: !0, retainedNodes: !2) 105cee313d2SEric Christopher!10 = !DISubroutineType(types: !11) 106cee313d2SEric Christopher!11 = !{!12} 107cee313d2SEric Christopher!12 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed) 108cee313d2SEric Christopher!13 = !{i32 2, !"Dwarf Version", i32 4} 109cee313d2SEric Christopher!14 = !{i32 2, !"Debug Info Version", i32 3} 110cee313d2SEric Christopher!15 = !{!"clang version 3.8.0 (trunk 251738) (llvm/trunk 251737)"} 111cee313d2SEric Christopher!16 = !DILocalVariable(name: "i", arg: 1, scope: !4, file: !1, line: 3, type: !8) 112cee313d2SEric Christopher!17 = !DIExpression() 113cee313d2SEric Christopher!18 = !DILocation(line: 3, column: 24, scope: !4) 114cee313d2SEric Christopher!19 = !DILocation(line: 4, column: 10, scope: !4) 115cee313d2SEric Christopher!20 = !DILocation(line: 4, column: 19, scope: !4) 116cee313d2SEric Christopher!21 = !DILocation(line: 4, column: 17, scope: !4) 117cee313d2SEric Christopher!22 = !DILocation(line: 4, column: 3, scope: !4) 118cee313d2SEric Christopher!23 = !DILocalVariable(name: "sum", scope: !9, file: !1, line: 8, type: !7) 119cee313d2SEric Christopher!24 = !DILocation(line: 8, column: 17, scope: !9) 120cee313d2SEric Christopher!25 = !DILocalVariable(name: "i", scope: !26, file: !1, line: 9, type: !12) 121cee313d2SEric Christopher!26 = distinct !DILexicalBlock(scope: !9, file: !1, line: 9, column: 3) 122cee313d2SEric Christopher!27 = !DILocation(line: 9, column: 12, scope: !26) 123cee313d2SEric Christopher!28 = !DILocation(line: 9, column: 8, scope: !26) 124cee313d2SEric Christopher!29 = !DILocation(line: 9, column: 19, scope: !30) 125cee313d2SEric Christopher!30 = !DILexicalBlockFile(scope: !31, file: !1, discriminator: 2) 126cee313d2SEric Christopher!31 = distinct !DILexicalBlock(scope: !26, file: !1, line: 9, column: 3) 127cee313d2SEric Christopher!32 = !DILocation(line: 9, column: 21, scope: !30) 128cee313d2SEric Christopher!33 = !DILocation(line: 9, column: 3, scope: !30) 129cee313d2SEric Christopher!34 = !DILocation(line: 10, column: 16, scope: !31) 130cee313d2SEric Christopher!35 = !DILocation(line: 10, column: 12, scope: !31) 131cee313d2SEric Christopher!36 = !DILocation(line: 10, column: 9, scope: !31) 132cee313d2SEric Christopher!37 = !DILocation(line: 10, column: 5, scope: !31) 133cee313d2SEric Christopher!38 = !DILocation(line: 9, column: 39, scope: !31) 134cee313d2SEric Christopher!39 = !DILocation(line: 9, column: 3, scope: !31) 135cee313d2SEric Christopher!40 = !DILocation(line: 11, column: 10, scope: !9) 136cee313d2SEric Christopher!41 = !DILocation(line: 11, column: 14, scope: !9) 137cee313d2SEric Christopher!42 = !DILocation(line: 11, column: 3, scope: !9) 138