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