diff options
author | Rong Xu <xur@google.com> | 2017-11-16 00:14:05 +0000 |
---|---|---|
committer | Rong Xu <xur@google.com> | 2017-11-16 00:14:05 +0000 |
commit | e4572c6b733243962103b8d18ea2c3872cbef91a (patch) | |
tree | de0d6dae859c26f7a948197359a3a7d62ae27c45 /llvm/lib | |
parent | 725584e26d79d00ad4b14cab15babc4b4499d22e (diff) | |
download | bcm5719-llvm-e4572c6b733243962103b8d18ea2c3872cbef91a.tar.gz bcm5719-llvm-e4572c6b733243962103b8d18ea2c3872cbef91a.zip |
[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
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp b/llvm/lib/CodeGen/SelectionDAG/SelectionDAGBuilder.cpp index 880edbfdf8b..c4acf285a65 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. |