[CodeGen] Fix the branch probability assertion in r318202

Due to integer precision, we might have numerator greater than denominator in
the branch probability scaling. Add a check to prevent this from happening.

llvm-svn: 318353
This commit is contained in:
Rong Xu 2017-11-16 00:14:05 +00:00
parent 725584e26d
commit e4572c6b73
1 changed files with 4 additions and 2 deletions

View File

@ -9847,8 +9847,10 @@ static BranchProbability scaleCaseProbality(BranchProbability CaseProb,
if (PeeledCaseProb == BranchProbability::getOne())
return BranchProbability::getZero();
BranchProbability SwitchProb = PeeledCaseProb.getCompl();
return BranchProbability(CaseProb.getNumerator(),
SwitchProb.scale(CaseProb.getDenominator()));
uint32_t Numerator = CaseProb.getNumerator();
uint32_t Denominator = SwitchProb.scale(CaseProb.getDenominator());
return BranchProbability(Numerator, std::max(Numerator, Denominator));
}
// Try to peel the top probability case if it exceeds the threshold.