aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/BranchProbabilityInfo.cpp
diff options
context:
space:
mode:
authorEvgeniy Brevnov <evgueni.brevnov@gmail.com>2020-04-29 14:08:01 +0700
committerEvgeniy Brevnov <evgueni.brevnov@gmail.com>2020-04-30 11:41:03 +0700
commitbb0842a3f11e5d5a13d3212b627d9f1521bff553 (patch)
treee8e231555219bffa8f34daf678fa1c8c12bb6efe /llvm/lib/Analysis/BranchProbabilityInfo.cpp
parent3e68a667047d1541e445c8f47501d69f5b1a497d (diff)
downloadllvm-bb0842a3f11e5d5a13d3212b627d9f1521bff553.zip
llvm-bb0842a3f11e5d5a13d3212b627d9f1521bff553.tar.gz
llvm-bb0842a3f11e5d5a13d3212b627d9f1521bff553.tar.bz2
[BPI] Incorrect probability reported in case of mulptiple edges.
Summary: By design 'BranchProbabilityInfo:: getEdgeProbability(const BasicBlock *Src, const BasicBlock *Dst) const' should return sum of probabilities over all edges from Src to Dst. Current implementation is buggy and returns 1/num_of_successors if probabilities are not explicitly set. Note current implementation of BPI printing has an issue as well and annotates each edge with sum of probabilities over all ages from one basic block to another. That's why 30% probability reported (instead of 10%) in the lit test. This is not urgent issue since only printing is affected. Note also current implementation assumes that either all or none edges have probabilities set. This is not the only place which uses such assumption. At least we should assert that in verifier. In addition we can think on a more robust API of BPI which would prevent situations. Reviewers: skatkov, yrouban, taewookoh Reviewed By: skatkov Subscribers: hiraditya, llvm-commits Tags: #llvm Differential Revision: https://reviews.llvm.org/D79071
Diffstat (limited to 'llvm/lib/Analysis/BranchProbabilityInfo.cpp')
-rw-r--r--llvm/lib/Analysis/BranchProbabilityInfo.cpp4
1 files changed, 3 insertions, 1 deletions
diff --git a/llvm/lib/Analysis/BranchProbabilityInfo.cpp b/llvm/lib/Analysis/BranchProbabilityInfo.cpp
index 99f253c..d33af83 100644
--- a/llvm/lib/Analysis/BranchProbabilityInfo.cpp
+++ b/llvm/lib/Analysis/BranchProbabilityInfo.cpp
@@ -936,8 +936,10 @@ BranchProbabilityInfo::getEdgeProbability(const BasicBlock *Src,
const BasicBlock *Dst) const {
auto Prob = BranchProbability::getZero();
bool FoundProb = false;
+ uint32_t EdgeCount = 0;
for (const_succ_iterator I = succ_begin(Src), E = succ_end(Src); I != E; ++I)
if (*I == Dst) {
+ ++EdgeCount;
auto MapI = Probs.find(std::make_pair(Src, I.getSuccessorIndex()));
if (MapI != Probs.end()) {
FoundProb = true;
@@ -945,7 +947,7 @@ BranchProbabilityInfo::getEdgeProbability(const BasicBlock *Src,
}
}
uint32_t succ_num = std::distance(succ_begin(Src), succ_end(Src));
- return FoundProb ? Prob : BranchProbability(1, succ_num);
+ return FoundProb ? Prob : BranchProbability(EdgeCount, succ_num);
}
/// Set the edge probability for a given edge specified by PredBlock and an