forked from OSchip/llvm-project
[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 llvm-svn: 328653
This commit is contained in:
parent
0a0c871f60
commit
662f38b16f
|
@ -224,8 +224,8 @@ static cl::opt<bool>
|
|||
EmitBranchProbability("pgo-emit-branch-prob", cl::init(false), cl::Hidden,
|
||||
cl::desc("When this option is on, the annotated "
|
||||
"branch probability will be emitted as "
|
||||
" optimization remarks: -Rpass-analysis="
|
||||
"pgo-instr-use"));
|
||||
"optimization remarks: -{Rpass|"
|
||||
"pass-remarks}=pgo-instrumentation"));
|
||||
|
||||
// Command line option to turn on CFG dot dump after profile annotation.
|
||||
// Defined in Analysis/BlockFrequencyInfo.cpp: -pgo-view-counts
|
||||
|
@ -1595,13 +1595,15 @@ void llvm::setProfMetadata(Module *M, Instruction *TI,
|
|||
if (BrCondStr.empty())
|
||||
return;
|
||||
|
||||
unsigned WSum =
|
||||
std::accumulate(Weights.begin(), Weights.end(), 0,
|
||||
[](unsigned w1, unsigned w2) { return w1 + w2; });
|
||||
uint64_t WSum =
|
||||
std::accumulate(Weights.begin(), Weights.end(), (uint64_t)0,
|
||||
[](uint64_t w1, uint64_t w2) { return w1 + w2; });
|
||||
uint64_t TotalCount =
|
||||
std::accumulate(EdgeCounts.begin(), EdgeCounts.end(), 0,
|
||||
std::accumulate(EdgeCounts.begin(), EdgeCounts.end(), (uint64_t)0,
|
||||
[](uint64_t c1, uint64_t c2) { return c1 + c2; });
|
||||
BranchProbability BP(Weights[0], WSum);
|
||||
Scale = calculateCountScale(WSum);
|
||||
BranchProbability BP(scaleBranchCount(Weights[0], Scale),
|
||||
scaleBranchCount(WSum, Scale));
|
||||
std::string BranchProbStr;
|
||||
raw_string_ostream OS(BranchProbStr);
|
||||
OS << BP;
|
||||
|
|
|
@ -0,0 +1,8 @@
|
|||
# :ir is the flag to indicate this is IR level profile.
|
||||
:ir
|
||||
test
|
||||
25571299074
|
||||
2
|
||||
40000000000
|
||||
20000000000
|
||||
|
|
@ -0,0 +1,22 @@
|
|||
; RUN: llvm-profdata merge %S/Inputs/large_count_remarks.proftext -o %t.profdata
|
||||
; 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
|
||||
; 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
|
||||
|
||||
target datalayout = "e-m:e-i64:64-f80:128-n8:16:32:64-S128"
|
||||
target triple = "x86_64-unknown-linux-gnu"
|
||||
|
||||
define i32 @test(i32 %i) {
|
||||
entry:
|
||||
%cmp = icmp sgt i32 %i, 0
|
||||
br i1 %cmp, label %if.then, label %if.end
|
||||
|
||||
if.then:
|
||||
%add = add nsw i32 %i, 2
|
||||
br label %if.end
|
||||
|
||||
if.end:
|
||||
%retv = phi i32 [ %add, %if.then ], [ %i, %entry ]
|
||||
ret i32 %retv
|
||||
}
|
||||
|
||||
; ANALYSIS:remark: <unknown>:0:0: sgt_i32_Zero {{.*}}50.00% (total count : 40000000000)
|
Loading…
Reference in New Issue