diff options
author | Cong Hou <congh@google.com> | 2015-08-26 23:17:52 +0000 |
---|---|---|
committer | Cong Hou <congh@google.com> | 2015-08-26 23:17:52 +0000 |
commit | b5ef475e5c5256c93f3d869dac672a8ddeaba383 (patch) | |
tree | 24b65cc06880b7f78290fe868d0823b9304eb375 /llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp | |
parent | 28690925ed8318d7024d417e45902a23841d03df (diff) | |
download | bcm5719-llvm-b5ef475e5c5256c93f3d869dac672a8ddeaba383.tar.gz bcm5719-llvm-b5ef475e5c5256c93f3d869dac672a8ddeaba383.zip |
[ARM] Use BranchProbability::scale() to scale an integer with a probability in ARMBaseInstrInfo.cpp,
Previously in isProfitableToIfCvt() in ARMBaseInstrInfo.cpp, the multiplication between an integer and a branch probability is done manually in an unsafe way that may lead to overflow. This patch corrects those cases by using BranchProbability's member function scale() to avoid overflow (which stores the intermediate result in int64).
Differential Revision: http://reviews.llvm.org/D12295
llvm-svn: 246106
Diffstat (limited to 'llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp')
-rw-r--r-- | llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp | 12 |
1 files changed, 3 insertions, 9 deletions
diff --git a/llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp b/llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp index 2f97b2ef4d2..47a6338f4c3 100644 --- a/llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp +++ b/llvm/lib/Target/ARM/ARMBaseInstrInfo.cpp @@ -1670,8 +1670,7 @@ isProfitableToIfCvt(MachineBasicBlock &MBB, } // Attempt to estimate the relative costs of predication versus branching. - unsigned UnpredCost = Probability.getNumerator() * NumCycles; - UnpredCost /= Probability.getDenominator(); + unsigned UnpredCost = Probability.scale(NumCycles); UnpredCost += 1; // The branch itself UnpredCost += Subtarget.getMispredictionPenalty() / 10; @@ -1688,13 +1687,8 @@ isProfitableToIfCvt(MachineBasicBlock &TMBB, return false; // Attempt to estimate the relative costs of predication versus branching. - unsigned TUnpredCost = Probability.getNumerator() * TCycles; - TUnpredCost /= Probability.getDenominator(); - - uint32_t Comp = Probability.getDenominator() - Probability.getNumerator(); - unsigned FUnpredCost = Comp * FCycles; - FUnpredCost /= Probability.getDenominator(); - + unsigned TUnpredCost = Probability.scale(TCycles); + unsigned FUnpredCost = Probability.getCompl().scale(FCycles); unsigned UnpredCost = TUnpredCost + FUnpredCost; UnpredCost += 1; // The branch itself UnpredCost += Subtarget.getMispredictionPenalty() / 10; |