1 ; RUN: opt < %s -instcombine -sample-profile -sample-profile-file=%S/Inputs/cov-zero-samples.prof -sample-profile-check-record-coverage=100 -pass-remarks=sample-profile -pass-remarks-analysis=sample-profile -o /dev/null 2>&1 | FileCheck %s 2 ; RUN: opt < %s -passes="function(instcombine),sample-profile" -sample-profile-file=%S/Inputs/cov-zero-samples.prof -sample-profile-check-record-coverage=100 -pass-remarks=sample-profile -pass-remarks-analysis=sample-profile -o /dev/null 2>&1 | FileCheck %s 3 ; 4 ; CHECK: remark: cov-zero-samples.cc:9:29: Applied 404065 samples from profile (offset: 2.1) 5 ; CHECK: remark: cov-zero-samples.cc:10:9: Applied 443089 samples from profile (offset: 3) 6 ; CHECK: remark: cov-zero-samples.cc:10:36: Applied 0 samples from profile (offset: 3.1) 7 ; CHECK: remark: cov-zero-samples.cc:11:12: Applied 404066 samples from profile (offset: 4) 8 ; CHECK: remark: cov-zero-samples.cc:13:25: Applied 0 samples from profile (offset: 6) 9 ; CHECK: remark: cov-zero-samples.cc:14:3: Applied 0 samples from profile (offset: 7) 10 ; CHECK: remark: cov-zero-samples.cc:10:9: most popular destination for conditional branches at cov-zero-samples.cc:9:3 11 ; CHECK: remark: cov-zero-samples.cc:11:12: most popular destination for conditional branches at cov-zero-samples.cc:10:9 12 ; 13 ; Coverage for this profile should be 100% 14 ; CHECK-NOT: warning: cov-zero-samples.cc:1: 15 16 source_filename = "test/Transforms/SampleProfile/cov-zero-samples.ll" 17 18 @N = global i64 8000000000, align 8, !dbg !0 19 @.str = private unnamed_addr constant [11 x i8] c"sum is %d\0A\00", align 1 20 21 define i32 @_Z12never_calledi(i32 %i) !dbg !11 { 22 entry: 23 ret i32 0, !dbg !15 24 } 25 26 ; Function Attrs: nounwind readnone 27 declare void @llvm.dbg.declare(metadata, metadata, metadata) #0 28 29 define i32 @main() !dbg !17 { 30 entry: 31 %retval = alloca i32, align 4 32 %sum = alloca i32, align 4 33 %i = alloca i64, align 8 34 store i32 0, i32* %retval, align 4 35 call void @llvm.dbg.declare(metadata i32* %sum, metadata !20, metadata !21), !dbg !22 36 store i32 0, i32* %sum, align 4, !dbg !22 37 call void @llvm.dbg.declare(metadata i64* %i, metadata !23, metadata !21), !dbg !25 38 store i64 0, i64* %i, align 8, !dbg !25 39 br label %for.cond, !dbg !26 40 41 for.cond: ; preds = %for.inc, %entry 42 43 %0 = load i64, i64* %i, align 8, !dbg !27 44 %1 = load volatile i64, i64* @N, align 8, !dbg !30 45 %cmp = icmp slt i64 %0, %1, !dbg !31 46 br i1 %cmp, label %for.body, label %for.end, !dbg !32 47 48 for.body: ; preds = %for.cond 49 %2 = load i64, i64* %i, align 8, !dbg !33 50 %3 = load volatile i64, i64* @N, align 8, !dbg !36 51 %cmp1 = icmp sgt i64 %2, %3, !dbg !37 52 br i1 %cmp1, label %if.then, label %if.end, !dbg !38 53 54 if.then: ; preds = %for.body 55 %4 = load i64, i64* %i, align 8, !dbg !39 56 %conv = trunc i64 %4 to i32, !dbg !39 57 %call = call i32 @_Z12never_calledi(i32 %conv), !dbg !41 58 %5 = load i32, i32* %sum, align 4, !dbg !42 59 %add = add nsw i32 %5, %call, !dbg !42 60 store i32 %add, i32* %sum, align 4, !dbg !42 61 br label %if.end, !dbg !43 62 63 if.end: ; preds = %if.then, %for.body 64 %6 = load i64, i64* %i, align 8, !dbg !44 65 %div = sdiv i64 %6, 239, !dbg !45 66 %7 = load i32, i32* %sum, align 4, !dbg !46 67 %conv2 = sext i32 %7 to i64, !dbg !46 68 %mul = mul nsw i64 %conv2, %div, !dbg !46 69 %conv3 = trunc i64 %mul to i32, !dbg !46 70 store i32 %conv3, i32* %sum, align 4, !dbg !46 71 br label %for.inc, !dbg !47 72 73 for.inc: ; preds = %if.end 74 %8 = load i64, i64* %i, align 8, !dbg !48 75 %inc = add nsw i64 %8, 1, !dbg !48 76 store i64 %inc, i64* %i, align 8, !dbg !48 77 br label %for.cond, !dbg !50 78 79 for.end: ; preds = %for.cond 80 %9 = load i32, i32* %sum, align 4, !dbg !51 81 %call4 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([11 x i8], [11 x i8]* @.str, i32 0, i32 0), i32 %9), !dbg !52 82 ret i32 0, !dbg !53 83 } 84 85 declare i32 @printf(i8*, ...) 86 87 attributes #0 = { nounwind readnone } 88 89 !llvm.dbg.cu = !{!2} 90 !llvm.module.flags = !{!8, !9} 91 !llvm.ident = !{!10} 92 93 !0 = !DIGlobalVariableExpression(var: !1, expr: !DIExpression()) 94 !1 = !DIGlobalVariable(name: "N", scope: !2, file: !3, line: 3, type: !6, isLocal: false, isDefinition: true) 95 !2 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !3, producer: "clang version 3.8.0 (trunk 253667) (llvm/trunk 253670)", isOptimized: false, runtimeVersion: 0, emissionKind: NoDebug, enums: !4, globals: !5) 96 !3 = !DIFile(filename: "cov-zero-samples.cc", directory: ".") 97 !4 = !{} 98 !5 = !{!0} 99 !6 = !DIDerivedType(tag: DW_TAG_volatile_type, baseType: !7) 100 !7 = !DIBasicType(name: "long long int", size: 64, align: 64, encoding: DW_ATE_signed) 101 !8 = !{i32 2, !"Dwarf Version", i32 4} 102 !9 = !{i32 2, !"Debug Info Version", i32 3} 103 !10 = !{!"clang version 3.8.0 (trunk 253667) (llvm/trunk 253670)"} 104 !11 = distinct !DISubprogram(name: "never_called", linkageName: "_Z12never_calledi", scope: !3, file: !3, line: 5, type: !12, isLocal: false, isDefinition: true, scopeLine: 5, flags: DIFlagPrototyped, isOptimized: false, unit: !2, retainedNodes: !4) 105 !12 = !DISubroutineType(types: !13) 106 !13 = !{!14, !14} 107 !14 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed) 108 !15 = !DILocation(line: 5, column: 27, scope: !16) 109 !16 = !DILexicalBlockFile(scope: !11, file: !3, discriminator: 6) 110 !17 = distinct !DISubprogram(name: "main", scope: !3, file: !3, line: 7, type: !18, isLocal: false, isDefinition: true, scopeLine: 7, flags: DIFlagPrototyped, isOptimized: false, unit: !2, retainedNodes: !4) 111 !18 = !DISubroutineType(types: !19) 112 !19 = !{!14} 113 !20 = !DILocalVariable(name: "sum", scope: !17, file: !3, line: 8, type: !14) 114 !21 = !DIExpression() 115 !22 = !DILocation(line: 8, column: 7, scope: !17) 116 !23 = !DILocalVariable(name: "i", scope: !24, file: !3, line: 9, type: !7) 117 !24 = distinct !DILexicalBlock(scope: !17, file: !3, line: 9, column: 3) 118 !25 = !DILocation(line: 9, column: 18, scope: !24) 119 !26 = !DILocation(line: 9, column: 8, scope: !24) 120 !27 = !DILocation(line: 9, column: 25, scope: !28) 121 !28 = !DILexicalBlockFile(scope: !29, file: !3, discriminator: 2) 122 !29 = distinct !DILexicalBlock(scope: !24, file: !3, line: 9, column: 3) 123 !30 = !DILocation(line: 9, column: 29, scope: !28) 124 !31 = !DILocation(line: 9, column: 27, scope: !28) 125 !32 = !DILocation(line: 9, column: 3, scope: !28) 126 !33 = !DILocation(line: 10, column: 9, scope: !34) 127 !34 = distinct !DILexicalBlock(scope: !35, file: !3, line: 10, column: 9) 128 !35 = distinct !DILexicalBlock(scope: !29, file: !3, line: 9, column: 37) 129 !36 = !DILocation(line: 10, column: 13, scope: !34) 130 !37 = !DILocation(line: 10, column: 11, scope: !34) 131 !38 = !DILocation(line: 10, column: 9, scope: !35) 132 !39 = !DILocation(line: 10, column: 36, scope: !40) 133 !40 = !DILexicalBlockFile(scope: !34, file: !3, discriminator: 2) 134 !41 = !DILocation(line: 10, column: 23, scope: !40) 135 !42 = !DILocation(line: 10, column: 20, scope: !40) 136 !43 = !DILocation(line: 10, column: 16, scope: !40) 137 !44 = !DILocation(line: 11, column: 12, scope: !35) 138 !45 = !DILocation(line: 11, column: 14, scope: !35) 139 !46 = !DILocation(line: 11, column: 9, scope: !35) 140 !47 = !DILocation(line: 12, column: 3, scope: !35) 141 !48 = !DILocation(line: 9, column: 33, scope: !49) 142 !49 = !DILexicalBlockFile(scope: !29, file: !3, discriminator: 4) 143 !50 = !DILocation(line: 9, column: 3, scope: !49) 144 !51 = !DILocation(line: 13, column: 25, scope: !17) 145 !52 = !DILocation(line: 13, column: 3, scope: !17) 146 !53 = !DILocation(line: 14, column: 3, scope: !17) 147 148