blob: eef7b162eb7a58b82d8f98b083973b225fbe92e6 [file] [log] [blame]
Diego Novillo0accb3d2014-01-10 23:23:46 +00001; RUN: opt < %s -sample-profile -sample-profile-file=%S/Inputs/propagate.prof | opt -analyze -branch-prob | FileCheck %s
2
3; Original C++ code for this test case:
4;
5; #include <stdio.h>
6;
7; long foo(int x, int y, long N) {
8; if (x < y) {
9; return y - x;
10; } else {
11; for (long i = 0; i < N; i++) {
12; if (i > N / 3)
13; x--;
14; if (i > N / 4) {
15; y++;
16; x += 3;
17; } else {
18; for (unsigned j = 0; j < i; j++) {
19; x += j;
20; y -= 3;
21; }
22; }
23; }
24; }
25; return y * x;
26; }
27;
28; int main() {
29; int x = 5678;
30; int y = 1234;
31; long N = 999999;
32; printf("foo(%d, %d, %ld) = %ld\n", x, y, N, foo(x, y, N));
33; return 0;
34; }
35
36; ModuleID = 'propagate.cc'
37target datalayout = "e-p:64:64:64-i1:8:8-i8:8:8-i16:16:16-i32:32:32-i64:64:64-f32:32:32-f64:64:64-v64:64:64-v128:128:128-a0:0:64-s0:64:64-f80:128:128-n8:16:32:64-S128"
38target triple = "x86_64-unknown-linux-gnu"
39
40@.str = private unnamed_addr constant [24 x i8] c"foo(%d, %d, %ld) = %ld\0A\00", align 1
41
42; Function Attrs: nounwind uwtable
Peter Collingbourned4bff302015-11-05 22:03:56 +000043define i64 @_Z3fooiil(i32 %x, i32 %y, i64 %N) #0 !dbg !4 {
Diego Novillo0accb3d2014-01-10 23:23:46 +000044entry:
45 %retval = alloca i64, align 8
46 %x.addr = alloca i32, align 4
47 %y.addr = alloca i32, align 4
48 %N.addr = alloca i64, align 8
49 %i = alloca i64, align 8
50 %j = alloca i32, align 4
51 store i32 %x, i32* %x.addr, align 4
52 store i32 %y, i32* %y.addr, align 4
53 store i64 %N, i64* %N.addr, align 8
David Blaikiea79ac142015-02-27 21:17:42 +000054 %0 = load i32, i32* %x.addr, align 4, !dbg !11
55 %1 = load i32, i32* %y.addr, align 4, !dbg !11
Diego Novillo0accb3d2014-01-10 23:23:46 +000056 %cmp = icmp slt i32 %0, %1, !dbg !11
57 br i1 %cmp, label %if.then, label %if.else, !dbg !11
58
59if.then: ; preds = %entry
David Blaikiea79ac142015-02-27 21:17:42 +000060 %2 = load i32, i32* %y.addr, align 4, !dbg !13
61 %3 = load i32, i32* %x.addr, align 4, !dbg !13
Diego Novillo0accb3d2014-01-10 23:23:46 +000062 %sub = sub nsw i32 %2, %3, !dbg !13
63 %conv = sext i32 %sub to i64, !dbg !13
64 store i64 %conv, i64* %retval, !dbg !13
65 br label %return, !dbg !13
66
67if.else: ; preds = %entry
68 store i64 0, i64* %i, align 8, !dbg !15
69 br label %for.cond, !dbg !15
70
71for.cond: ; preds = %for.inc16, %if.else
David Blaikiea79ac142015-02-27 21:17:42 +000072 %4 = load i64, i64* %i, align 8, !dbg !15
73 %5 = load i64, i64* %N.addr, align 8, !dbg !15
Diego Novillo0accb3d2014-01-10 23:23:46 +000074 %cmp1 = icmp slt i64 %4, %5, !dbg !15
75 br i1 %cmp1, label %for.body, label %for.end18, !dbg !15
Dehao Chen7c41dd62015-10-01 00:26:56 +000076; CHECK: edge for.cond -> for.body probability is 0x745d1746 / 0x80000000 = 90.91% [HOT edge]
77; CHECK: edge for.cond -> for.end18 probability is 0x0ba2e8ba / 0x80000000 = 9.09%
Diego Novillo0accb3d2014-01-10 23:23:46 +000078
79for.body: ; preds = %for.cond
David Blaikiea79ac142015-02-27 21:17:42 +000080 %6 = load i64, i64* %i, align 8, !dbg !18
81 %7 = load i64, i64* %N.addr, align 8, !dbg !18
Diego Novillo0accb3d2014-01-10 23:23:46 +000082 %div = sdiv i64 %7, 3, !dbg !18
83 %cmp2 = icmp sgt i64 %6, %div, !dbg !18
84 br i1 %cmp2, label %if.then3, label %if.end, !dbg !18
Cong Hou15ea0162015-09-25 23:09:59 +000085; CHECK: edge for.body -> if.then3 probability is 0x1999999a / 0x80000000 = 20.00%
86; CHECK: edge for.body -> if.end probability is 0x66666666 / 0x80000000 = 80.00%
Diego Novillo0accb3d2014-01-10 23:23:46 +000087
88if.then3: ; preds = %for.body
David Blaikiea79ac142015-02-27 21:17:42 +000089 %8 = load i32, i32* %x.addr, align 4, !dbg !21
Diego Novillo0accb3d2014-01-10 23:23:46 +000090 %dec = add nsw i32 %8, -1, !dbg !21
91 store i32 %dec, i32* %x.addr, align 4, !dbg !21
92 br label %if.end, !dbg !21
93
94if.end: ; preds = %if.then3, %for.body
David Blaikiea79ac142015-02-27 21:17:42 +000095 %9 = load i64, i64* %i, align 8, !dbg !22
96 %10 = load i64, i64* %N.addr, align 8, !dbg !22
Diego Novillo0accb3d2014-01-10 23:23:46 +000097 %div4 = sdiv i64 %10, 4, !dbg !22
98 %cmp5 = icmp sgt i64 %9, %div4, !dbg !22
99 br i1 %cmp5, label %if.then6, label %if.else7, !dbg !22
Cong Hou15ea0162015-09-25 23:09:59 +0000100; CHECK: edge if.end -> if.then6 probability is 0x000f801f / 0x80000000 = 0.05%
101; CHECK: edge if.end -> if.else7 probability is 0x7ff07fe1 / 0x80000000 = 99.95% [HOT edge]
Diego Novillo0accb3d2014-01-10 23:23:46 +0000102
103if.then6: ; preds = %if.end
David Blaikiea79ac142015-02-27 21:17:42 +0000104 %11 = load i32, i32* %y.addr, align 4, !dbg !24
Diego Novillo0accb3d2014-01-10 23:23:46 +0000105 %inc = add nsw i32 %11, 1, !dbg !24
106 store i32 %inc, i32* %y.addr, align 4, !dbg !24
David Blaikiea79ac142015-02-27 21:17:42 +0000107 %12 = load i32, i32* %x.addr, align 4, !dbg !26
Diego Novillo0accb3d2014-01-10 23:23:46 +0000108 %add = add nsw i32 %12, 3, !dbg !26
109 store i32 %add, i32* %x.addr, align 4, !dbg !26
110 br label %if.end15, !dbg !27
111
112if.else7: ; preds = %if.end
113 store i32 0, i32* %j, align 4, !dbg !28
114 br label %for.cond8, !dbg !28
115
116for.cond8: ; preds = %for.inc, %if.else7
David Blaikiea79ac142015-02-27 21:17:42 +0000117 %13 = load i32, i32* %j, align 4, !dbg !28
Diego Novillo0accb3d2014-01-10 23:23:46 +0000118 %conv9 = zext i32 %13 to i64, !dbg !28
David Blaikiea79ac142015-02-27 21:17:42 +0000119 %14 = load i64, i64* %i, align 8, !dbg !28
Diego Novillo0accb3d2014-01-10 23:23:46 +0000120 %cmp10 = icmp slt i64 %conv9, %14, !dbg !28
121 br i1 %cmp10, label %for.body11, label %for.end, !dbg !28
Dehao Chen7c41dd62015-10-01 00:26:56 +0000122; CHECK: edge for.cond8 -> for.body11 probability is 0x5bfc7472 / 0x80000000 = 71.86%
123; CHECK: edge for.cond8 -> for.end probability is 0x24038b8e / 0x80000000 = 28.14%
Diego Novillo0accb3d2014-01-10 23:23:46 +0000124
125for.body11: ; preds = %for.cond8
David Blaikiea79ac142015-02-27 21:17:42 +0000126 %15 = load i32, i32* %j, align 4, !dbg !31
127 %16 = load i32, i32* %x.addr, align 4, !dbg !31
Diego Novillo0accb3d2014-01-10 23:23:46 +0000128 %add12 = add i32 %16, %15, !dbg !31
129 store i32 %add12, i32* %x.addr, align 4, !dbg !31
David Blaikiea79ac142015-02-27 21:17:42 +0000130 %17 = load i32, i32* %y.addr, align 4, !dbg !33
Diego Novillo0accb3d2014-01-10 23:23:46 +0000131 %sub13 = sub nsw i32 %17, 3, !dbg !33
132 store i32 %sub13, i32* %y.addr, align 4, !dbg !33
133 br label %for.inc, !dbg !34
134
135for.inc: ; preds = %for.body11
David Blaikiea79ac142015-02-27 21:17:42 +0000136 %18 = load i32, i32* %j, align 4, !dbg !28
Diego Novillo0accb3d2014-01-10 23:23:46 +0000137 %inc14 = add i32 %18, 1, !dbg !28
138 store i32 %inc14, i32* %j, align 4, !dbg !28
139 br label %for.cond8, !dbg !28
140
141for.end: ; preds = %for.cond8
142 br label %if.end15
143
144if.end15: ; preds = %for.end, %if.then6
145 br label %for.inc16, !dbg !35
146
147for.inc16: ; preds = %if.end15
David Blaikiea79ac142015-02-27 21:17:42 +0000148 %19 = load i64, i64* %i, align 8, !dbg !15
Diego Novillo0accb3d2014-01-10 23:23:46 +0000149 %inc17 = add nsw i64 %19, 1, !dbg !15
150 store i64 %inc17, i64* %i, align 8, !dbg !15
151 br label %for.cond, !dbg !15
152
153for.end18: ; preds = %for.cond
154 br label %if.end19
155
156if.end19: ; preds = %for.end18
David Blaikiea79ac142015-02-27 21:17:42 +0000157 %20 = load i32, i32* %y.addr, align 4, !dbg !36
158 %21 = load i32, i32* %x.addr, align 4, !dbg !36
Diego Novillo0accb3d2014-01-10 23:23:46 +0000159 %mul = mul nsw i32 %20, %21, !dbg !36
160 %conv20 = sext i32 %mul to i64, !dbg !36
161 store i64 %conv20, i64* %retval, !dbg !36
162 br label %return, !dbg !36
163
164return: ; preds = %if.end19, %if.then
David Blaikiea79ac142015-02-27 21:17:42 +0000165 %22 = load i64, i64* %retval, !dbg !37
Diego Novillo0accb3d2014-01-10 23:23:46 +0000166 ret i64 %22, !dbg !37
167}
168
169; Function Attrs: uwtable
Peter Collingbourned4bff302015-11-05 22:03:56 +0000170define i32 @main() #1 !dbg !7 {
Diego Novillo0accb3d2014-01-10 23:23:46 +0000171entry:
172 %retval = alloca i32, align 4
173 %x = alloca i32, align 4
174 %y = alloca i32, align 4
175 %N = alloca i64, align 8
176 store i32 0, i32* %retval
177 store i32 5678, i32* %x, align 4, !dbg !38
178 store i32 1234, i32* %y, align 4, !dbg !39
179 store i64 999999, i64* %N, align 8, !dbg !40
David Blaikiea79ac142015-02-27 21:17:42 +0000180 %0 = load i32, i32* %x, align 4, !dbg !41
181 %1 = load i32, i32* %y, align 4, !dbg !41
182 %2 = load i64, i64* %N, align 8, !dbg !41
183 %3 = load i32, i32* %x, align 4, !dbg !41
184 %4 = load i32, i32* %y, align 4, !dbg !41
185 %5 = load i64, i64* %N, align 8, !dbg !41
Diego Novillo0accb3d2014-01-10 23:23:46 +0000186 %call = call i64 @_Z3fooiil(i32 %3, i32 %4, i64 %5), !dbg !41
David Blaikie23af6482015-04-16 23:24:18 +0000187 %call1 = call i32 (i8*, ...) @printf(i8* getelementptr inbounds ([24 x i8], [24 x i8]* @.str, i32 0, i32 0), i32 %0, i32 %1, i64 %2, i64 %call), !dbg !41
Diego Novillo0accb3d2014-01-10 23:23:46 +0000188 ret i32 0, !dbg !42
189}
190
191declare i32 @printf(i8*, ...) #2
192
193attributes #0 = { nounwind uwtable "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" "unsafe-fp-math"="false" "use-soft-float"="false" }
194attributes #1 = { uwtable "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" "unsafe-fp-math"="false" "use-soft-float"="false" }
195attributes #2 = { "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" "unsafe-fp-math"="false" "use-soft-float"="false" }
196
197!llvm.dbg.cu = !{!0}
198!llvm.module.flags = !{!8, !9}
199!llvm.ident = !{!10}
200
Duncan P. N. Exon Smith55ca9642015-08-03 17:26:41 +0000201!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, producer: "clang version 3.5 ", isOptimized: false, emissionKind: 0, file: !1, enums: !2, retainedTypes: !2, subprograms: !3, globals: !2, imports: !2)
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000202!1 = !DIFile(filename: "propagate.cc", directory: ".")
Duncan P. N. Exon Smithb7865722015-03-16 21:10:12 +0000203!2 = !{}
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +0000204!3 = !{!4, !7}
Peter Collingbourned4bff302015-11-05 22:03:56 +0000205!4 = distinct !DISubprogram(name: "foo", line: 3, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, scopeLine: 3, file: !1, scope: !5, type: !6, variables: !2)
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000206!5 = !DIFile(filename: "propagate.cc", directory: ".")
207!6 = !DISubroutineType(types: !{null})
Peter Collingbourned4bff302015-11-05 22:03:56 +0000208!7 = distinct !DISubprogram(name: "main", line: 24, isLocal: false, isDefinition: true, virtualIndex: 6, flags: DIFlagPrototyped, isOptimized: false, scopeLine: 24, file: !1, scope: !5, type: !6, variables: !2)
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +0000209!8 = !{i32 2, !"Dwarf Version", i32 4}
Duncan P. N. Exon Smithe2741802015-03-03 17:24:31 +0000210!9 = !{i32 1, !"Debug Info Version", i32 3}
Duncan P. N. Exon Smithbe7ea192014-12-15 19:07:53 +0000211!10 = !{!"clang version 3.5 "}
Duncan P. N. Exon Smitha9308c42015-04-29 16:38:44 +0000212!11 = !DILocation(line: 4, scope: !12)
213!12 = distinct !DILexicalBlock(line: 4, column: 0, file: !1, scope: !4)
214!13 = !DILocation(line: 5, scope: !14)
215!14 = distinct !DILexicalBlock(line: 4, column: 0, file: !1, scope: !12)
216!15 = !DILocation(line: 7, scope: !16)
217!16 = distinct !DILexicalBlock(line: 7, column: 0, file: !1, scope: !17)
218!17 = distinct !DILexicalBlock(line: 6, column: 0, file: !1, scope: !12)
219!18 = !DILocation(line: 8, scope: !19)
220!19 = distinct !DILexicalBlock(line: 8, column: 0, file: !1, scope: !20)
221!20 = distinct !DILexicalBlock(line: 7, column: 0, file: !1, scope: !16)
222!21 = !DILocation(line: 9, scope: !19)
223!22 = !DILocation(line: 10, scope: !23)
224!23 = distinct !DILexicalBlock(line: 10, column: 0, file: !1, scope: !20)
225!24 = !DILocation(line: 11, scope: !25)
226!25 = distinct !DILexicalBlock(line: 10, column: 0, file: !1, scope: !23)
227!26 = !DILocation(line: 12, scope: !25)
228!27 = !DILocation(line: 13, scope: !25)
229!28 = !DILocation(line: 14, scope: !29)
230!29 = distinct !DILexicalBlock(line: 14, column: 0, file: !1, scope: !30)
231!30 = distinct !DILexicalBlock(line: 13, column: 0, file: !1, scope: !23)
232!31 = !DILocation(line: 15, scope: !32)
233!32 = distinct !DILexicalBlock(line: 14, column: 0, file: !1, scope: !29)
234!33 = !DILocation(line: 16, scope: !32)
235!34 = !DILocation(line: 17, scope: !32)
236!35 = !DILocation(line: 19, scope: !20)
237!36 = !DILocation(line: 21, scope: !4)
238!37 = !DILocation(line: 22, scope: !4)
239!38 = !DILocation(line: 25, scope: !7)
240!39 = !DILocation(line: 26, scope: !7)
241!40 = !DILocation(line: 27, scope: !7)
242!41 = !DILocation(line: 28, scope: !7)
243!42 = !DILocation(line: 29, scope: !7)