Index: lib/Analysis/InlineCost.cpp =================================================================== --- lib/Analysis/InlineCost.cpp +++ lib/Analysis/InlineCost.cpp @@ -840,24 +840,6 @@ } void CallAnalyzer::updateThreshold(CallSite CS, Function &Callee) { - // If no size growth is allowed for this inlining, set Threshold to 0. - if (!allowSizeGrowth(CS)) { - Threshold = 0; - return; - } - - Function *Caller = CS.getCaller(); - - // return min(A, B) if B is valid. - auto MinIfValid = [](int A, Optional B) { - return B ? std::min(A, B.getValue()) : A; - }; - - // return max(A, B) if B is valid. - auto MaxIfValid = [](int A, Optional B) { - return B ? std::max(A, B.getValue()) : A; - }; - // Various bonus percentages. These are multiplied by Threshold to get the // bonus values. // SingleBBBonus: This bonus is applied if the callee has a single reachable @@ -883,6 +865,34 @@ int VectorBonusPercent = 150; int LastCallToStaticBonus = InlineConstants::LastCallToStaticBonus; + // If this is true, then we can apply the LastCallToStaticBonus. + bool OnlyOneCallAndLocalLinkage = + F.hasLocalLinkage() && F.hasOneUse() && &F == CS.getCalledFunction(); + + // If no size growth is allowed in this inlining, set the threshold to 0 and + // apply any cost bonuses. After that, return. + if (!allowSizeGrowth(CS)) { + Threshold = 0; + + // This could still be "zero-cost" if F only has one use and has local + // linkage. Apply the LastCallToStatic bonus if it applies. + if (OnlyOneCallAndLocalLinkage) + Cost -= LastCallToStaticBonus; + return; + } + + Function *Caller = CS.getCaller(); + + // return min(A, B) if B is valid. + auto MinIfValid = [](int A, Optional B) { + return B ? std::min(A, B.getValue()) : A; + }; + + // return max(A, B) if B is valid. + auto MaxIfValid = [](int A, Optional B) { + return B ? std::max(A, B.getValue()) : A; + }; + // Lambda to set all the above bonus and bonus percentages to 0. auto DisallowAllBonuses = [&]() { SingleBBBonusPercent = 0; @@ -961,8 +971,6 @@ SingleBBBonus = Threshold * SingleBBBonusPercent / 100; VectorBonus = Threshold * VectorBonusPercent / 100; - bool OnlyOneCallAndLocalLinkage = - F.hasLocalLinkage() && F.hasOneUse() && &F == CS.getCalledFunction(); // If there is only one call of the function, and it has internal linkage, // the cost of inlining it drops dramatically. It may seem odd to update // Cost in updateThreshold, but the bonus depends on the logic in this method. Index: test/Transforms/Inline/ARM/unreachable.ll =================================================================== --- /dev/null +++ test/Transforms/Inline/ARM/unreachable.ll @@ -0,0 +1,21 @@ +; RUN: opt < %s -mtriple=arm--- -S -inline | FileCheck %s + +declare i32* @pluto() local_unnamed_addr #0 + +define internal void @foo() local_unnamed_addr #0 { +bb: + call i32* @pluto() #0 + ret void +} + +define void @wibble() unnamed_addr #0 { +; CHECK-LABEL: wibble +; CHECK-NOT: @foo() +; CHECK: %0 = call i32* @pluto() +; CHECK-NEXT: unreachable +bb: + tail call void @foo() #0 + unreachable +} + +attributes #0 = { minsize optsize }