diff options
author | Evgeny Stupachenko <evstupac@gmail.com> | 2017-06-05 22:44:18 +0000 |
---|---|---|
committer | Evgeny Stupachenko <evstupac@gmail.com> | 2017-06-05 22:44:18 +0000 |
commit | 4d94e994467405321f67339fbb3154e8bbc0b4a0 (patch) | |
tree | d0c78dac8dd38cf0b287c5a7f10a048025b8daf0 /llvm/lib | |
parent | 3092d728cd80b2cd234a694120dc05edcb305d4d (diff) | |
download | bcm5719-llvm-4d94e994467405321f67339fbb3154e8bbc0b4a0.tar.gz bcm5719-llvm-4d94e994467405321f67339fbb3154e8bbc0b4a0.zip |
LSR: Calculate instruction cost only if InsnsCost is set to true (NFC)
Summary:
The patch guard all instruction cost calculations with InsnCosts (-lsr-insns-cost) option.
Currently even if the option set to false we calculate and print (in debug mode) instruction costs.
Reviewers: qcolombet
Differential Revision: http://reviews.llvm.org/D33914
From: Evgeny Stupachenko <evstupac@gmail.com>
llvm-svn: 304746
Diffstat (limited to 'llvm/lib')
-rw-r--r-- | llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp | 35 |
1 files changed, 21 insertions, 14 deletions
diff --git a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp index 28d94497a3e..11c37adc0eb 100644 --- a/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp +++ b/llvm/lib/Transforms/Scalar/LoopStrengthReduce.cpp @@ -1251,18 +1251,6 @@ void Cost::RateFormula(const TargetTransformInfo &TTI, return; } - // Treat every new register that exceeds TTI.getNumberOfRegisters() - 1 as - // additional instruction (at least fill). - unsigned TTIRegNum = TTI.getNumberOfRegisters(false) - 1; - if (NumRegs > TTIRegNum) { - // Cost already exceeded TTIRegNum, then only newly added register can add - // new instructions. - if (PrevNumRegs > TTIRegNum) - Insns += (NumRegs - PrevNumRegs); - else - Insns += (NumRegs - TTIRegNum); - } - // Determine how many (unfolded) adds we'll need inside the loop. size_t NumBaseParts = F.getNumRegs(); if (NumBaseParts > 1) @@ -1292,6 +1280,24 @@ void Cost::RateFormula(const TargetTransformInfo &TTI, NumBaseAdds++; } + // If we don't count instruction cost exit here. + if (!InsnsCost) { + assert(isValid() && "invalid cost"); + return; + } + + // Treat every new register that exceeds TTI.getNumberOfRegisters() - 1 as + // additional instruction (at least fill). + unsigned TTIRegNum = TTI.getNumberOfRegisters(false) - 1; + if (NumRegs > TTIRegNum) { + // Cost already exceeded TTIRegNum, then only newly added register can add + // new instructions. + if (PrevNumRegs > TTIRegNum) + Insns += (NumRegs - PrevNumRegs); + else + Insns += (NumRegs - TTIRegNum); + } + // If ICmpZero formula ends with not 0, it could not be replaced by // just add or sub. We'll need to compare final result of AddRec. // That means we'll need an additional instruction. @@ -1326,7 +1332,7 @@ void Cost::Lose() { /// Choose the lower cost. bool Cost::operator<(const Cost &Other) const { - if (InsnsCost && Insns != Other.Insns) + if (InsnsCost.getNumOccurrences() > 0 && InsnsCost && Insns != Other.Insns) return Insns < Other.Insns; return std::tie(NumRegs, AddRecCost, NumIVMuls, NumBaseAdds, ScaleCost, ImmCost, SetupCost) < @@ -1336,7 +1342,8 @@ bool Cost::operator<(const Cost &Other) const { } void Cost::print(raw_ostream &OS) const { - OS << Insns << " instruction" << (Insns == 1 ? " " : "s "); + if (InsnsCost) + OS << Insns << " instruction" << (Insns == 1 ? " " : "s "); OS << NumRegs << " reg" << (NumRegs == 1 ? "" : "s"); if (AddRecCost != 0) OS << ", with addrec cost " << AddRecCost; |