[llvm] r318353 - [CodeGen] Fix the branch probability assertion in r318202
Rong Xu via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 15 16:14:05 PST 2017
Author: xur
Date: Wed Nov 15 16:14:05 2017
New Revision: 318353
URL: http://llvm.org/viewvc/llvm-project?rev=318353&view=rev
Log:
[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.
Modified:
llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
Modified: llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp
URL: http://llvm.org/viewvc/llvm-project/llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp?rev=318353&r1=318352&r2=318353&view=diff
==============================================================================
--- llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp (original)
+++ llvm/trunk/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp Wed Nov 15 16:14:05 2017
@@ -9847,8 +9847,10 @@ static BranchProbability scaleCaseProbal
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.
More information about the llvm-commits
mailing list