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