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");
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++)