aboutsummaryrefslogtreecommitdiff
path: root/llvm/lib/Analysis/BranchProbabilityInfo.cpp
diff options
context:
space:
mode:
authorCong Hou <congh@google.com>2015-10-26 18:00:17 +0000
committerCong Hou <congh@google.com>2015-10-26 18:00:17 +0000
commitfff8ccf5792b8cec4483c88e87d8d98c72b76633 (patch)
treedd000df23b931fe4e7ad91a1cca6b052e43e88b4 /llvm/lib/Analysis/BranchProbabilityInfo.cpp
parent57f8837adad4859e3ea12fdebe792819b9cf3848 (diff)
downloadllvm-fff8ccf5792b8cec4483c88e87d8d98c72b76633.zip
llvm-fff8ccf5792b8cec4483c88e87d8d98c72b76633.tar.gz
llvm-fff8ccf5792b8cec4483c88e87d8d98c72b76633.tar.bz2
Check the case that the numerator and denominator are both zeros when getting edge probabilities in BPI and return 100% in this case.
This issue is triggered in PGO mode when bootstrapping LLVM. It seems that it is not guaranteed that edge weights are always greater than zero which are read from profile data. llvm-svn: 251317
Diffstat (limited to 'llvm/lib/Analysis/BranchProbabilityInfo.cpp')
-rw-r--r--llvm/lib/Analysis/BranchProbabilityInfo.cpp10
1 files changed, 10 insertions, 0 deletions
diff --git a/llvm/lib/Analysis/BranchProbabilityInfo.cpp b/llvm/lib/Analysis/BranchProbabilityInfo.cpp
index 9ab357b..f483946 100644
--- a/llvm/lib/Analysis/BranchProbabilityInfo.cpp
+++ b/llvm/lib/Analysis/BranchProbabilityInfo.cpp
@@ -623,6 +623,11 @@ getEdgeProbability(const BasicBlock *Src, unsigned IndexInSuccessors) const {
uint32_t N = getEdgeWeight(Src, IndexInSuccessors);
uint32_t D = getSumForBlock(Src);
+ // It is possible that the edge weight on the only successor edge of Src is
+ // zero, in which case we return 100%.
+ if (N == 0 && D == 0)
+ return BranchProbability::getOne();
+
return BranchProbability(N, D);
}
@@ -634,6 +639,11 @@ getEdgeProbability(const BasicBlock *Src, const BasicBlock *Dst) const {
uint32_t N = getEdgeWeight(Src, Dst);
uint32_t D = getSumForBlock(Src);
+ // It is possible that the edge weight on the only successor edge of Src is
+ // zero, in which case we return 100%.
+ if (N == 0 && D == 0)
+ return BranchProbability::getOne();
+
return BranchProbability(N, D);
}