[llvm] r328653 - [PGO] Fix branch probability remarks assert
Rong Xu via llvm-commits
llvm-commits at lists.llvm.org
Tue Mar 27 11:55:56 PDT 2018
Author: xur
Date: Tue Mar 27 11:55:56 2018
New Revision: 328653
URL: http://llvm.org/viewvc/llvm-project?rev=328653&view=rev
Log:
[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
Added:
llvm/trunk/test/Transforms/PGOProfile/Inputs/large_count_remarks.proftext
llvm/trunk/test/Transforms/PGOProfile/large_count_remarks.ll
Modified:
llvm/trunk/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
Modified: llvm/trunk/lib/Transforms/Instrumentation/PGOInstrumentation.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Instrumentation/PGOInstrumentation.cpp?rev=328653&r1=328652&r2=328653&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Instrumentation/PGOInstrumentation.cpp (original)
+++ llvm/trunk/lib/Transforms/Instrumentation/PGOInstrumentation.cpp Tue Mar 27 11:55:56 2018
@@ -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, In
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;
Added: llvm/trunk/test/Transforms/PGOProfile/Inputs/large_count_remarks.proftext
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/PGOProfile/Inputs/large_count_remarks.proftext?rev=328653&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/PGOProfile/Inputs/large_count_remarks.proftext (added)
+++ llvm/trunk/test/Transforms/PGOProfile/Inputs/large_count_remarks.proftext Tue Mar 27 11:55:56 2018
@@ -0,0 +1,8 @@
+# :ir is the flag to indicate this is IR level profile.
+:ir
+test
+25571299074
+2
+40000000000
+20000000000
+
Added: llvm/trunk/test/Transforms/PGOProfile/large_count_remarks.ll
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/test/Transforms/PGOProfile/large_count_remarks.ll?rev=328653&view=auto
==============================================================================
--- llvm/trunk/test/Transforms/PGOProfile/large_count_remarks.ll (added)
+++ llvm/trunk/test/Transforms/PGOProfile/large_count_remarks.ll Tue Mar 27 11:55:56 2018
@@ -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)
More information about the llvm-commits
mailing list