diff --git a/llvm/lib/Analysis/InlineCost.cpp b/llvm/lib/Analysis/InlineCost.cpp --- a/llvm/lib/Analysis/InlineCost.cpp +++ b/llvm/lib/Analysis/InlineCost.cpp @@ -461,7 +461,8 @@ /// 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 int CostUpperBound = + std::numeric_limits::max() - InlineConstants::InstrCost - 1; const bool ComputeFullInlineCost; int LoadEliminationCost = 0; /// Bonus to be applied when percentage of vector instructions in callee is @@ -532,9 +533,11 @@ 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 = (int)std::min(UpperBound, Cost + Inc); + void addCost(int64_t Inc, + int64_t UpperBound = std::numeric_limits::max()) { + assert(UpperBound > 0 && UpperBound <= std::numeric_limits::max() && + "invalid upper bound"); + Cost = std::min(UpperBound, Cost + Inc); } void onDisableSROA(AllocaInst *Arg) override { @@ -595,10 +598,11 @@ // branch to destination. // Maximum valid cost increased in this function. if (JumpTableSize) { - int64_t JTCost = (int64_t)JumpTableSize * InlineConstants::InstrCost + - 4 * InlineConstants::InstrCost; + int64_t JTCost = + static_cast(JumpTableSize) * InlineConstants::InstrCost + + 4 * InlineConstants::InstrCost; - addCost(JTCost, (int64_t)CostUpperBound); + addCost(JTCost, static_cast(CostUpperBound)); return; } @@ -613,7 +617,7 @@ int64_t SwitchCost = ExpectedNumberOfCompare * 2 * InlineConstants::InstrCost; - addCost(SwitchCost, (int64_t)CostUpperBound); + addCost(SwitchCost, static_cast(CostUpperBound)); } void onMissedSimplification() override { addCost(InlineConstants::InstrCost); @@ -938,9 +942,9 @@ } virtual ~InlineCostCallAnalyzer() {} - int getThreshold() { return Threshold; } - int getCost() { return Cost; } - bool wasDecidedByCostBenefit() { return DecidedByCostBenefit; } + int getThreshold() const { return Threshold; } + int getCost() const { return Cost; } + bool wasDecidedByCostBenefit() const { return DecidedByCostBenefit; } }; class InlineCostFeaturesAnalyzer final : public CallAnalyzer {