mirror of
https://github.com/RPCS3/llvm-mirror.git
synced 2024-11-26 12:50:30 +00:00
[BPI] Fix two potential divide-by-zero operations that are introduced in r256263.
llvm-svn: 256303
This commit is contained in:
parent
69b537cdd4
commit
d72d3cbece
@ -221,8 +221,14 @@ bool BranchProbabilityInfo::calcMetadataWeights(BasicBlock *BB) {
|
||||
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");
|
||||
|
@ -1647,14 +1647,19 @@ void JumpThreading::UpdateBlockFreqAndEdgeWeight(BasicBlock *PredBB,
|
||||
|
||||
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++)
|
||||
|
Loading…
Reference in New Issue
Block a user