blob: a0e6a9deb8a8579af211815d1798363d6f05f381 [file] [log] [blame]
Diego Novillo7963ea12015-10-26 18:52:53 +00001; RUN: opt < %s -sample-profile -sample-profile-file=%S/Inputs/remarks.prof -S -pass-remarks=sample-profile 2>&1 | FileCheck %s
2;
3; Original test case.
4;
5; 1 #include <stdlib.h>
6; 2
7; 3 long long foo() {
8; 4 long long int sum = 0;
9; 5 for (int i = 0; i < 500000000; i++)
10; 6 if (i < 1000)
11; 7 sum -= i;
12; 8 else
13; 9 sum += -i * rand();
14; 10 return sum;
15; 11 }
16; 12
17; 13 int main() { return foo() > 0; }
18
19; We are expecting foo() to be inlined in main() (almost all the cycles are
20; spent inside foo).
21; CHECK: remark: remarks.cc:13:21: inlined hot callee '_Z3foov' with 623868 samples into 'main'
22
23; The back edge for the loop is the hottest edge in the loop subgraph.
24; CHECK: remark: remarks.cc:6:9: most popular destination for conditional branches at remarks.cc:5:3
25
26; The predicate almost always chooses the 'else' branch.
27; CHECK: remark: remarks.cc:9:15: most popular destination for conditional branches at remarks.cc:6:9
28
29; Function Attrs: nounwind uwtable
Peter Collingbourned4bff302015-11-05 22:03:56 +000030define i64 @_Z3foov() #0 !dbg !4 {
Diego Novillo7963ea12015-10-26 18:52:53 +000031entry:
32 %sum = alloca i64, align 8
33 %i = alloca i32, align 4
34 %0 = bitcast i64* %sum to i8*, !dbg !19
35 call void @llvm.lifetime.start(i64 8, i8* %0) #4, !dbg !19
36 call void @llvm.dbg.declare(metadata i64* %sum, metadata !9, metadata !20), !dbg !21
37 store i64 0, i64* %sum, align 8, !dbg !21, !tbaa !22
38 %1 = bitcast i32* %i to i8*, !dbg !26
39 call void @llvm.lifetime.start(i64 4, i8* %1) #4, !dbg !26
40 call void @llvm.dbg.declare(metadata i32* %i, metadata !10, metadata !20), !dbg !27
41 store i32 0, i32* %i, align 4, !dbg !27, !tbaa !28
42 br label %for.cond, !dbg !26
43
44for.cond: ; preds = %for.inc, %entry
45 %2 = load i32, i32* %i, align 4, !dbg !30, !tbaa !28
46 %cmp = icmp slt i32 %2, 500000000, !dbg !34
47 br i1 %cmp, label %for.body, label %for.cond.cleanup, !dbg !35
48
49for.cond.cleanup: ; preds = %for.cond
50 %3 = bitcast i32* %i to i8*, !dbg !36
51 call void @llvm.lifetime.end(i64 4, i8* %3) #4, !dbg !36
52 br label %for.end
53
54for.body: ; preds = %for.cond
55 %4 = load i32, i32* %i, align 4, !dbg !38, !tbaa !28
56 %cmp1 = icmp slt i32 %4, 1000, !dbg !40
57 br i1 %cmp1, label %if.then, label %if.else, !dbg !41
58
59if.then: ; preds = %for.body
60 %5 = load i32, i32* %i, align 4, !dbg !42, !tbaa !28
61 %conv = sext i32 %5 to i64, !dbg !42
62 %6 = load i64, i64* %sum, align 8, !dbg !43, !tbaa !22
63 %sub = sub nsw i64 %6, %conv, !dbg !43
64 store i64 %sub, i64* %sum, align 8, !dbg !43, !tbaa !22
65 br label %if.end, !dbg !44
66
67if.else: ; preds = %for.body
68 %7 = load i32, i32* %i, align 4, !dbg !45, !tbaa !28
69 %sub2 = sub nsw i32 0, %7, !dbg !46
70 %call = call i32 @rand() #4, !dbg !47
71 %mul = mul nsw i32 %sub2, %call, !dbg !48
72 %conv3 = sext i32 %mul to i64, !dbg !46
73 %8 = load i64, i64* %sum, align 8, !dbg !49, !tbaa !22
74 %add = add nsw i64 %8, %conv3, !dbg !49
75 store i64 %add, i64* %sum, align 8, !dbg !49, !tbaa !22
76 br label %if.end
77
78if.end: ; preds = %if.else, %if.then
79 br label %for.inc, !dbg !50
80
81for.inc: ; preds = %if.end
82 %9 = load i32, i32* %i, align 4, !dbg !51, !tbaa !28
83 %inc = add nsw i32 %9, 1, !dbg !51
84 store i32 %inc, i32* %i, align 4, !dbg !51, !tbaa !28
85 br label %for.cond, !dbg !52
86
87for.end: ; preds = %for.cond.cleanup
88 %10 = load i64, i64* %sum, align 8, !dbg !53, !tbaa !22
89 %11 = bitcast i64* %sum to i8*, !dbg !54
90 call void @llvm.lifetime.end(i64 8, i8* %11) #4, !dbg !54
91 ret i64 %10, !dbg !55
92}
93
94; Function Attrs: nounwind argmemonly
95declare void @llvm.lifetime.start(i64, i8* nocapture) #1
96
97; Function Attrs: nounwind readnone
98declare void @llvm.dbg.declare(metadata, metadata, metadata) #2
99
100; Function Attrs: nounwind
101declare i32 @rand() #3
102
103; Function Attrs: nounwind argmemonly
104declare void @llvm.lifetime.end(i64, i8* nocapture) #1
105
106; Function Attrs: nounwind uwtable
Peter Collingbourned4bff302015-11-05 22:03:56 +0000107define i32 @main() #0 !dbg !13 {
Diego Novillo7963ea12015-10-26 18:52:53 +0000108entry:
109 %retval = alloca i32, align 4
110 store i32 0, i32* %retval, align 4
111 %call = call i64 @_Z3foov(), !dbg !56
112 %cmp = icmp sgt i64 %call, 0, !dbg !57
113 %conv = zext i1 %cmp to i32, !dbg !56
114 ret i32 %conv, !dbg !58
115}
116
117attributes #0 = { nounwind uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" }
118attributes #1 = { nounwind argmemonly }
119attributes #2 = { nounwind readnone }
120attributes #3 = { nounwind "disable-tail-calls"="false" "less-precise-fpmad"="false" "no-frame-pointer-elim"="false" "no-infs-fp-math"="false" "no-nans-fp-math"="false" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+fxsr,+mmx,+sse,+sse2" "unsafe-fp-math"="false" "use-soft-float"="false" }
121attributes #4 = { nounwind }
122
123!llvm.dbg.cu = !{!0}
124!llvm.module.flags = !{!16, !17}
125!llvm.ident = !{!18}
126
127!0 = distinct !DICompileUnit(language: DW_LANG_C_plus_plus, file: !1, producer: "clang version 3.8.0 (trunk 251041) (llvm/trunk 251053)", isOptimized: true, runtimeVersion: 0, emissionKind: 1, enums: !2, subprograms: !3)
128!1 = !DIFile(filename: "remarks.cc", directory: ".")
129!2 = !{}
130!3 = !{!4, !13}
Peter Collingbourned4bff302015-11-05 22:03:56 +0000131!4 = distinct !DISubprogram(name: "foo", linkageName: "_Z3foov", scope: !1, file: !1, line: 3, type: !5, isLocal: false, isDefinition: true, scopeLine: 3, flags: DIFlagPrototyped, isOptimized: true, variables: !8)
Diego Novillo7963ea12015-10-26 18:52:53 +0000132!5 = !DISubroutineType(types: !6)
133!6 = !{!7}
134!7 = !DIBasicType(name: "long long int", size: 64, align: 64, encoding: DW_ATE_signed)
135!8 = !{!9, !10}
136!9 = !DILocalVariable(name: "sum", scope: !4, file: !1, line: 4, type: !7)
137!10 = !DILocalVariable(name: "i", scope: !11, file: !1, line: 5, type: !12)
138!11 = distinct !DILexicalBlock(scope: !4, file: !1, line: 5, column: 3)
139!12 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
Peter Collingbourned4bff302015-11-05 22:03:56 +0000140!13 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 13, type: !14, isLocal: false, isDefinition: true, scopeLine: 13, flags: DIFlagPrototyped, isOptimized: true, variables: !2)
Diego Novillo7963ea12015-10-26 18:52:53 +0000141!14 = !DISubroutineType(types: !15)
142!15 = !{!12}
143!16 = !{i32 2, !"Dwarf Version", i32 4}
144!17 = !{i32 2, !"Debug Info Version", i32 3}
145!18 = !{!"clang version 3.8.0 (trunk 251041) (llvm/trunk 251053)"}
146!19 = !DILocation(line: 4, column: 3, scope: !4)
147!20 = !DIExpression()
148!21 = !DILocation(line: 4, column: 17, scope: !4)
149!22 = !{!23, !23, i64 0}
150!23 = !{!"long long", !24, i64 0}
151!24 = !{!"omnipotent char", !25, i64 0}
152!25 = !{!"Simple C/C++ TBAA"}
153!26 = !DILocation(line: 5, column: 8, scope: !11)
154!27 = !DILocation(line: 5, column: 12, scope: !11)
155!28 = !{!29, !29, i64 0}
156!29 = !{!"int", !24, i64 0}
157!30 = !DILocation(line: 5, column: 19, scope: !31)
158!31 = !DILexicalBlockFile(scope: !32, file: !1, discriminator: 3)
159!32 = !DILexicalBlockFile(scope: !33, file: !1, discriminator: 1)
160!33 = distinct !DILexicalBlock(scope: !11, file: !1, line: 5, column: 3)
161!34 = !DILocation(line: 5, column: 21, scope: !33)
162!35 = !DILocation(line: 5, column: 3, scope: !11)
163!36 = !DILocation(line: 5, column: 3, scope: !37)
164!37 = !DILexicalBlockFile(scope: !33, file: !1, discriminator: 2)
165!38 = !DILocation(line: 6, column: 9, scope: !39)
166!39 = distinct !DILexicalBlock(scope: !33, file: !1, line: 6, column: 9)
167!40 = !DILocation(line: 6, column: 11, scope: !39)
168!41 = !DILocation(line: 6, column: 9, scope: !33)
169!42 = !DILocation(line: 7, column: 14, scope: !39)
170!43 = !DILocation(line: 7, column: 11, scope: !39)
171!44 = !DILocation(line: 7, column: 7, scope: !39)
172!45 = !DILocation(line: 9, column: 15, scope: !39)
173!46 = !DILocation(line: 9, column: 14, scope: !39)
174!47 = !DILocation(line: 9, column: 19, scope: !39)
175!48 = !DILocation(line: 9, column: 17, scope: !39)
176!49 = !DILocation(line: 9, column: 11, scope: !39)
177!50 = !DILocation(line: 6, column: 13, scope: !39)
178!51 = !DILocation(line: 5, column: 35, scope: !33)
179!52 = !DILocation(line: 5, column: 3, scope: !33)
180!53 = !DILocation(line: 10, column: 10, scope: !4)
181!54 = !DILocation(line: 11, column: 1, scope: !4)
182!55 = !DILocation(line: 10, column: 3, scope: !4)
183!56 = !DILocation(line: 13, column: 21, scope: !13)
184!57 = !DILocation(line: 13, column: 27, scope: !13)
185!58 = !DILocation(line: 13, column: 14, scope: !13)