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; @@ -832,6 +835,7 @@ Threshold -= VectorBonus / 2; if (auto Result = costBenefitAnalysis()) { + DecidedByCostBenefit = true; if (Result.getValue()) return InlineResult::success(); else @@ -933,6 +937,7 @@ virtual ~InlineCostCallAnalyzer() {} int getThreshold() { return Threshold; } int getCost() { return Cost; } + bool wasDecidedByCostBenefit() { return DecidedByCostBenefit; } }; } // namespace @@ -2616,6 +2621,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()); diff --git a/llvm/test/Other/optimization-remarks-auto.ll b/llvm/test/Other/optimization-remarks-auto.ll --- a/llvm/test/Other/optimization-remarks-auto.ll +++ b/llvm/test/Other/optimization-remarks-auto.ll @@ -10,14 +10,14 @@ ; RUN: FileCheck %s -check-prefix=YAML-MISS < %t.yaml ;; test 'auto' threshold -; RUN: opt < %s --disable-output --enable-new-pm \ +; RUN: opt < %s --disable-output --enable-new-pm --inline-enable-cost-benefit-analysis=0 \ ; RUN: --passes='module(print-profile-summary,cgscc(inline))' \ ; RUN: --pass-remarks-output=%t.hot.yaml --pass-remarks-filter='inline' \ ; RUN: --pass-remarks-with-hotness --pass-remarks-hotness-threshold=auto 2>&1 | FileCheck %s ; RUN: FileCheck %s -check-prefix=YAML-PASS < %t.hot.yaml ; RUN: not FileCheck %s -check-prefix=YAML-MISS < %t.hot.yaml -; RUN: opt < %s --disable-output --enable-new-pm \ +; RUN: opt < %s --disable-output --enable-new-pm --inline-enable-cost-benefit-analysis=0 \ ; RUN: --passes='module(print-profile-summary,cgscc(inline))' \ ; RUN: --pass-remarks=inline --pass-remarks-missed=inline --pass-remarks-analysis=inline \ ; RUN: --pass-remarks-with-hotness --pass-remarks-hotness-threshold=auto 2>&1 | FileCheck %s -check-prefix=CHECK-RPASS @@ -82,4 +82,3 @@ !12 = !{i32 10000, i64 100, i32 1} !13 = !{i32 999000, i64 100, i32 1} !14 = !{i32 999999, i64 1, i32 2} -