Index: include/llvm/Analysis/InlineCost.h =================================================================== --- include/llvm/Analysis/InlineCost.h +++ include/llvm/Analysis/InlineCost.h @@ -33,7 +33,7 @@ const int OptSizeThreshold = 75; // Use when minsize (-Oz) is specified. -const int OptMinSizeThreshold = 25; +const int OptMinSizeThreshold = 5; // Use when -O3 is specified. const int OptAggressiveThreshold = 275; @@ -41,7 +41,6 @@ // Various magic constants used to adjust heuristics. const int InstrCost = 5; const int IndirectCallThreshold = 100; -const int CallPenalty = 25; const int LastCallToStaticBonus = 15000; const int ColdccPenalty = 2000; const int NoreturnPenalty = 10000; Index: lib/Analysis/InlineCost.cpp =================================================================== --- lib/Analysis/InlineCost.cpp +++ lib/Analysis/InlineCost.cpp @@ -931,11 +931,6 @@ // We account for the average 1 instruction per call argument setup // here. Cost += CS.arg_size() * InlineConstants::InstrCost; - - // Everything other than inline ASM will also have a significant cost - // merely from making the call. - if (!isa(CS.getCalledValue())) - Cost += InlineConstants::CallPenalty; } return Base::visitCallSite(CS); @@ -1114,7 +1109,7 @@ if (TTI.getFPOpCost(I->getType()) == TargetTransformInfo::TCC_Expensive || hasSoftFloatAttr) - Cost += InlineConstants::CallPenalty; + Cost += InlineConstants::InstrCost; } // If the instruction simplified to a constant, there is no cost to this @@ -1255,7 +1250,9 @@ Cost -= InlineConstants::InstrCost; } } - + // The call instruction itself will also disappear after inlining. + Cost -= InlineConstants::InstrCost; + // If there is only one call of the function, and it has internal linkage, // the cost of inlining it drops dramatically. bool OnlyOneCallAndLocalLinkage = Index: lib/Transforms/IPO/Inliner.cpp =================================================================== --- lib/Transforms/IPO/Inliner.cpp +++ lib/Transforms/IPO/Inliner.cpp @@ -291,7 +291,7 @@ // treating them as truly abstract units etc. TotalSecondaryCost = 0; // The candidate cost to be imposed upon the current function. - int CandidateCost = IC.getCost() - (InlineConstants::CallPenalty + 1); + int CandidateCost = IC.getCost() - 1; // This bool tracks what happens if we do NOT inline C into B. bool callerWillBeRemoved = Caller->hasLocalLinkage(); // This bool tracks what happens if we DO inline C into B. Index: lib/Transforms/Scalar/LoopStrengthReduce.cpp =================================================================== --- lib/Transforms/Scalar/LoopStrengthReduce.cpp +++ lib/Transforms/Scalar/LoopStrengthReduce.cpp @@ -1061,6 +1061,7 @@ Lose(); return; } + AddRecCost += 1; /// TODO: This should be a function of the stride. // Add the step value register, if it needs one. Index: test/Transforms/Inline/alloca-bonus.ll =================================================================== --- test/Transforms/Inline/alloca-bonus.ll +++ test/Transforms/Inline/alloca-bonus.ll @@ -1,4 +1,4 @@ -; RUN: opt -inline < %s -S -o - -inline-threshold=8 | FileCheck %s +; RUN: opt -inline < %s -S -o - -inline-threshold=4 | FileCheck %s target datalayout = "p:32:32" Index: test/Transforms/Inline/ephemeral.ll =================================================================== --- test/Transforms/Inline/ephemeral.ll +++ test/Transforms/Inline/ephemeral.ll @@ -2,10 +2,8 @@ @a = global i32 4 -define i1 @inner() { +define i32 @inner(i32 %x1) { %a1 = load volatile i32, i32* @a - %x1 = add i32 %a1, %a1 - %c = icmp eq i32 %x1, 0 ; Here are enough instructions to prevent inlining, but because they are used ; only by the @llvm.assume intrinsic, they're free (and, thus, inlining will @@ -18,14 +16,14 @@ %ca = icmp sgt i32 %a6, -7 tail call void @llvm.assume(i1 %ca) - ret i1 %c + ret i32 %a1 } ; @inner() should be inlined for -Oz. -; CHECK-NOT: call i1 @inner -define i1 @outer() optsize { - %r = call i1 @inner() - ret i1 %r +; CHECK-NOT: call i32 @inner +define i32 @outer() optsize { + %r = call i32 @inner(i32 6) + ret i32 %r } declare void @llvm.assume(i1) nounwind Index: test/Transforms/Inline/inline-fp.ll =================================================================== --- test/Transforms/Inline/inline-fp.ll +++ test/Transforms/Inline/inline-fp.ll @@ -1,4 +1,4 @@ -; RUN: opt -S -inline < %s | FileCheck %s +; RUN: opt -S -inline -inline-threshold=25 < %s | FileCheck %s ; Make sure that soft float implementations are calculated as being more expensive ; to the inliner. Index: test/Transforms/Inline/inline_minisize.ll =================================================================== --- test/Transforms/Inline/inline_minisize.ll +++ test/Transforms/Inline/inline_minisize.ll @@ -22,7 +22,6 @@ %mul = mul nsw i32 %tmp2, %tmp5 store i32 %mul, i32* %res, align 4 store i32 0, i32* %i, align 4 - store i32 0, i32* %i, align 4 br label %for.cond for.cond: ; preds = %for.inc, %entry @@ -198,7 +197,7 @@ ret i32 %tmp21 } -define i32 @fct3(i32 %c) nounwind uwtable ssp { +define i32 @fct3(i32 %c) optsize nounwind uwtable ssp { entry: ;CHECK-LABEL: @fct3( ;CHECK: call i32 @fct1 Index: test/Transforms/Inline/invoke-cost.ll =================================================================== --- test/Transforms/Inline/invoke-cost.ll +++ test/Transforms/Inline/invoke-cost.ll @@ -1,4 +1,4 @@ -; RUN: opt -inline < %s -S -o - -inline-threshold=100 | FileCheck %s +; RUN: opt -inline < %s -S -o - -inline-threshold=20 | FileCheck %s target datalayout = "p:32:32" Index: test/Transforms/Inline/nonnull.ll =================================================================== --- test/Transforms/Inline/nonnull.ll +++ test/Transforms/Inline/nonnull.ll @@ -1,4 +1,4 @@ -; RUN: opt -S -inline %s | FileCheck %s +; RUN: opt -S -inline %s -inline-threshold=20 | FileCheck %s declare void @foo() declare void @bar()