blob: 19e85b45dba8b2d47be64733650ea76bc172a2ce [file] [log] [blame]
Diego Novillo8d6568b2013-11-13 12:22:21 +00001; RUN: opt < %s -sample-profile -sample-profile-file=%S/Inputs/branch.prof | opt -analyze -branch-prob | FileCheck %s
2
3; Original C++ code for this test case:
4;
5; #include <stdio.h>
6; #include <stdlib.h>
Dehao Chen7c41dd62015-10-01 00:26:56 +00007
Diego Novillo8d6568b2013-11-13 12:22:21 +00008; int main(int argc, char *argv[]) {
9; if (argc < 2)
10; return 1;
11; double result;
12; int limit = atoi(argv[1]);
13; if (limit > 100) {
Dehao Chen7c41dd62015-10-01 00:26:56 +000014; double s = 23.041968 * atoi(argv[2]);
Diego Novillo8d6568b2013-11-13 12:22:21 +000015; for (int u = 0; u < limit; u++) {
16; double x = s;
17; s = x + 3.049 + (double)u;
18; s -= s + 3.94 / x * 0.32;
19; }
20; result = s;
21; } else {
Dehao Chen7c41dd62015-10-01 00:26:56 +000022; result = atoi(argv[2]);
Diego Novillo8d6568b2013-11-13 12:22:21 +000023; }
24; printf("result is %lf\n", result);
25; return 0;
26; }
27
28@.str = private unnamed_addr constant [15 x i8] c"result is %lf\0A\00", align 1
29
Dehao Chen7c41dd62015-10-01 00:26:56 +000030; Function Attrs: uwtable
Peter Collingbourned4bff302015-11-05 22:03:56 +000031define i32 @main(i32 %argc, i8** %argv) #0 !dbg !6 {
Diego Novillo8d6568b2013-11-13 12:22:21 +000032; CHECK: Printing analysis 'Branch Probability Analysis' for function 'main':
33
34entry:
Dehao Chen7c41dd62015-10-01 00:26:56 +000035 %retval = alloca i32, align 4
36 %argc.addr = alloca i32, align 4
37 %argv.addr = alloca i8**, align 8
38 %result = alloca double, align 8
39 %limit = alloca i32, align 4
40 %s = alloca double, align 8
41 %u = alloca i32, align 4
42 %x = alloca double, align 8
43 store i32 0, i32* %retval, align 4
44 store i32 %argc, i32* %argc.addr, align 4
45 call void @llvm.dbg.declare(metadata i32* %argc.addr, metadata !16, metadata !17), !dbg !18
46 store i8** %argv, i8*** %argv.addr, align 8
47 call void @llvm.dbg.declare(metadata i8*** %argv.addr, metadata !19, metadata !17), !dbg !20
48 %0 = load i32, i32* %argc.addr, align 4, !dbg !21
49 %cmp = icmp slt i32 %0, 2, !dbg !23
50 br i1 %cmp, label %if.then, label %if.end, !dbg !24
51; CHECK: edge entry -> if.then probability is 0x4ccccccd / 0x80000000 = 60.00%
52; CHECK: edge entry -> if.end probability is 0x33333333 / 0x80000000 = 40.00%
53
54if.then: ; preds = %entry
55 store i32 1, i32* %retval, align 4, !dbg !25
56 br label %return, !dbg !25
Diego Novillo8d6568b2013-11-13 12:22:21 +000057
58if.end: ; preds = %entry
Dehao Chen7c41dd62015-10-01 00:26:56 +000059 call void @llvm.dbg.declare(metadata double* %result, metadata !26, metadata !17), !dbg !27
60 call void @llvm.dbg.declare(metadata i32* %limit, metadata !28, metadata !17), !dbg !29
61 %1 = load i8**, i8*** %argv.addr, align 8, !dbg !30
62 %arrayidx = getelementptr inbounds i8*, i8** %1, i64 1, !dbg !30
63 %2 = load i8*, i8** %arrayidx, align 8, !dbg !30
64 %call = call i32 @atoi(i8* %2) #4, !dbg !31
65 store i32 %call, i32* %limit, align 4, !dbg !29
66 %3 = load i32, i32* %limit, align 4, !dbg !32
67 %cmp1 = icmp sgt i32 %3, 100, !dbg !34
68 br i1 %cmp1, label %if.then.2, label %if.else, !dbg !35
69; CHECK: edge if.end -> if.then.2 probability is 0x66666666 / 0x80000000 = 80.00%
70; CHECK: edge if.end -> if.else probability is 0x1999999a / 0x80000000 = 20.00%
Diego Novillo8d6568b2013-11-13 12:22:21 +000071
Dehao Chen7c41dd62015-10-01 00:26:56 +000072if.then.2: ; preds = %if.end
73 call void @llvm.dbg.declare(metadata double* %s, metadata !36, metadata !17), !dbg !38
74 %4 = load i8**, i8*** %argv.addr, align 8, !dbg !39
75 %arrayidx3 = getelementptr inbounds i8*, i8** %4, i64 2, !dbg !39
76 %5 = load i8*, i8** %arrayidx3, align 8, !dbg !39
77 %call4 = call i32 @atoi(i8* %5) #4, !dbg !40
78 %conv = sitofp i32 %call4 to double, !dbg !40
79 %mul = fmul double 0x40370ABE6A337A81, %conv, !dbg !41
80 store double %mul, double* %s, align 8, !dbg !38
81 call void @llvm.dbg.declare(metadata i32* %u, metadata !42, metadata !17), !dbg !44
82 store i32 0, i32* %u, align 4, !dbg !44
83 br label %for.cond, !dbg !45
Diego Novillo8d6568b2013-11-13 12:22:21 +000084
Dehao Chen7c41dd62015-10-01 00:26:56 +000085for.cond: ; preds = %for.inc, %if.then.2
86 %6 = load i32, i32* %u, align 4, !dbg !46
87 %7 = load i32, i32* %limit, align 4, !dbg !48
88 %cmp5 = icmp slt i32 %6, %7, !dbg !49
89 br i1 %cmp5, label %for.body, label %for.end, !dbg !50
Diego Novillo8d6568b2013-11-13 12:22:21 +000090
Dehao Chen7c41dd62015-10-01 00:26:56 +000091for.body: ; preds = %for.cond
92 call void @llvm.dbg.declare(metadata double* %x, metadata !51, metadata !17), !dbg !53
93 %8 = load double, double* %s, align 8, !dbg !54
94 store double %8, double* %x, align 8, !dbg !53
95 %9 = load double, double* %x, align 8, !dbg !55
96 %add = fadd double %9, 3.049000e+00, !dbg !56
97 %10 = load i32, i32* %u, align 4, !dbg !57
98 %conv6 = sitofp i32 %10 to double, !dbg !57
99 %add7 = fadd double %add, %conv6, !dbg !58
100 store double %add7, double* %s, align 8, !dbg !59
101 %11 = load double, double* %s, align 8, !dbg !60
102 %12 = load double, double* %x, align 8, !dbg !61
103 %div = fdiv double 3.940000e+00, %12, !dbg !62
104 %mul8 = fmul double %div, 3.200000e-01, !dbg !63
105 %add9 = fadd double %11, %mul8, !dbg !64
106 %13 = load double, double* %s, align 8, !dbg !65
107 %sub = fsub double %13, %add9, !dbg !65
108 store double %sub, double* %s, align 8, !dbg !65
109 br label %for.inc, !dbg !66
110
111for.inc: ; preds = %for.body
112 %14 = load i32, i32* %u, align 4, !dbg !67
113 %inc = add nsw i32 %14, 1, !dbg !67
114 store i32 %inc, i32* %u, align 4, !dbg !67
115 br label %for.cond, !dbg !68
116
117for.end: ; preds = %for.cond
118 %15 = load double, double* %s, align 8, !dbg !69
119 store double %15, double* %result, align 8, !dbg !70
120 br label %if.end.13, !dbg !71
121
122if.else: ; preds = %if.end
123 %16 = load i8**, i8*** %argv.addr, align 8, !dbg !72
124 %arrayidx10 = getelementptr inbounds i8*, i8** %16, i64 2, !dbg !72
125 %17 = load i8*, i8** %arrayidx10, align 8, !dbg !72
126 %call11 = call i32 @atoi(i8* %17) #4, !dbg !74
127 %conv12 = sitofp i32 %call11 to double, !dbg !74
128 store double %conv12, double* %result, align 8, !dbg !75
129 br label %if.end.13
130
131if.end.13: ; preds = %if.else, %for.end
132 %18 = load double, double* %result, align 8, !dbg !76
133 %call14 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([15 x i8], [15 x i8]* @.str, i32 0, i32 0), double %18), !dbg !77
134 store i32 0, i32* %retval, align 4, !dbg !78
135 br label %return, !dbg !78
136
137return: ; preds = %if.end.13, %if.then
138 %19 = load i32, i32* %retval, align 4, !dbg !79
139 ret i32 %19, !dbg !79
Diego Novillo8d6568b2013-11-13 12:22:21 +0000140}
141
Diego Novillo8d6568b2013-11-13 12:22:21 +0000142; Function Attrs: nounwind readnone
Dehao Chen7c41dd62015-10-01 00:26:56 +0000143declare void @llvm.dbg.declare(metadata, metadata, metadata) #1
Diego Novillo8d6568b2013-11-13 12:22:21 +0000144
Dehao Chen7c41dd62015-10-01 00:26:56 +0000145; Function Attrs: nounwind readonly
146declare i32 @atoi(i8*) #2
147
148declare i32 @printf(i8*, ...) #3
149
150attributes #0 = { uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" }
151attributes #1 = { nounwind readnone }
152attributes #2 = { nounwind readonly "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" }
153attributes #3 = { "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="true" "no-frame-pointer-elim-non-leaf" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" }
Diego Novillo8d6568b2013-11-13 12:22:21 +0000154attributes #4 = { nounwind readonly }
155
156!llvm.dbg.cu = !{!0}
Dehao Chen7c41dd62015-10-01 00:26:56 +0000157!llvm.module.flags = !{!13, !14}
158!llvm.ident = !{!15}
Diego Novillo8d6568b2013-11-13 12:22:21 +0000159
Adrian Prantl75819ae2016-04-15 15:57:41 +0000160!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 3.8.0 (trunk 248211) (llvm/trunk 248217)", isOptimized: false, runtimeVersion: 0, emissionKind: NoDebug, enums: !2, retainedTypes: !3)
Dehao Chen7c41dd62015-10-01 00:26:56 +0000161!1 = !DIFile(filename: "test.cc", directory: "/ssd/llvm_commit")
Duncan P. N. Exon Smith988a7f82015-03-27 20:46:33 +0000162!2 = !{}
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +0000163!3 = !{!4}
Dehao Chen7c41dd62015-10-01 00:26:56 +0000164!4 = !DIBasicType(name: "double", size: 64, align: 64, encoding: DW_ATE_float)
Adrian Prantl75819ae2016-04-15 15:57:41 +0000165!6 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 4, type: !7, isLocal: false, isDefinition: true, scopeLine: 4, flags: DIFlagPrototyped, isOptimized: false, unit: !0, variables: !2)
Dehao Chen7c41dd62015-10-01 00:26:56 +0000166!7 = !DISubroutineType(types: !8)
167!8 = !{!9, !9, !10}
168!9 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
169!10 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !11, size: 64, align: 64)
170!11 = !DIDerivedType(tag: DW_TAG_pointer_type, baseType: !12, size: 64, align: 64)
171!12 = !DIBasicType(name: "char", size: 8, align: 8, encoding: DW_ATE_signed_char)
172!13 = !{i32 2, !"Dwarf Version", i32 4}
173!14 = !{i32 2, !"Debug Info Version", i32 3}
174!15 = !{!"clang version 3.8.0 (trunk 248211) (llvm/trunk 248217)"}
175!16 = !DILocalVariable(name: "argc", arg: 1, scope: !6, file: !1, line: 4, type: !9)
176!17 = !DIExpression()
177!18 = !DILocation(line: 4, column: 15, scope: !6)
178!19 = !DILocalVariable(name: "argv", arg: 2, scope: !6, file: !1, line: 4, type: !10)
179!20 = !DILocation(line: 4, column: 27, scope: !6)
180!21 = !DILocation(line: 5, column: 8, scope: !22)
181!22 = distinct !DILexicalBlock(scope: !6, file: !1, line: 5, column: 8)
182!23 = !DILocation(line: 5, column: 13, scope: !22)
183!24 = !DILocation(line: 5, column: 8, scope: !6)
184!25 = !DILocation(line: 6, column: 6, scope: !22)
185!26 = !DILocalVariable(name: "result", scope: !6, file: !1, line: 7, type: !4)
186!27 = !DILocation(line: 7, column: 11, scope: !6)
187!28 = !DILocalVariable(name: "limit", scope: !6, file: !1, line: 8, type: !9)
188!29 = !DILocation(line: 8, column: 8, scope: !6)
189!30 = !DILocation(line: 8, column: 21, scope: !6)
190!31 = !DILocation(line: 8, column: 16, scope: !6)
191!32 = !DILocation(line: 9, column: 8, scope: !33)
192!33 = distinct !DILexicalBlock(scope: !6, file: !1, line: 9, column: 8)
193!34 = !DILocation(line: 9, column: 14, scope: !33)
194!35 = !DILocation(line: 9, column: 8, scope: !6)
195!36 = !DILocalVariable(name: "s", scope: !37, file: !1, line: 10, type: !4)
196!37 = distinct !DILexicalBlock(scope: !33, file: !1, line: 9, column: 21)
197!38 = !DILocation(line: 10, column: 13, scope: !37)
198!39 = !DILocation(line: 10, column: 34, scope: !37)
199!40 = !DILocation(line: 10, column: 29, scope: !37)
200!41 = !DILocation(line: 10, column: 27, scope: !37)
201!42 = !DILocalVariable(name: "u", scope: !43, file: !1, line: 11, type: !9)
202!43 = distinct !DILexicalBlock(scope: !37, file: !1, line: 11, column: 6)
203!44 = !DILocation(line: 11, column: 15, scope: !43)
204!45 = !DILocation(line: 11, column: 11, scope: !43)
205!46 = !DILocation(line: 11, column: 22, scope: !47)
206!47 = distinct !DILexicalBlock(scope: !43, file: !1, line: 11, column: 6)
207!48 = !DILocation(line: 11, column: 26, scope: !47)
208!49 = !DILocation(line: 11, column: 24, scope: !47)
209!50 = !DILocation(line: 11, column: 6, scope: !43)
210!51 = !DILocalVariable(name: "x", scope: !52, file: !1, line: 12, type: !4)
211!52 = distinct !DILexicalBlock(scope: !47, file: !1, line: 11, column: 38)
212!53 = !DILocation(line: 12, column: 15, scope: !52)
213!54 = !DILocation(line: 12, column: 19, scope: !52)
214!55 = !DILocation(line: 13, column: 12, scope: !52)
215!56 = !DILocation(line: 13, column: 14, scope: !52)
216!57 = !DILocation(line: 13, column: 32, scope: !52)
217!58 = !DILocation(line: 13, column: 22, scope: !52)
218!59 = !DILocation(line: 13, column: 10, scope: !52)
219!60 = !DILocation(line: 14, column: 13, scope: !52)
220!61 = !DILocation(line: 14, column: 24, scope: !52)
221!62 = !DILocation(line: 14, column: 22, scope: !52)
222!63 = !DILocation(line: 14, column: 26, scope: !52)
223!64 = !DILocation(line: 14, column: 15, scope: !52)
224!65 = !DILocation(line: 14, column: 10, scope: !52)
225!66 = !DILocation(line: 15, column: 6, scope: !52)
226!67 = !DILocation(line: 11, column: 34, scope: !47)
227!68 = !DILocation(line: 11, column: 6, scope: !47)
228!69 = !DILocation(line: 16, column: 15, scope: !37)
229!70 = !DILocation(line: 16, column: 13, scope: !37)
230!71 = !DILocation(line: 17, column: 4, scope: !37)
231!72 = !DILocation(line: 18, column: 20, scope: !73)
232!73 = distinct !DILexicalBlock(scope: !33, file: !1, line: 17, column: 11)
233!74 = !DILocation(line: 18, column: 15, scope: !73)
234!75 = !DILocation(line: 18, column: 13, scope: !73)
235!76 = !DILocation(line: 20, column: 30, scope: !6)
236!77 = !DILocation(line: 20, column: 4, scope: !6)
237!78 = !DILocation(line: 21, column: 4, scope: !6)
238!79 = !DILocation(line: 22, column: 2, scope: !6)