From e4572c6b733243962103b8d18ea2c3872cbef91a Mon Sep 17 00:00:00 2001 From: Rong Xu Date: Thu, 16 Nov 2017 00:14:05 +0000 Subject: [PATCH] [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 --- llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp index 880edbf..c4acf28 100644 --- a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp +++ b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp @@ -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. -- 2.7.4