Index: llvm/lib/Analysis/InlineCost.cpp =================================================================== --- llvm/lib/Analysis/InlineCost.cpp +++ llvm/lib/Analysis/InlineCost.cpp @@ -899,11 +899,11 @@ int VectorBonusPercent = 150; int LastCallToStaticBonus = InlineConstants::LastCallToStaticBonus; - // Lambda to set all the above bonus and bonus percentages to 0. - auto DisallowAllBonuses = [&]() { + // Lambda to significantly reduce all the above bonus and bonus percentages. + auto ReduceAllBonuses = [&]() { SingleBBBonusPercent = 0; VectorBonusPercent = 0; - LastCallToStaticBonus = 0; + LastCallToStaticBonus = 50; }; // Use the OptMinSizeThreshold or OptSizeThreshold knob if they are available @@ -943,11 +943,11 @@ Threshold = HotCallSiteThreshold.getValue(); } else if (isColdCallSite(Call, CallerBFI)) { LLVM_DEBUG(dbgs() << "Cold callsite.\n"); - // Do not apply bonuses for a cold callsite including the + // Significantly reduce bonuses for a cold callsite including the // LastCallToStatic bonus. While this bonus might result in code size // reduction, it can cause the size of a non-cold caller to increase // preventing it from being inlined. - DisallowAllBonuses(); + ReduceAllBonuses(); Threshold = MinIfValid(Threshold, Params.ColdCallSiteThreshold); } else if (PSI) { // Use callee's global profile information only if we have no way of @@ -960,11 +960,11 @@ Threshold = MaxIfValid(Threshold, Params.HintThreshold); } else if (PSI->isFunctionEntryCold(&Callee)) { LLVM_DEBUG(dbgs() << "Cold callee.\n"); - // Do not apply bonuses for a cold callee including the + // Significantly reduce bonuses for a cold callee including the // LastCallToStatic bonus. While this bonus might result in code size // reduction, it can cause the size of a non-cold caller to increase // preventing it from being inlined. - DisallowAllBonuses(); + ReduceAllBonuses(); Threshold = MinIfValid(Threshold, Params.ColdThreshold); } } Index: llvm/test/Transforms/Inline/last-call-no-bonus.ll =================================================================== --- llvm/test/Transforms/Inline/last-call-no-bonus.ll +++ llvm/test/Transforms/Inline/last-call-no-bonus.ll @@ -2,7 +2,7 @@ ; to the internal functions are cold, thereby preventing the last call to ; static bonus from being applied. -; RUN: opt < %s -passes='function(require,unroll),require,cgscc(inline)' -unroll-threshold=15000 -inline-threshold=250 -S | FileCheck %s +; RUN: opt < %s -passes='function(require,unroll),require,cgscc(inline)' -unroll-threshold=15000 -inline-threshold=0 -S | FileCheck %s ; CHECK-LABEL: define internal i32 @baz define internal i32 @baz() { @@ -41,6 +41,12 @@ ret: ret i32 0 } + +define internal i32 @bac() { + call void @extern() + ret i32 0 +} + ; CHECK-LABEL: define i32 @foo define i32 @foo(i1 %b) { entry: @@ -48,6 +54,8 @@ bb1: ; CHECK: call i32 @bar call i32 @bar(i1 %b) +; CHECK-NOT: call i32 @bac + call i32 @bac() br label %ret ret: ret i32 0