1 ; RUN: opt < %s -passes=sample-profile -sample-profile-file=%S/Inputs/fsafdo.extbinary.afdo | opt -passes='print<branch-prob>' -disable-output 2>&1 | FileCheck %s
2 ; RUN: opt < %s -passes=sample-profile -profile-isfs -sample-profile-file=%S/Inputs/fsafdo.prof | opt -passes='print<branch-prob>' -disable-output 2>&1 | FileCheck %s
4 target triple = "x86_64-unknown-linux-gnu"
6 @sum = dso_local local_unnamed_addr global i32 0, align 4
8 declare i32 @bar(i32 %i) #0
9 declare void @work(i32 %i) #2
11 define dso_local void @foo() #0 !dbg !29 {
12 ; CHECK: Printing analysis {{.*}} for function 'foo':
15 br label %for.cond1.preheader, !dbg !30
16 ; CHECK: edge %entry -> %for.cond1.preheader probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
19 %j.012 = phi i32 [ 0, %entry ], [ %inc11, %if.end9.3 ]
20 %mul = mul nuw nsw i32 %j.012, 48
21 %call = tail call i32 @bar(i32 %mul), !dbg !32
22 %0 = and i32 %call, 1, !dbg !33
23 %tobool.not = icmp eq i32 %0, 0, !dbg !33
24 br i1 %tobool.not, label %if.end, label %if.then, !dbg !35
25 ; CHECK: edge %for.cond1.preheader -> %if.end probability is 0x3f6262b8 / 0x80000000 = 49.52%
26 ; CHECK: edge %for.cond1.preheader -> %if.then probability is 0x409d9d48 / 0x80000000 = 50.48%
30 %mul4 = shl nsw i32 %call, 1, !dbg !36
31 tail call void @work(i32 %mul4), !dbg !37
32 br label %if.end, !dbg !38
33 ; CHECK: edge %if.then -> %if.end probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
36 %1 = and i32 %call, 3, !dbg !39
37 %tobool6.not = icmp eq i32 %1, 0, !dbg !39
38 br i1 %tobool6.not, label %if.end9, label %if.then7, !dbg !40
39 ; CHECK: edge %if.end -> %if.end9 probability is 0x22c6bac3 / 0x80000000 = 27.17%
40 ; CHECK: edge %if.end -> %if.then7 probability is 0x5d39453d / 0x80000000 = 72.83%
44 %mul8 = mul nsw i32 %call, 3, !dbg !41
45 tail call void @work(i32 %mul8), !dbg !42
46 br label %if.end9, !dbg !43
47 ; CHECK: edge %if.then7 -> %if.end9 probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
50 %add.1 = or i32 %mul, 1, !dbg !44
51 %call.1 = tail call i32 @bar(i32 %add.1), !dbg !32
52 %2 = and i32 %call.1, 1, !dbg !33
53 %tobool.not.1 = icmp eq i32 %2, 0, !dbg !33
54 br i1 %tobool.not.1, label %if.end.1, label %if.then.1, !dbg !35
55 ; CHECK: edge %if.end9 -> %if.end.1 probability is 0x3f6262b8 / 0x80000000 = 49.52%
56 ; CHECK: edge %if.end9 -> %if.then.1 probability is 0x409d9d48 / 0x80000000 = 50.48%
62 %mul4.1 = shl nsw i32 %call.1, 1, !dbg !36
63 tail call void @work(i32 %mul4.1), !dbg !37
64 br label %if.end.1, !dbg !38
65 ; CHECK: edge %if.then.1 -> %if.end.1 probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
68 %3 = and i32 %call.1, 3, !dbg !39
69 %tobool6.not.1 = icmp eq i32 %3, 0, !dbg !39
70 br i1 %tobool6.not.1, label %if.end9.1, label %if.then7.1, !dbg !40
71 ; CHECK: edge %if.end.1 -> %if.end9.1 probability is 0x22c6bac3 / 0x80000000 = 27.17%
72 ; CHECK: edge %if.end.1 -> %if.then7.1 probability is 0x5d39453d / 0x80000000 = 72.83%
75 %mul8.1 = mul nsw i32 %call.1, 3, !dbg !41
76 tail call void @work(i32 %mul8.1), !dbg !42
77 br label %if.end9.1, !dbg !43
78 ; CHECK: edge %if.then7.1 -> %if.end9.1 probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
81 %add.2 = or i32 %mul, 2, !dbg !44
82 %call.2 = tail call i32 @bar(i32 %add.2), !dbg !32
83 %4 = and i32 %call.2, 1, !dbg !33
84 %tobool.not.2 = icmp eq i32 %4, 0, !dbg !33
85 br i1 %tobool.not.2, label %if.end.2, label %if.then.2, !dbg !35
86 ; CHECK: edge %if.end9.1 -> %if.end.2 probability is 0x3f6262b8 / 0x80000000 = 49.52%
87 ; CHECK: edge %if.end9.1 -> %if.then.2 probability is 0x409d9d48 / 0x80000000 = 50.48%
90 %mul4.2 = shl nsw i32 %call.2, 1, !dbg !36
91 tail call void @work(i32 %mul4.2), !dbg !37
92 br label %if.end.2, !dbg !38
93 ; CHECK: edge %if.then.2 -> %if.end.2 probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
96 %5 = and i32 %call.2, 3, !dbg !39
97 %tobool6.not.2 = icmp eq i32 %5, 0, !dbg !39
98 br i1 %tobool6.not.2, label %if.end9.2, label %if.then7.2, !dbg !40
99 ; CHECK: edge %if.end.2 -> %if.end9.2 probability is 0x22c6bac3 / 0x80000000 = 27.17%
100 ; CHECK: edge %if.end.2 -> %if.then7.2 probability is 0x5d39453d / 0x80000000 = 72.83%
103 %mul8.2 = mul nsw i32 %call.2, 3, !dbg !41
104 tail call void @work(i32 %mul8.2), !dbg !42
105 br label %if.end9.2, !dbg !43
106 ; CHECK: edge %if.then7.2 -> %if.end9.2 probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
109 %add.3 = or i32 %mul, 3, !dbg !44
110 %call.3 = tail call i32 @bar(i32 %add.3), !dbg !32
111 %6 = and i32 %call.3, 1, !dbg !33
112 %tobool.not.3 = icmp eq i32 %6, 0, !dbg !33
113 br i1 %tobool.not.3, label %if.end.3, label %if.then.3, !dbg !35
114 ; CHECK: edge %if.end9.2 -> %if.end.3 probability is 0x3f6262b8 / 0x80000000 = 49.52%
115 ; CHECK: edge %if.end9.2 -> %if.then.3 probability is 0x409d9d48 / 0x80000000 = 50.48%
118 %mul4.3 = shl nsw i32 %call.3, 1, !dbg !36
119 tail call void @work(i32 %mul4.3), !dbg !37
120 br label %if.end.3, !dbg !38
121 ; CHECK: edge %if.then.3 -> %if.end.3 probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
124 %7 = and i32 %call.3, 3, !dbg !39
125 %tobool6.not.3 = icmp eq i32 %7, 0, !dbg !39
126 br i1 %tobool6.not.3, label %if.end9.3, label %if.then7.3, !dbg !40
127 ; CHECK: edge %if.end.3 -> %if.end9.3 probability is 0x22c6bac3 / 0x80000000 = 27.17%
128 ; CHECK: edge %if.end.3 -> %if.then7.3 probability is 0x5d39453d / 0x80000000 = 72.83%
131 %mul8.3 = mul nsw i32 %call.3, 3, !dbg !41
132 tail call void @work(i32 %mul8.3), !dbg !42
133 br label %if.end9.3, !dbg !43
134 ; CHECK: edge %if.then7.3 -> %if.end9.3 probability is 0x80000000 / 0x80000000 = 100.00% [HOT edge]
137 %inc11 = add nuw nsw i32 %j.012, 1, !dbg !46
138 %exitcond.not = icmp eq i32 %inc11, 48, !dbg !48
139 br i1 %exitcond.not, label %for.end12, label %for.cond1.preheader, !dbg !30, !llvm.loop !49
140 ; CHECK: edge %if.end9.3 -> %for.end12 probability is 0x00834dd9 / 0x80000000 = 0.40%
141 ; CHECK: edge %if.end9.3 -> %for.cond1.preheader probability is 0x7f7cb227 / 0x80000000 = 99.60% [HOT edge]
144 define dso_local i32 @main() #3 !dbg !52 {
146 br label %for.body, !dbg !53
149 %i.03 = phi i32 [ 0, %entry ], [ %inc, %for.body ]
150 tail call void @foo(), !dbg !55
151 %inc = add nuw nsw i32 %i.03, 1, !dbg !56
152 %exitcond.not = icmp eq i32 %inc, 10000000, !dbg !58
153 br i1 %exitcond.not, label %for.end, label %for.body, !dbg !53, !llvm.loop !60
160 attributes #0 = { noinline nounwind uwtable "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" "unsafe-fp-math"="false" "use-soft-float"="false" "use-sample-profile"}
161 attributes #1 = { argmemonly nounwind willreturn }
162 attributes #2 = { nofree noinline norecurse nounwind uwtable "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" "unsafe-fp-math"="false" "use-soft-float"="false" }
163 attributes #3 = { nounwind uwtable "disable-tail-calls"="false" "frame-pointer"="none" "less-precise-fpmad"="false" "min-legal-vector-width"="0" "no-infs-fp-math"="false" "no-jump-tables"="false" "no-nans-fp-math"="false" "no-signed-zeros-fp-math"="false" "no-trapping-math"="true" "stack-protector-buffer-size"="8" "target-cpu"="x86-64" "target-features"="+cx8,+fxsr,+mmx,+sse,+sse2,+x87" "tune-cpu"="generic" "unsafe-fp-math"="false" "use-soft-float"="false" }
166 !llvm.module.flags = !{!3, !4, !5}
168 !0 = distinct !DICompileUnit(language: DW_LANG_C99, file: !1, isOptimized: true, runtimeVersion: 0, emissionKind: LineTablesOnly, enums: !2, splitDebugInlining: false, debugInfoForProfiling: true, nameTableKind: None)
169 !1 = !DIFile(filename: "unroll.c", directory: "a/")
171 !3 = !{i32 7, !"Dwarf Version", i32 4}
172 !4 = !{i32 2, !"Debug Info Version", i32 3}
173 !5 = !{i32 1, !"wchar_size", i32 4}
174 !7 = distinct !DISubprogram(name: "bar", scope: !1, file: !1, line: 3, type: !8, scopeLine: 3, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
175 !8 = !DISubroutineType(types: !2)
176 !9 = !DILocation(line: 4, column: 3, scope: !7)
177 !10 = !DILocation(line: 5, column: 5, scope: !7)
178 !11 = !{!12, !12, i64 0}
179 !12 = !{!"int", !13, i64 0}
180 !13 = !{!"omnipotent char", !14, i64 0}
181 !14 = !{!"Simple C/C++ TBAA"}
182 !15 = !DILocation(line: 6, column: 10, scope: !7)
183 !16 = !DILocation(line: 7, column: 1, scope: !7)
184 !17 = !DILocation(line: 6, column: 3, scope: !18)
185 !18 = !DILexicalBlockFile(scope: !7, file: !1, discriminator: 1)
186 !19 = distinct !DISubprogram(name: "work", scope: !1, file: !1, line: 10, type: !8, scopeLine: 10, flags: DIFlagPrototyped | DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
187 !20 = !DILocation(line: 11, column: 7, scope: !19)
188 !21 = !DILocation(line: 11, column: 11, scope: !22)
189 !22 = !DILexicalBlockFile(scope: !19, file: !1, discriminator: 1)
190 !23 = !DILocation(line: 11, column: 11, scope: !24)
191 !24 = !DILexicalBlockFile(scope: !19, file: !1, discriminator: 2)
192 !25 = !DILocation(line: 11, column: 7, scope: !26)
193 !26 = !DILexicalBlockFile(scope: !19, file: !1, discriminator: 3)
194 !27 = !DILocation(line: 0, scope: !22)
195 !28 = !DILocation(line: 15, column: 1, scope: !19)
196 !29 = distinct !DISubprogram(name: "foo", scope: !1, file: !1, line: 17, type: !8, scopeLine: 17, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
197 !30 = !DILocation(line: 19, column: 3, scope: !31)
198 !31 = !DILexicalBlockFile(scope: !29, file: !1, discriminator: 2)
199 !32 = !DILocation(line: 21, column: 16, scope: !31)
200 !33 = !DILocation(line: 22, column: 14, scope: !34)
201 !34 = !DILexicalBlockFile(scope: !29, file: !1, discriminator: 1)
202 !35 = !DILocation(line: 22, column: 11, scope: !31)
203 !36 = !DILocation(line: 23, column: 16, scope: !29)
204 !37 = !DILocation(line: 23, column: 9, scope: !34)
205 !38 = !DILocation(line: 23, column: 9, scope: !31)
206 !39 = !DILocation(line: 24, column: 14, scope: !34)
207 !40 = !DILocation(line: 24, column: 11, scope: !31)
208 !41 = !DILocation(line: 25, column: 16, scope: !29)
209 !42 = !DILocation(line: 25, column: 9, scope: !34)
210 !43 = !DILocation(line: 25, column: 9, scope: !31)
211 !44 = !DILocation(line: 21, column: 21, scope: !34)
212 !45 = !DILocation(line: 27, column: 1, scope: !29)
213 !46 = !DILocation(line: 19, column: 24, scope: !47)
214 !47 = !DILexicalBlockFile(scope: !29, file: !1, discriminator: 3)
215 !48 = !DILocation(line: 19, column: 17, scope: !34)
216 !49 = distinct !{!49, !50, !51}
217 !50 = !DILocation(line: 19, column: 3, scope: !29)
218 !51 = !DILocation(line: 26, column: 3, scope: !29)
219 !52 = distinct !DISubprogram(name: "main", scope: !1, file: !1, line: 29, type: !8, scopeLine: 29, flags: DIFlagAllCallsDescribed, spFlags: DISPFlagDefinition | DISPFlagOptimized, unit: !0, retainedNodes: !2)
220 !53 = !DILocation(line: 31, column: 3, scope: !54)
221 !54 = !DILexicalBlockFile(scope: !52, file: !1, discriminator: 2)
222 !55 = !DILocation(line: 32, column: 5, scope: !52)
223 !56 = !DILocation(line: 31, column: 30, scope: !57)
224 !57 = !DILexicalBlockFile(scope: !52, file: !1, discriminator: 3)
225 !58 = !DILocation(line: 31, column: 17, scope: !59)
226 !59 = !DILexicalBlockFile(scope: !52, file: !1, discriminator: 1)
227 !60 = distinct !{!60, !61, !62}
228 !61 = !DILocation(line: 31, column: 3, scope: !52)
229 !62 = !DILocation(line: 33, column: 3, scope: !52)
230 !63 = !DILocation(line: 34, column: 1, scope: !52)