diff options
author | Vitaly Buka <vitalybuka@google.com> | 2022-08-01 19:53:09 -0700 |
---|---|---|
committer | Vitaly Buka <vitalybuka@google.com> | 2022-08-03 14:54:37 -0700 |
commit | 26dd42705c2af0b8f6e5d6cdb32c9bd5ed9524eb (patch) | |
tree | fd4e3fbde76c0546b9bb75c03dbbae8477ba98be /llvm/lib/Analysis/InlineCost.cpp | |
parent | 84e91948289cd606a0cd8a3372398b363d4b5460 (diff) | |
download | llvm-26dd42705c2af0b8f6e5d6cdb32c9bd5ed9524eb.zip llvm-26dd42705c2af0b8f6e5d6cdb32c9bd5ed9524eb.tar.gz llvm-26dd42705c2af0b8f6e5d6cdb32c9bd5ed9524eb.tar.bz2 |
[NFC][Inliner] Simplify clamping in addCost
Diffstat (limited to 'llvm/lib/Analysis/InlineCost.cpp')
-rw-r--r-- | llvm/lib/Analysis/InlineCost.cpp | 12 |
1 files changed, 6 insertions, 6 deletions
diff --git a/llvm/lib/Analysis/InlineCost.cpp b/llvm/lib/Analysis/InlineCost.cpp index d0a33dd..ee0cb7f 100644 --- a/llvm/lib/Analysis/InlineCost.cpp +++ b/llvm/lib/Analysis/InlineCost.cpp @@ -42,6 +42,7 @@ #include "llvm/Support/Debug.h" #include "llvm/Support/FormattedStream.h" #include "llvm/Support/raw_ostream.h" +#include <climits> #include <limits> using namespace llvm; @@ -502,7 +503,6 @@ int64_t getExpectedNumberOfCompare(int NumCaseCluster) { /// FIXME: if it is necessary to derive from InlineCostCallAnalyzer, note /// the FIXME in onLoweredCall, when instantiating an InlineCostCallAnalyzer class InlineCostCallAnalyzer final : public CallAnalyzer { - const int CostUpperBound = INT_MAX - InlineConstants::InstrCost - 1; const bool ComputeFullInlineCost; int LoadEliminationCost = 0; /// Bonus to be applied when percentage of vector instructions in callee is @@ -579,9 +579,9 @@ class InlineCostCallAnalyzer final : public CallAnalyzer { BlockFrequencyInfo *CallerBFI); /// Handle a capped 'int' increment for Cost. - void addCost(int64_t Inc, int64_t UpperBound = INT_MAX) { - assert(UpperBound > 0 && UpperBound <= INT_MAX && "invalid upper bound"); - Cost = std::min<int>(UpperBound, Cost + Inc); + void addCost(int64_t Inc) { + Inc = std::max<int64_t>(std::min<int64_t>(INT_MAX, Inc), INT_MIN); + Cost = std::max<int64_t>(std::min<int64_t>(INT_MAX, Inc + Cost), INT_MIN); } void onDisableSROA(AllocaInst *Arg) override { @@ -662,7 +662,7 @@ class InlineCostCallAnalyzer final : public CallAnalyzer { static_cast<int64_t>(JumpTableSize) * InlineConstants::InstrCost + 4 * InlineConstants::InstrCost; - addCost(JTCost, static_cast<int64_t>(CostUpperBound)); + addCost(JTCost); return; } @@ -677,7 +677,7 @@ class InlineCostCallAnalyzer final : public CallAnalyzer { int64_t SwitchCost = ExpectedNumberOfCompare * 2 * InlineConstants::InstrCost; - addCost(SwitchCost, static_cast<int64_t>(CostUpperBound)); + addCost(SwitchCost); } void onMissedSimplification() override { addCost(InlineConstants::InstrCost); |