blob: 368da42fc8a1f22d97a3da731f66b8c12e98f9f1 [file] [log] [blame]
Diego Novilloc572e922014-10-30 18:00:06 +00001; The two profiles used in this test are the same but encoded in different
2; formats. This checks that we produce the same profile annotations regardless
3; of the profile format.
4;
5; RUN: opt < %s -sample-profile -sample-profile-file=%S/Inputs/fnptr.prof | opt -analyze -branch-prob | FileCheck %s
6; RUN: opt < %s -sample-profile -sample-profile-file=%S/Inputs/fnptr.binprof | opt -analyze -branch-prob | FileCheck %s
7
8; CHECK: edge for.body3 -> if.then probability is 534 / 2598 = 20.5543%
9; CHECK: edge for.body3 -> if.else probability is 2064 / 2598 = 79.4457%
10; CHECK: edge for.inc -> for.inc12 probability is 1052 / 2598 = 40.4927%
11; CHECK: edge for.inc -> for.body3 probability is 1546 / 2598 = 59.5073%
12; CHECK: edge for.inc12 -> for.end14 probability is 518 / 1052 = 49.2395%
13; CHECK: edge for.inc12 -> for.cond1.preheader probability is 534 / 1052 = 50.7605%
14
15; Original C++ test case.
16;
17; #include <stdlib.h>
18; #include <math.h>
19; #include <stdio.h>
20;
21; #define N 10000
22; #define M 6000
23;
24; double foo(int x) {
25; return x * sin((double)x);
26; }
27;
28; double bar(int x) {
29; return x - cos((double)x);
30; }
31;
32; int main() {
33; double (*fptr)(int);
34; double S = 0;
35; for (int i = 0; i < N; i++)
36; for (int j = 0; j < M; j++) {
37; fptr = (rand() % 100 < 30) ? foo : bar;
38; if (rand() % 100 < 10)
39; S += (*fptr)(i + j * 300);
40; else
41; S += (*fptr)(i - j / 840);
42; }
43; printf("S = %lf\n", S);
44; return 0;
45; }
46
47@.str = private unnamed_addr constant [9 x i8] c"S = %lf\0A\00", align 1
48
49define double @_Z3fooi(i32 %x) #0 {
50entry:
51 %conv = sitofp i32 %x to double, !dbg !2
52 %call = tail call double @sin(double %conv) #3, !dbg !8
53 %mul = fmul double %conv, %call, !dbg !8
54 ret double %mul, !dbg !8
55}
56
57declare double @sin(double) #1
58
59define double @_Z3bari(i32 %x) #0 {
60entry:
61 %conv = sitofp i32 %x to double, !dbg !9
62 %call = tail call double @cos(double %conv) #3, !dbg !11
63 %sub = fsub double %conv, %call, !dbg !11
64 ret double %sub, !dbg !11
65}
66
67declare double @cos(double) #1
68
69define i32 @main() #2 {
70entry:
71 br label %for.cond1.preheader, !dbg !12
72
73for.cond1.preheader: ; preds = %for.inc12, %entry
74 %i.025 = phi i32 [ 0, %entry ], [ %inc13, %for.inc12 ]
75 %S.024 = phi double [ 0.000000e+00, %entry ], [ %S.2.lcssa, %for.inc12 ]
76 br label %for.body3, !dbg !14
77
78for.body3: ; preds = %for.inc, %for.cond1.preheader
79 %j.023 = phi i32 [ 0, %for.cond1.preheader ], [ %inc, %for.inc ]
80 %S.122 = phi double [ %S.024, %for.cond1.preheader ], [ %S.2, %for.inc ]
81 %call = tail call i32 @rand() #3, !dbg !15
82 %rem = srem i32 %call, 100, !dbg !15
83 %cmp4 = icmp slt i32 %rem, 30, !dbg !15
84 %_Z3fooi._Z3bari = select i1 %cmp4, double (i32)* @_Z3fooi, double (i32)* @_Z3bari, !dbg !15
85 %call5 = tail call i32 @rand() #3, !dbg !16
86 %rem6 = srem i32 %call5, 100, !dbg !16
87 %cmp7 = icmp slt i32 %rem6, 10, !dbg !16
88 br i1 %cmp7, label %if.then, label %if.else, !dbg !16, !prof !17
89
90if.then: ; preds = %for.body3
91 %mul = mul nsw i32 %j.023, 300, !dbg !18
92 %add = add nsw i32 %mul, %i.025, !dbg !18
93 %call8 = tail call double %_Z3fooi._Z3bari(i32 %add), !dbg !18
94 br label %for.inc, !dbg !18
95
96if.else: ; preds = %for.body3
97 %div = sdiv i32 %j.023, 840, !dbg !19
98 %sub = sub nsw i32 %i.025, %div, !dbg !19
99 %call10 = tail call double %_Z3fooi._Z3bari(i32 %sub), !dbg !19
100 br label %for.inc
101
102for.inc: ; preds = %if.then, %if.else
103 %call8.pn = phi double [ %call8, %if.then ], [ %call10, %if.else ]
104 %S.2 = fadd double %S.122, %call8.pn, !dbg !18
105 %inc = add nsw i32 %j.023, 1, !dbg !20
106 %exitcond = icmp eq i32 %j.023, 5999, !dbg !14
107 br i1 %exitcond, label %for.inc12, label %for.body3, !dbg !14, !prof !21
108
109for.inc12: ; preds = %for.inc
110 %S.2.lcssa = phi double [ %S.2, %for.inc ]
111 %inc13 = add nsw i32 %i.025, 1, !dbg !22
112 %exitcond26 = icmp eq i32 %i.025, 9999, !dbg !12
113 br i1 %exitcond26, label %for.end14, label %for.cond1.preheader, !dbg !12, !prof !23
114
115for.end14: ; preds = %for.inc12
116 %S.2.lcssa.lcssa = phi double [ %S.2.lcssa, %for.inc12 ]
David Blaikie23af6482015-04-16 23:24:18 +0000117 %call15 = tail call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([9 x i8], [9 x i8]* @.str, i64 0, i64 0), double %S.2.lcssa.lcssa), !dbg !24
Diego Novilloc572e922014-10-30 18:00:06 +0000118 ret i32 0, !dbg !25
119}
120
121; Function Attrs: nounwind
122declare i32 @rand() #1
123
124; Function Attrs: nounwind
125declare i32 @printf(i8* nocapture readonly, ...) #1
126
127!llvm.module.flags = !{!0}
128!llvm.ident = !{!1}
129
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +0000130!0 = !{i32 2, !"Debug Info Version", i32 3}
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +0000131!1 = !{!"clang version 3.6.0 "}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000132!2 = !DILocation(line: 9, column: 3, scope: !3)
133!3 = !DISubprogram(name: "foo", line: 8, isLocal: false, isDefinition: true, flags: DIFlagPrototyped, isOptimized: true, scopeLine: 8, file: !4, scope: !5, type: !6, function: double (i32)* @_Z3fooi, variables: !7)
134!4 = !DIFile(filename: "fnptr.cc", directory: ".")
135!5 = !DIFile(filename: "fnptr.cc", directory: ".")
136!6 = !DISubroutineType(types: !7)
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +0000137!7 = !{}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000138!8 = !DILocation(line: 9, column: 14, scope: !3)
139!9 = !DILocation(line: 13, column: 3, scope: !10)
140!10 = !DISubprogram(name: "bar", line: 12, isLocal: false, isDefinition: true, flags: DIFlagPrototyped, isOptimized: true, scopeLine: 12, file: !4, scope: !5, type: !6, function: double (i32)* @_Z3bari, variables: !7)
141!11 = !DILocation(line: 13, column: 14, scope: !10)
142!12 = !DILocation(line: 19, column: 3, scope: !13)
143!13 = !DISubprogram(name: "main", line: 16, isLocal: false, isDefinition: true, flags: DIFlagPrototyped, isOptimized: true, scopeLine: 16, file: !4, scope: !5, type: !6, function: i32 ()* @main, variables: !7)
144!14 = !DILocation(line: 20, column: 5, scope: !13)
145!15 = !DILocation(line: 21, column: 15, scope: !13)
146!16 = !DILocation(line: 22, column: 11, scope: !13)
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +0000147!17 = !{!"branch_weights", i32 534, i32 2064}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000148!18 = !DILocation(line: 23, column: 14, scope: !13)
149!19 = !DILocation(line: 25, column: 14, scope: !13)
150!20 = !DILocation(line: 20, column: 28, scope: !13)
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +0000151!21 = !{!"branch_weights", i32 0, i32 1075}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000152!22 = !DILocation(line: 19, column: 26, scope: !13)
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +0000153!23 = !{!"branch_weights", i32 0, i32 534}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000154!24 = !DILocation(line: 27, column: 3, scope: !13)
155!25 = !DILocation(line: 28, column: 3, scope: !13)