blob: ae08466c38e85404e2f426bdbdc468ca7a8bfac7 [file] [log] [blame]
Dehao Chen80b16d42016-05-27 16:14:15 +00001; RUN: opt < %s -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 -o /dev/null 2>&1 | FileCheck %s
Diego Novillof9ed08e2015-10-31 21:53:58 +00002;
3; Original code:
4;
5; 1 #include <stdlib.h>
6; 2
7; 3 long long int foo(long i) {
8; 4 return rand() * i;
9; 5 }
10; 6
11; 7 int main() {
12; 8 long long int sum = 0;
13; 9 for (int i = 0; i < 200000 * 3000; i++)
14; 10 sum += foo(i);
15; 11 return sum > 0 ? 0 : 1;
16; 12 }
17;
18; CHECK: remark: coverage.cc:10:12: inlined hot callee '_Z3fool' with 172746 samples into 'main'
Dehao Chen1012be12016-03-01 22:53:02 +000019; CHECK: remark: coverage.cc:9:21: Applied 23478 samples from profile (offset: 2.1)
Diego Novillodf544a02015-11-20 15:39:42 +000020; CHECK: remark: coverage.cc:10:16: Applied 23478 samples from profile (offset: 3)
21; CHECK: remark: coverage.cc:4:10: Applied 31878 samples from profile (offset: 1)
22; CHECK: remark: coverage.cc:11:10: Applied 0 samples from profile (offset: 4)
Diego Novillof9ed08e2015-10-31 21:53:58 +000023; CHECK: remark: coverage.cc:10:16: most popular destination for conditional branches at coverage.cc:9:3
24;
25; There is one sample record with 0 samples at offset 4 in main() that we never
26; use:
27; CHECK: warning: coverage.cc:7: 4 of 5 available profile records (80%) were applied
Diego Novillo243ea6a2015-11-23 20:12:21 +000028;
29; Since the unused sample record contributes no samples, sample coverage should
30; be 100%. Note that we get this warning because we are requesting an impossible
31; 110% coverage check.
32; CHECK: warning: coverage.cc:7: 78834 of 78834 available profile samples (100%) were applied
Diego Novillof9ed08e2015-10-31 21:53:58 +000033
Peter Collingbourned4bff302015-11-05 22:03:56 +000034define i64 @_Z3fool(i64 %i) !dbg !4 {
Diego Novillof9ed08e2015-10-31 21:53:58 +000035entry:
36 %i.addr = alloca i64, align 8
37 store i64 %i, i64* %i.addr, align 8
38 call void @llvm.dbg.declare(metadata i64* %i.addr, metadata !16, metadata !17), !dbg !18
39 %call = call i32 @rand(), !dbg !19
40 %conv = sext i32 %call to i64, !dbg !19
41 %0 = load i64, i64* %i.addr, align 8, !dbg !20
42 %mul = mul nsw i64 %conv, %0, !dbg !21
43 ret i64 %mul, !dbg !22
44}
45
46declare void @llvm.dbg.declare(metadata, metadata, metadata)
47
48declare i32 @rand()
49
Peter Collingbourned4bff302015-11-05 22:03:56 +000050define i32 @main() !dbg !9 {
Diego Novillof9ed08e2015-10-31 21:53:58 +000051entry:
52 %retval = alloca i32, align 4
53 %sum = alloca i64, align 8
54 %i = alloca i32, align 4
55 store i32 0, i32* %retval, align 4
56 call void @llvm.dbg.declare(metadata i64* %sum, metadata !23, metadata !17), !dbg !24
57 store i64 0, i64* %sum, align 8, !dbg !24
58 call void @llvm.dbg.declare(metadata i32* %i, metadata !25, metadata !17), !dbg !27
59 store i32 0, i32* %i, align 4, !dbg !27
60 br label %for.cond, !dbg !28
61
62for.cond: ; preds = %for.inc, %entry
63 %0 = load i32, i32* %i, align 4, !dbg !29
64 %cmp = icmp slt i32 %0, 600000000, !dbg !32
65 br i1 %cmp, label %for.body, label %for.end, !dbg !33
66
67for.body: ; preds = %for.cond
68 %1 = load i32, i32* %i, align 4, !dbg !34
69 %conv = sext i32 %1 to i64, !dbg !34
70 %call = call i64 @_Z3fool(i64 %conv), !dbg !35
71 %2 = load i64, i64* %sum, align 8, !dbg !36
72 %add = add nsw i64 %2, %call, !dbg !36
73 store i64 %add, i64* %sum, align 8, !dbg !36
74 br label %for.inc, !dbg !37
75
76for.inc: ; preds = %for.body
77 %3 = load i32, i32* %i, align 4, !dbg !38
78 %inc = add nsw i32 %3, 1, !dbg !38
79 store i32 %inc, i32* %i, align 4, !dbg !38
80 br label %for.cond, !dbg !39
81
82for.end: ; preds = %for.cond
83 %4 = load i64, i64* %sum, align 8, !dbg !40
84 %cmp1 = icmp sgt i64 %4, 0, !dbg !41
85 %cond = select i1 %cmp1, i32 0, i32 1, !dbg !40
86 ret i32 %cond, !dbg !42
87}
88
89!llvm.dbg.cu = !{!0}
90!llvm.module.flags = !{!13, !14}
91!llvm.ident = !{!15}
92
Adrian Prantl75819ae2016-04-15 15:57:41 +000093!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)
Diego Novillof9ed08e2015-10-31 21:53:58 +000094!1 = !DIFile(filename: "coverage.cc", directory: ".")
95!2 = !{}
Adrian Prantl75819ae2016-04-15 15:57:41 +000096!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, variables: !2)
Diego Novillof9ed08e2015-10-31 21:53:58 +000097!5 = !DISubroutineType(types: !6)
98!6 = !{!7, !8}
99!7 = !DIBasicType(name: "long long int", size: 64, align: 64, encoding: DW_ATE_signed)
100!8 = !DIBasicType(name: "long int", size: 64, align: 64, encoding: DW_ATE_signed)
Adrian Prantl75819ae2016-04-15 15:57:41 +0000101!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, variables: !2)
Diego Novillof9ed08e2015-10-31 21:53:58 +0000102!10 = !DISubroutineType(types: !11)
103!11 = !{!12}
104!12 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
105!13 = !{i32 2, !"Dwarf Version", i32 4}
106!14 = !{i32 2, !"Debug Info Version", i32 3}
107!15 = !{!"clang version 3.8.0 (trunk 251738) (llvm/trunk 251737)"}
108!16 = !DILocalVariable(name: "i", arg: 1, scope: !4, file: !1, line: 3, type: !8)
109!17 = !DIExpression()
110!18 = !DILocation(line: 3, column: 24, scope: !4)
111!19 = !DILocation(line: 4, column: 10, scope: !4)
112!20 = !DILocation(line: 4, column: 19, scope: !4)
113!21 = !DILocation(line: 4, column: 17, scope: !4)
114!22 = !DILocation(line: 4, column: 3, scope: !4)
115!23 = !DILocalVariable(name: "sum", scope: !9, file: !1, line: 8, type: !7)
116!24 = !DILocation(line: 8, column: 17, scope: !9)
117!25 = !DILocalVariable(name: "i", scope: !26, file: !1, line: 9, type: !12)
118!26 = distinct !DILexicalBlock(scope: !9, file: !1, line: 9, column: 3)
119!27 = !DILocation(line: 9, column: 12, scope: !26)
120!28 = !DILocation(line: 9, column: 8, scope: !26)
121!29 = !DILocation(line: 9, column: 19, scope: !30)
122!30 = !DILexicalBlockFile(scope: !31, file: !1, discriminator: 1)
123!31 = distinct !DILexicalBlock(scope: !26, file: !1, line: 9, column: 3)
124!32 = !DILocation(line: 9, column: 21, scope: !30)
125!33 = !DILocation(line: 9, column: 3, scope: !30)
126!34 = !DILocation(line: 10, column: 16, scope: !31)
127!35 = !DILocation(line: 10, column: 12, scope: !31)
128!36 = !DILocation(line: 10, column: 9, scope: !31)
129!37 = !DILocation(line: 10, column: 5, scope: !31)
130!38 = !DILocation(line: 9, column: 39, scope: !31)
131!39 = !DILocation(line: 9, column: 3, scope: !31)
132!40 = !DILocation(line: 11, column: 10, scope: !9)
133!41 = !DILocation(line: 11, column: 14, scope: !9)
134!42 = !DILocation(line: 11, column: 3, scope: !9)