Skip to content

Commit e4572c6

Browse files
committed
[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
1 parent 725584e commit e4572c6

File tree

1 file changed

+4
-2
lines changed

1 file changed

+4
-2
lines changed

llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9847,8 +9847,10 @@ static BranchProbability scaleCaseProbality(BranchProbability CaseProb,
98479847
if (PeeledCaseProb == BranchProbability::getOne())
98489848
return BranchProbability::getZero();
98499849
BranchProbability SwitchProb = PeeledCaseProb.getCompl();
9850-
return BranchProbability(CaseProb.getNumerator(),
9851-
SwitchProb.scale(CaseProb.getDenominator()));
9850+
9851+
uint32_t Numerator = CaseProb.getNumerator();
9852+
uint32_t Denominator = SwitchProb.scale(CaseProb.getDenominator());
9853+
return BranchProbability(Numerator, std::max(Numerator, Denominator));
98529854
}
98539855

98549856
// Try to peel the top probability case if it exceeds the threshold.

0 commit comments

Comments
 (0)