llvm.org GIT mirror llvm / 25956d8
[PGO] Fix branch probability remarks assert Fixed counter/weight overflow that leads to an assertion. Also fixed the help string for pgo-emit-branch-prob option. Differential Revision: https://reviews.llvm.org/D44809 git-svn-id: https://llvm.org/svn/llvm-project/llvm/trunk@328653 91177308-0d34-0410-b5e6-96231b3b80d8 Rong Xu 1 year, 5 months ago
3 changed file(s) with 39 addition(s) and 7 deletion(s). Raw diff Collapse all Expand all
223223 EmitBranchProbability("pgo-emit-branch-prob", cl::init(false), cl::Hidden,
224224 cl::desc("When this option is on, the annotated "
225225 "branch probability will be emitted as "
226 " optimization remarks: -Rpass-analysis="
227 "pgo-instr-use"));
226 "optimization remarks: -{Rpass|"
227 "pass-remarks}=pgo-instrumentation"));
228228
229229 // Command line option to turn on CFG dot dump after profile annotation.
230230 // Defined in Analysis/BlockFrequencyInfo.cpp: -pgo-view-counts
15941594 if (BrCondStr.empty())
15951595 return;
15961596
1597 unsigned WSum =
1598 std::accumulate(Weights.begin(), Weights.end(), 0,
1599 [](unsigned w1, unsigned w2) { return w1 + w2; });
1597 uint64_t WSum =
1598 std::accumulate(Weights.begin(), Weights.end(), (uint64_t)0,
1599 [](uint64_t w1, uint64_t w2) { return w1 + w2; });
16001600 uint64_t TotalCount =
1601 std::accumulate(EdgeCounts.begin(), EdgeCounts.end(), 0,
1601 std::accumulate(EdgeCounts.begin(), EdgeCounts.end(), (uint64_t)0,
16021602 [](uint64_t c1, uint64_t c2) { return c1 + c2; });
1603 BranchProbability BP(Weights[0], WSum);
1603 Scale = calculateCountScale(WSum);
1604 BranchProbability BP(scaleBranchCount(Weights[0], Scale),
1605 scaleBranchCount(WSum, Scale));
16041606 std::string BranchProbStr;
16051607 raw_string_ostream OS(BranchProbStr);
16061608 OS << BP;
0 # :ir is the flag to indicate this is IR level profile.
1 :ir
2 test
3 25571299074
4 2
5 40000000000
6 20000000000
7
0 ; RUN: llvm-profdata merge %S/Inputs/large_count_remarks.proftext -o %t.profdata
1 ; RUN: opt < %s -pgo-instr-use -pgo-test-profile-file=%t.profdata -pass-remarks=pgo-instrumentation -pgo-emit-branch-prob -S 2>&1| FileCheck %s --check-prefix=ANALYSIS
2 ; RUN: opt < %s -passes=pgo-instr-use -pgo-test-profile-file=%t.profdata -pass-remarks=pgo-instrumentation -pgo-emit-branch-prob -S 2>&1| FileCheck %s --check-prefix=ANALYSIS
3
4 target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
5 target triple = "x86_64-unknown-linux-gnu"
6
7 define i32 @test(i32 %i) {
8 entry:
9 %cmp = icmp sgt i32 %i, 0
10 br i1 %cmp, label %if.then, label %if.end
11
12 if.then:
13 %add = add nsw i32 %i, 2
14 br label %if.end
15
16 if.end:
17 %retv = phi i32 [ %add, %if.then ], [ %i, %entry ]
18 ret i32 %retv
19 }
20
21 ; ANALYSIS:remark: :0:0: sgt_i32_Zero {{.*}}50.00% (total count : 40000000000)