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 @@ -2609,6 +2614,16 @@ LLVM_DEBUG(CA.dump()); + // Always make cost benefit based decision explicit. + // We use always/never here since threshold is not meaningful, + // as it's not what drives cost-benefit analysis. + if (CA.wasDecidedByCostBenefit()) { + if (ShouldInline.isSuccess()) + return InlineCost::getAlways("benefit over cost"); + else + return InlineCost::getNever("cost over benefit"); + } + // Check if there was a reason to force inlining or no inlining. if (!ShouldInline.isSuccess() && CA.getCost() < CA.getThreshold()) return InlineCost::getNever(ShouldInline.getFailureReason());