• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1; RUN: opt < %s -sample-profile -sample-profile-file=%S/Inputs/remarks.prof -S -pass-remarks=sample-profile -pass-remarks-output=%t.opt.yaml 2>&1 | FileCheck %s
2; RUN: FileCheck %s -check-prefix=YAML < %t.opt.yaml
3; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/remarks.prof -S -pass-remarks=sample-profile -pass-remarks-output=%t.opt.yaml 2>&1 | FileCheck %s
4; RUN: FileCheck %s -check-prefix=YAML < %t.opt.yaml
5
6; Original test case.
7;
8;     1    #include <stdlib.h>
9;     2
10;     3    long long foo() {
11;     4      long long int sum = 0;
12;     5      for (int i = 0; i < 500000000; i++)
13;     6        if (i < 1000)
14;     7          sum -= i;
15;     8        else
16;     9          sum += -i * rand();
17;    10      return sum;
18;    11    }
19;    12
20;    13    int main() { return foo() > 0; }
21
22; We are expecting foo() to be inlined in main() (almost all the cycles are
23; spent inside foo).
24; CHECK: remark: remarks.cc:13:21: _Z3foov inlined into main to match profiling context with (cost=130, threshold=225) at callsite main:0
25; CHECK: remark: remarks.cc:9:19: rand inlined into main to match profiling context with (cost=always): always inline attribute at callsite _Z3foov:6 @ main:0
26
27; The back edge for the loop is the hottest edge in the loop subgraph.
28; CHECK: remark: remarks.cc:6:9: most popular destination for conditional branches at remarks.cc:5:3
29
30; The predicate almost always chooses the 'else' branch.
31; CHECK: remark: remarks.cc:9:15: most popular destination for conditional branches at remarks.cc:6:9
32
33; Checking to see if YAML file is generated and contains remarks
34;YAML:       --- !Passed
35;YAML-NEXT:  Pass:            sample-profile-inline
36;YAML-NEXT:  Name:            Inlined
37;YAML-NEXT:  DebugLoc:        { File: remarks.cc, Line: 13, Column: 21 }
38;YAML-NEXT:  Function:        main
39;YAML-NEXT:  Args:
40;YAML-NEXT:    - Callee:          _Z3foov
41;YAML-NEXT:      DebugLoc:        { File: remarks.cc, Line: 3, Column: 0 }
42;YAML-NEXT:    - String:          ' inlined into '
43;YAML-NEXT:    - Caller:          main
44;YAML-NEXT:        DebugLoc:        { File: remarks.cc, Line: 13, Column: 0 }
45;YAML-NEXT:    - String:          ' to match profiling context'
46;YAML-NEXT:    - String:          ' with '
47;YAML-NEXT:    - String:          '(cost='
48;YAML-NEXT:    - Cost:            '130'
49;YAML-NEXT:    - String:          ', threshold='
50;YAML-NEXT:    - Threshold:       '225'
51;YAML-NEXT:    - String:          ')'
52;YAML-NEXT:    - String:          ' at callsite '
53;YAML-NEXT:    - String:          main
54;YAML-NEXT:    - String:          ':'
55;YAML-NEXT:    - Line:            '0'
56;YAML-NEXT:  ...
57;YAML:       --- !Passed
58;YAML-NEXT:  Pass:            sample-profile-inline
59;YAML-NEXT:  Name:            AlwaysInline
60;YAML-NEXT:  DebugLoc:        { File: remarks.cc, Line: 9, Column: 19 }
61;YAML-NEXT:  Function:        main
62;YAML-NEXT:  Args:
63;YAML-NEXT:    - Callee:          rand
64;YAML-NEXT:      DebugLoc:        { File: remarks.cc, Line: 90, Column: 0 }
65;YAML-NEXT:    - String:          ' inlined into '
66;YAML-NEXT:    - Caller:          main
67;YAML-NEXT:      DebugLoc:        { File: remarks.cc, Line: 13, Column: 0 }
68;YAML-NEXT:    - String:          ' to match profiling context'
69;YAML-NEXT:    - String:          ' with '
70;YAML-NEXT:    - String:          '(cost=always)'
71;YAML-NEXT:    - String:          ': '
72;YAML-NEXT:    - Reason:          always inline attribute
73;YAML-NEXT:    - String:          ' at callsite '
74;YAML-NEXT:    - String:          _Z3foov
75;YAML-NEXT:    - String:          ':'
76;YAML-NEXT:    - Line:            '6'
77;YAML-NEXT:    - String:          ' @ '
78;YAML-NEXT:    - String:          main
79;YAML-NEXT:    - String:          ':'
80;YAML-NEXT:    - Line:            '0'
81;YAML:  --- !Analysis
82;YAML-NEXT:  Pass:            sample-profile
83;YAML-NEXT:  Name:            AppliedSamples
84;YAML-NEXT:  DebugLoc:        { File: remarks.cc, Line: 5, Column: 8 }
85;YAML-NEXT:  Function:        main
86;YAML-NEXT:  Args:
87;YAML-NEXT:    - String:          'Applied '
88;YAML-NEXT:    - NumSamples:      '18305'
89;YAML-NEXT:    - String:          ' samples from profile (offset: '
90;YAML-NEXT:    - LineOffset:      '2'
91;YAML-NEXT:    - String:          ')'
92;YAML-NEXT:  ...
93;YAML:  --- !Passed
94;YAML-NEXT:  Pass:            sample-profile
95;YAML-NEXT:  Name:            PopularDest
96;YAML-NEXT:  DebugLoc:        { File: remarks.cc, Line: 6, Column: 9 }
97;YAML-NEXT:  Function:        main
98;YAML-NEXT:  Args:
99;YAML-NEXT:    - String:          'most popular destination for conditional branches at '
100;YAML-NEXT:    - CondBranchesLoc: 'remarks.cc:5:3'
101;YAML-NEXT:      DebugLoc:        { File: remarks.cc, Line: 5, Column: 3 }
102;YAML-NEXT:  ...
103
104; Function Attrs: nounwind uwtable
105define i64 @_Z3foov() #0 !dbg !4 {
106entry:
107  %sum = alloca i64, align 8
108  %i = alloca i32, align 4
109  %0 = bitcast i64* %sum to i8*, !dbg !19
110  call void @llvm.lifetime.start.p0i8(i64 8, i8* %0) #4, !dbg !19
111  call void @llvm.dbg.declare(metadata i64* %sum, metadata !9, metadata !20), !dbg !21
112  store i64 0, i64* %sum, align 8, !dbg !21, !tbaa !22
113  %1 = bitcast i32* %i to i8*, !dbg !26
114  call void @llvm.lifetime.start.p0i8(i64 4, i8* %1) #4, !dbg !26
115  call void @llvm.dbg.declare(metadata i32* %i, metadata !10, metadata !20), !dbg !27
116  store i32 0, i32* %i, align 4, !dbg !27, !tbaa !28
117  br label %for.cond, !dbg !26
118
119for.cond:                                         ; preds = %for.inc, %entry
120  %2 = load i32, i32* %i, align 4, !dbg !30, !tbaa !28
121  %cmp = icmp slt i32 %2, 500000000, !dbg !34
122  br i1 %cmp, label %for.body, label %for.cond.cleanup, !dbg !35
123
124for.cond.cleanup:                                 ; preds = %for.cond
125  %3 = bitcast i32* %i to i8*, !dbg !36
126  call void @llvm.lifetime.end.p0i8(i64 4, i8* %3) #4, !dbg !36
127  br label %for.end
128
129for.body:                                         ; preds = %for.cond
130  %4 = load i32, i32* %i, align 4, !dbg !38, !tbaa !28
131  %cmp1 = icmp slt i32 %4, 1000, !dbg !40
132  br i1 %cmp1, label %if.then, label %if.else, !dbg !41
133
134if.then:                                          ; preds = %for.body
135  %5 = load i32, i32* %i, align 4, !dbg !42, !tbaa !28
136  %conv = sext i32 %5 to i64, !dbg !42
137  %6 = load i64, i64* %sum, align 8, !dbg !43, !tbaa !22
138  %sub = sub nsw i64 %6, %conv, !dbg !43
139  store i64 %sub, i64* %sum, align 8, !dbg !43, !tbaa !22
140  br label %if.end, !dbg !44
141
142if.else:                                          ; preds = %for.body
143  %7 = load i32, i32* %i, align 4, !dbg !45, !tbaa !28
144  %sub2 = sub nsw i32 0, %7, !dbg !46
145  %call = call i32 @rand() #4, !dbg !47
146  %mul = mul nsw i32 %sub2, %call, !dbg !48
147  %conv3 = sext i32 %mul to i64, !dbg !46
148  %8 = load i64, i64* %sum, align 8, !dbg !49, !tbaa !22
149  %add = add nsw i64 %8, %conv3, !dbg !49
150  store i64 %add, i64* %sum, align 8, !dbg !49, !tbaa !22
151  br label %if.end
152
153if.end:                                           ; preds = %if.else, %if.then
154  br label %for.inc, !dbg !50
155
156for.inc:                                          ; preds = %if.end
157  %9 = load i32, i32* %i, align 4, !dbg !51, !tbaa !28
158  %inc = add nsw i32 %9, 1, !dbg !51
159  store i32 %inc, i32* %i, align 4, !dbg !51, !tbaa !28
160  br label %for.cond, !dbg !52
161
162for.end:                                          ; preds = %for.cond.cleanup
163  %10 = load i64, i64* %sum, align 8, !dbg !53, !tbaa !22
164  %11 = bitcast i64* %sum to i8*, !dbg !54
165  call void @llvm.lifetime.end.p0i8(i64 8, i8* %11) #4, !dbg !54
166  ret i64 %10, !dbg !55
167}
168
169; Function Attrs: nounwind argmemonly
170declare void @llvm.lifetime.start.p0i8(i64, i8* nocapture) #1
171
172; Function Attrs: nounwind readnone
173declare void @llvm.dbg.declare(metadata, metadata, metadata) #2
174
175; Function Attrs: nounwind
176define i32 @rand() #3 !dbg !59 {
177  ret i32 1
178}
179
180; Function Attrs: nounwind argmemonly
181declare void @llvm.lifetime.end.p0i8(i64, i8* nocapture) #1
182
183; Function Attrs: nounwind uwtable
184define i32 @main() #0 !dbg !13 {
185entry:
186  %retval = alloca i32, align 4
187  store i32 0, i32* %retval, align 4
188  %call = call i64 @_Z3foov(), !dbg !56
189  %cmp = icmp sgt i64 %call, 0, !dbg !57
190  %conv = zext i1 %cmp to i32, !dbg !56
191  ret i32 %conv, !dbg !58
192}
193
194attributes #0 = { nounwind uwtable "disable-tail-calls"="false" "less-precise-fpmad"="false" "frame-pointer"="none" "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" "use-sample-profile" }
195attributes #1 = { nounwind argmemonly }
196attributes #2 = { nounwind readnone }
197attributes #3 = { nounwind alwaysinline "disable-tail-calls"="false" "less-precise-fpmad"="false" "frame-pointer"="none" "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" }
198attributes #4 = { nounwind }
199
200!llvm.dbg.cu = !{!0}
201!llvm.module.flags = !{!16, !17}
202!llvm.ident = !{!18}
203
204!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: NoDebug, enums: !2)
205!1 = !DIFile(filename: "remarks.cc", directory: ".")
206!2 = !{}
207!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, unit: !0, retainedNodes: !8)
208!5 = !DISubroutineType(types: !6)
209!6 = !{!7}
210!7 = !DIBasicType(name: "long long int", size: 64, align: 64, encoding: DW_ATE_signed)
211!8 = !{!9, !10}
212!9 = !DILocalVariable(name: "sum", scope: !4, file: !1, line: 4, type: !7)
213!10 = !DILocalVariable(name: "i", scope: !11, file: !1, line: 5, type: !12)
214!11 = distinct !DILexicalBlock(scope: !4, file: !1, line: 5, column: 3)
215!12 = !DIBasicType(name: "int", size: 32, align: 32, encoding: DW_ATE_signed)
216!13 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 13, type: !14, isLocal: false, isDefinition: true, scopeLine: 13, flags: DIFlagPrototyped, isOptimized: true, unit: !0, retainedNodes: !2)
217!14 = !DISubroutineType(types: !15)
218!15 = !{!12}
219!16 = !{i32 2, !"Dwarf Version", i32 4}
220!17 = !{i32 2, !"Debug Info Version", i32 3}
221!18 = !{!"clang version 3.8.0 (trunk 251041) (llvm/trunk 251053)"}
222!19 = !DILocation(line: 4, column: 3, scope: !4)
223!20 = !DIExpression()
224!21 = !DILocation(line: 4, column: 17, scope: !4)
225!22 = !{!23, !23, i64 0}
226!23 = !{!"long long", !24, i64 0}
227!24 = !{!"omnipotent char", !25, i64 0}
228!25 = !{!"Simple C/C++ TBAA"}
229!26 = !DILocation(line: 5, column: 8, scope: !11)
230!27 = !DILocation(line: 5, column: 12, scope: !11)
231!28 = !{!29, !29, i64 0}
232!29 = !{!"int", !24, i64 0}
233!30 = !DILocation(line: 5, column: 19, scope: !31)
234!31 = !DILexicalBlockFile(scope: !32, file: !1, discriminator: 3)
235!32 = !DILexicalBlockFile(scope: !33, file: !1, discriminator: 1)
236!33 = distinct !DILexicalBlock(scope: !11, file: !1, line: 5, column: 3)
237!34 = !DILocation(line: 5, column: 21, scope: !33)
238!35 = !DILocation(line: 5, column: 3, scope: !11)
239!36 = !DILocation(line: 5, column: 3, scope: !37)
240!37 = !DILexicalBlockFile(scope: !33, file: !1, discriminator: 2)
241!38 = !DILocation(line: 6, column: 9, scope: !39)
242!39 = distinct !DILexicalBlock(scope: !33, file: !1, line: 6, column: 9)
243!40 = !DILocation(line: 6, column: 11, scope: !39)
244!41 = !DILocation(line: 6, column: 9, scope: !33)
245!42 = !DILocation(line: 7, column: 14, scope: !39)
246!43 = !DILocation(line: 7, column: 11, scope: !39)
247!44 = !DILocation(line: 7, column: 7, scope: !39)
248!45 = !DILocation(line: 9, column: 15, scope: !39)
249!46 = !DILocation(line: 9, column: 14, scope: !39)
250!47 = !DILocation(line: 9, column: 19, scope: !39)
251!48 = !DILocation(line: 9, column: 17, scope: !39)
252!49 = !DILocation(line: 9, column: 11, scope: !39)
253!50 = !DILocation(line: 6, column: 13, scope: !39)
254!51 = !DILocation(line: 5, column: 35, scope: !33)
255!52 = !DILocation(line: 5, column: 3, scope: !33)
256!53 = !DILocation(line: 10, column: 10, scope: !4)
257!54 = !DILocation(line: 11, column: 1, scope: !4)
258!55 = !DILocation(line: 10, column: 3, scope: !4)
259!56 = !DILocation(line: 13, column: 21, scope: !13)
260!57 = !DILocation(line: 13, column: 27, scope: !13)
261!58 = !DILocation(line: 13, column: 14, scope: !13)
262!59 = distinct !DISubprogram(name: "rand", linkageName: "rand", scope: !1, file: !1, line: 90, type: !5, isLocal: false, isDefinition: true, scopeLine: 90, flags: DIFlagPrototyped, isOptimized: true, unit: !0)
263