[PATCH] D44809: [PGO] Fix branch probability remarks assert
Rong Xu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Mar 22 15:16:31 PDT 2018
xur created this revision.
xur added a reviewer: davidxl.
Fix assertion caused by counter/weight overflow.
Fix the help string for pgo-emit-branch-prob option.
https://reviews.llvm.org/D44809
Files:
lib/Transforms/Instrumentation/PGOInstrumentation.cpp
test/Transforms/PGOProfile/Inputs/large_count_remarks.proftext
test/Transforms/PGOProfile/large_count_remarks.ll
Index: test/Transforms/PGOProfile/large_count_remarks.ll
===================================================================
--- /dev/null
+++ test/Transforms/PGOProfile/large_count_remarks.ll
@@ -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)
Index: test/Transforms/PGOProfile/Inputs/large_count_remarks.proftext
===================================================================
--- /dev/null
+++ test/Transforms/PGOProfile/Inputs/large_count_remarks.proftext
@@ -0,0 +1,8 @@
+# :ir is the flag to indicate this is IR level profile.
+:ir
+test
+25571299074
+2
+40000000000
+20000000000
+
Index: lib/Transforms/Instrumentation/PGOInstrumentation.cpp
===================================================================
--- lib/Transforms/Instrumentation/PGOInstrumentation.cpp
+++ lib/Transforms/Instrumentation/PGOInstrumentation.cpp
@@ -224,8 +224,8 @@
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 @@
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;
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D44809.139520.patch
Type: text/x-patch
Size: 3291 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20180322/0db92bfc/attachment.bin>
More information about the llvm-commits
mailing list