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 @@ -489,6 +489,9 @@ // sense that it's not weighted by profile counts at all. int ColdSize = 0; + // Whether inlining is decided by cost-benefit analysis. + bool DecidedByCostBenefit = false; + bool SingleBB = true; unsigned SROACostSavings = 0; @@ -825,6 +828,7 @@ Threshold -= VectorBonus / 2; if (auto Result = costBenefitAnalysis()) { + DecidedByCostBenefit = true; if (Result.getValue()) return InlineResult::success(); else @@ -926,6 +930,7 @@ virtual ~InlineCostCallAnalyzer() {} int getThreshold() { return Threshold; } int getCost() { return Cost; } + bool wasDecidedByCostBenefit() { return DecidedByCostBenefit; } }; } // namespace @@ -2610,6 +2615,8 @@ LLVM_DEBUG(CA.dump()); // Check if there was a reason to force inlining or no inlining. + if (ShouldInline.isSuccess() && CA.wasDecidedByCostBenefit()) + return InlineCost::getAlways("benefit over cost"); if (!ShouldInline.isSuccess() && CA.getCost() < CA.getThreshold()) return InlineCost::getNever(ShouldInline.getFailureReason()); if (ShouldInline.isSuccess() && CA.getCost() >= CA.getThreshold())