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