[llvm] r256303 - [BPI] Fix two potential divide-by-zero operations that are introduced in r256263.
Cong Hou via llvm-commits
llvm-commits at lists.llvm.org
Tue Dec 22 15:45:55 PST 2015
Author: conghou
Date: Tue Dec 22 17:45:55 2015
New Revision: 256303
URL: http://llvm.org/viewvc/llvm-project?rev=256303&view=rev
Log:
[BPI] Fix two potential divide-by-zero operations that are introduced in r256263.
Modified:
llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp
llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp
Modified: llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp?rev=256303&r1=256302&r2=256303&view=diff
==============================================================================
--- llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp (original)
+++ llvm/trunk/lib/Analysis/BranchProbabilityInfo.cpp Tue Dec 22 17:45:55 2015
@@ -221,8 +221,14 @@ bool BranchProbabilityInfo::calcMetadata
Weights[i] /= ScalingFactor;
WeightSum += Weights[i];
}
- for (unsigned i = 0, e = TI->getNumSuccessors(); i != e; ++i)
- setEdgeProbability(BB, i, {Weights[i], static_cast<uint32_t>(WeightSum)});
+
+ if (WeightSum == 0) {
+ for (unsigned i = 0, e = TI->getNumSuccessors(); i != e; ++i)
+ setEdgeProbability(BB, i, {1, e});
+ } else {
+ for (unsigned i = 0, e = TI->getNumSuccessors(); i != e; ++i)
+ setEdgeProbability(BB, i, {Weights[i], static_cast<uint32_t>(WeightSum)});
+ }
assert(WeightSum <= UINT32_MAX &&
"Expected weights to scale down to 32 bits");
Modified: llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp?rev=256303&r1=256302&r2=256303&view=diff
==============================================================================
--- llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp (original)
+++ llvm/trunk/lib/Transforms/Scalar/JumpThreading.cpp Tue Dec 22 17:45:55 2015
@@ -1647,14 +1647,19 @@ void JumpThreading::UpdateBlockFreqAndEd
uint64_t MaxBBSuccFreq =
*std::max_element(BBSuccFreq.begin(), BBSuccFreq.end());
- SmallVector<BranchProbability, 4> BBSuccProbs;
- for (uint64_t Freq : BBSuccFreq)
- BBSuccProbs.push_back(
- BranchProbability::getBranchProbability(Freq, MaxBBSuccFreq));
- // Normalize edge probabilities so that they sum up to one.
- BranchProbability::normalizeProbabilities(BBSuccProbs.begin(),
- BBSuccProbs.end());
+ SmallVector<BranchProbability, 4> BBSuccProbs;
+ if (MaxBBSuccFreq == 0)
+ BBSuccProbs.assign(BBSuccFreq.size(),
+ {1, static_cast<unsigned>(BBSuccFreq.size())});
+ else {
+ for (uint64_t Freq : BBSuccFreq)
+ BBSuccProbs.push_back(
+ BranchProbability::getBranchProbability(Freq, MaxBBSuccFreq));
+ // Normalize edge probabilities so that they sum up to one.
+ BranchProbability::normalizeProbabilities(BBSuccProbs.begin(),
+ BBSuccProbs.end());
+ }
// Update edge probabilities in BPI.
for (int I = 0, E = BBSuccProbs.size(); I < E; I++)
More information about the llvm-commits
mailing list