1 ; 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
2 ; 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
6 ; 1 #include <stdlib.h>
8 ; 3 long long int foo(long i) {
13 ; 8 long long int sum = 0;
14 ; 9 for (int i = 0; i < 200000 * 3000; i++)
16 ; 11 return sum > 0 ? 0 : 1;
19 ; CHECK: remark: coverage.cc:10:12: previous inlining reattempted for hotness: '_Z3fool' into 'main'
20 ; CHECK: remark: coverage.cc:9:21: Applied 23478 samples from profile (offset: 2.1)
21 ; CHECK: remark: coverage.cc:10:16: Applied 23478 samples from profile (offset: 3)
22 ; CHECK: remark: coverage.cc:4:10: Applied 31878 samples from profile (offset: 1)
23 ; CHECK: remark: coverage.cc:11:10: Applied 0 samples from profile (offset: 4)
24 ; CHECK: remark: coverage.cc:10:16: most popular destination for conditional branches at coverage.cc:9:3
26 ; There is one sample record with 0 samples at offset 4 in main() that we never
28 ; CHECK: warning: coverage.cc:7: 4 of 5 available profile records (80%) were applied
30 ; Since the unused sample record contributes no samples, sample coverage should
31 ; be 100%. Note that we get this warning because we are requesting an impossible
32 ; 110% coverage check.
33 ; CHECK: warning: coverage.cc:7: 78834 of 78834 available profile samples (100%) were applied
35 define i64 @_Z3fool(i64 %i) #0 !dbg !4 {
37 %i.addr = alloca i64, align 8
38 store i64 %i, ptr %i.addr, align 8
39 call void @llvm.dbg.declare(metadata ptr %i.addr, metadata !16, metadata !17), !dbg !18
40 %call = call i32 @rand(), !dbg !19
41 %conv = sext i32 %call to i64, !dbg !19
42 %0 = load i64, ptr %i.addr, align 8, !dbg !20
43 %mul = mul nsw i64 %conv, %0, !dbg !21
44 ret i64 %mul, !dbg !22
47 declare void @llvm.dbg.declare(metadata, metadata, metadata)
51 define i32 @main() #0 !dbg !9 {
53 %retval = alloca i32, align 4
54 %sum = alloca i64, align 8
55 %i = alloca i32, align 4
56 store i32 0, ptr %retval, align 4
57 call void @llvm.dbg.declare(metadata ptr %sum, metadata !23, metadata !17), !dbg !24
58 store i64 0, ptr %sum, align 8, !dbg !24
59 call void @llvm.dbg.declare(metadata ptr %i, metadata !25, metadata !17), !dbg !27
60 store i32 0, ptr %i, align 4, !dbg !27
61 br label %for.cond, !dbg !28
63 for.cond: ; preds = %for.inc, %entry
64 %0 = load i32, ptr %i, align 4, !dbg !29
65 %cmp = icmp slt i32 %0, 600000000, !dbg !32
66 br i1 %cmp, label %for.body, label %for.end, !dbg !33
68 for.body: ; preds = %for.cond
69 %1 = load i32, ptr %i, align 4, !dbg !34
70 %conv = sext i32 %1 to i64, !dbg !34
71 %call = call i64 @_Z3fool(i64 %conv), !dbg !35
72 %2 = load i64, ptr %sum, align 8, !dbg !36
73 %add = add nsw i64 %2, %call, !dbg !36
74 store i64 %add, ptr %sum, align 8, !dbg !36
75 br label %for.inc, !dbg !37
77 for.inc: ; preds = %for.body
78 %3 = load i32, ptr %i, align 4, !dbg !38
79 %inc = add nsw i32 %3, 1, !dbg !38
80 store i32 %inc, ptr %i, align 4, !dbg !38
81 br label %for.cond, !dbg !39
83 for.end: ; preds = %for.cond
84 %4 = load i64, ptr %sum, align 8, !dbg !40
85 %cmp1 = icmp sgt i64 %4, 0, !dbg !41
86 %cond = select i1 %cmp1, i32 0, i32 1, !dbg !40
87 ret i32 %cond, !dbg !42
90 attributes #0 = { "use-sample-profile" }
93 !llvm.module.flags = !{!13, !14}
96 !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)
97 !1 = !DIFile(filename: "coverage.cc", directory: ".")
99 !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)
100 !5 = !DISubroutineType(types: !6)
102 !7 = !DIBasicType(name: "long long int", size: 64, align: 64, encoding: DW_ATE_signed)
103 !8 = !DIBasicType(name: "long int", size: 64, align: 64, encoding: DW_ATE_signed)
104 !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)
105 !10 = !DISubroutineType(types: !11)
107 !12 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
108 !13 = !{i32 2, !"Dwarf Version", i32 4}
109 !14 = !{i32 2, !"Debug Info Version", i32 3}
110 !15 = !{!"clang version 3.8.0 (trunk 251738) (llvm/trunk 251737)"}
111 !16 = !DILocalVariable(name: "i", arg: 1, scope: !4, file: !1, line: 3, type: !8)
112 !17 = !DIExpression()
113 !18 = !DILocation(line: 3, column: 24, scope: !4)
114 !19 = !DILocation(line: 4, column: 10, scope: !4)
115 !20 = !DILocation(line: 4, column: 19, scope: !4)
116 !21 = !DILocation(line: 4, column: 17, scope: !4)
117 !22 = !DILocation(line: 4, column: 3, scope: !4)
118 !23 = !DILocalVariable(name: "sum", scope: !9, file: !1, line: 8, type: !7)
119 !24 = !DILocation(line: 8, column: 17, scope: !9)
120 !25 = !DILocalVariable(name: "i", scope: !26, file: !1, line: 9, type: !12)
121 !26 = distinct !DILexicalBlock(scope: !9, file: !1, line: 9, column: 3)
122 !27 = !DILocation(line: 9, column: 12, scope: !26)
123 !28 = !DILocation(line: 9, column: 8, scope: !26)
124 !29 = !DILocation(line: 9, column: 19, scope: !30)
125 !30 = !DILexicalBlockFile(scope: !31, file: !1, discriminator: 2)
126 !31 = distinct !DILexicalBlock(scope: !26, file: !1, line: 9, column: 3)
127 !32 = !DILocation(line: 9, column: 21, scope: !30)
128 !33 = !DILocation(line: 9, column: 3, scope: !30)
129 !34 = !DILocation(line: 10, column: 16, scope: !31)
130 !35 = !DILocation(line: 10, column: 12, scope: !31)
131 !36 = !DILocation(line: 10, column: 9, scope: !31)
132 !37 = !DILocation(line: 10, column: 5, scope: !31)
133 !38 = !DILocation(line: 9, column: 39, scope: !31)
134 !39 = !DILocation(line: 9, column: 3, scope: !31)
135 !40 = !DILocation(line: 11, column: 10, scope: !9)
136 !41 = !DILocation(line: 11, column: 14, scope: !9)
137 !42 = !DILocation(line: 11, column: 3, scope: !9)