[llvm] 7f37a80 - [InlineCost] Add flag to allow changing the default inline cost
Teresa Johnson via llvm-commits
llvm-commits at lists.llvm.org
Tue Feb 4 12:06:59 PST 2020
Author: Teresa Johnson
Date: 2020-02-04T12:06:20-08:00
New Revision: 7f37a8026f6cfe51479309733be642102428fee4
URL: https://github.com/llvm/llvm-project/commit/7f37a8026f6cfe51479309733be642102428fee4
DIFF: https://github.com/llvm/llvm-project/commit/7f37a8026f6cfe51479309733be642102428fee4.diff
LOG: [InlineCost] Add flag to allow changing the default inline cost
Summary:
It can be useful to tune the default inline threshold without overriding other inlining thresholds (e.g. in code compiled for size).
The existing `-inline-threshold` flag overrides other thresholds, so it is insufficient in codebases where there is a mix of code compiled for size and speed.
Patch by Michael Holman <michael.holman at microsoft.com>
Reviewers: eraman, tejohnson
Reviewed By: tejohnson
Subscribers: tejohnson, mtrofin, davidxl, hiraditya, haicheng, llvm-commits
Tags: #llvm
Differential Revision: https://reviews.llvm.org/D73217
Added:
llvm/test/Transforms/Inline/inlinedefault-threshold.ll
Modified:
llvm/lib/Analysis/InlineCost.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Analysis/InlineCost.cpp b/llvm/lib/Analysis/InlineCost.cpp
index 49014e832b88..98ece45cbc13 100644
--- a/llvm/lib/Analysis/InlineCost.cpp
+++ b/llvm/lib/Analysis/InlineCost.cpp
@@ -46,6 +46,11 @@ using namespace llvm;
STATISTIC(NumCallsAnalyzed, "Number of call sites analyzed");
+static cl::opt<int>
+ DefaultThreshold("inlinedefault-threshold", cl::Hidden, cl::init(225),
+ cl::ZeroOrMore,
+ cl::desc("Default amount of inlining to perform"));
+
static cl::opt<int> InlineThreshold(
"inline-threshold", cl::Hidden, cl::init(225), cl::ZeroOrMore,
cl::desc("Control the amount of inlining to perform (default = 225)"));
@@ -2303,7 +2308,7 @@ InlineParams llvm::getInlineParams(int Threshold) {
}
InlineParams llvm::getInlineParams() {
- return getInlineParams(InlineThreshold);
+ return getInlineParams(DefaultThreshold);
}
// Compute the default threshold for inlining based on the opt level and the
@@ -2316,7 +2321,7 @@ static int computeThresholdFromOptLevels(unsigned OptLevel,
return InlineConstants::OptSizeThreshold;
if (SizeOptLevel == 2) // -Oz
return InlineConstants::OptMinSizeThreshold;
- return InlineThreshold;
+ return DefaultThreshold;
}
InlineParams llvm::getInlineParams(unsigned OptLevel, unsigned SizeOptLevel) {
diff --git a/llvm/test/Transforms/Inline/inlinedefault-threshold.ll b/llvm/test/Transforms/Inline/inlinedefault-threshold.ll
new file mode 100644
index 000000000000..195316a9121f
--- /dev/null
+++ b/llvm/test/Transforms/Inline/inlinedefault-threshold.ll
@@ -0,0 +1,113 @@
+; RUN: opt < %s -O2 -inlinedefault-threshold=100 -S | FileCheck %s
+
+; Check that the inlinedefault-threshold does not alter the inline threshold
+; for optsize or minsize functions
+
+ at a = global i32 4
+
+define i32 @inner() {
+ call void @extern()
+ %a1 = load volatile i32, i32* @a
+ %x1 = add i32 %a1, %a1
+ ret i32 %x1
+}
+
+define i32 @inner2() {
+ call void @extern()
+ %a1 = load volatile i32, i32* @a
+ %x1 = add i32 %a1, %a1
+ %a2 = load volatile i32, i32* @a
+ %x2 = add i32 %x1, %a2
+ %a3 = load volatile i32, i32* @a
+ %x3 = add i32 %x2, %a3
+ %a4 = load volatile i32, i32* @a
+ %x4 = add i32 %x3, %a4
+ %a5 = load volatile i32, i32* @a
+ %x5 = add i32 %x3, %a5
+ %a6 = load volatile i32, i32* @a
+ %x6 = add i32 %x5, %a6
+ %a7 = load volatile i32, i32* @a
+ %x7 = add i32 %x6, %a7
+ %a8 = load volatile i32, i32* @a
+ %x8 = add i32 %x7, %a8
+ ret i32 %x8
+}
+
+define i32 @inner3() {
+ call void @extern()
+ %a1 = load volatile i32, i32* @a
+ %x1 = add i32 %a1, %a1
+ %a2 = load volatile i32, i32* @a
+ %x2 = add i32 %x1, %a2
+ %a3 = load volatile i32, i32* @a
+ %x3 = add i32 %x2, %a3
+ %a4 = load volatile i32, i32* @a
+ %x4 = add i32 %x3, %a4
+ %a5 = load volatile i32, i32* @a
+ %x5 = add i32 %x4, %a5
+ %a6 = load volatile i32, i32* @a
+ %x6 = add i32 %x5, %a6
+ %a7 = load volatile i32, i32* @a
+ %x7 = add i32 %x6, %a7
+ %a8 = load volatile i32, i32* @a
+ %x8 = add i32 %x7, %a8
+ %a9 = load volatile i32, i32* @a
+ %x9 = add i32 %x8, %a9
+ %a10 = load volatile i32, i32* @a
+ %x10 = add i32 %x9, %a10
+ %a11 = load volatile i32, i32* @a
+ %x11 = add i32 %x10, %a11
+ %a12 = load volatile i32, i32* @a
+ %x12 = add i32 %x11, %a12
+ %a13 = load volatile i32, i32* @a
+ %x13 = add i32 %x12, %a13
+ %a14 = load volatile i32, i32* @a
+ %x14 = add i32 %x13, %a14
+ %a15 = load volatile i32, i32* @a
+ %x15 = add i32 %x14, %a15
+ ret i32 %x15
+}
+
+define i32 @outer() optsize {
+; CHECK-LABEL: @outer
+; CHECK-NOT: call i32 @inner()
+ %r = call i32 @inner()
+ ret i32 %r
+}
+
+define i32 @outer2() optsize {
+; CHECK-LABEL: @outer2
+; CHECK: call i32 @inner2()
+ %r = call i32 @inner2()
+ ret i32 %r
+}
+
+define i32 @outer3() minsize {
+; CHECK-LABEL: @outer3
+; CHECK: call i32 @inner()
+ %r = call i32 @inner()
+ ret i32 %r
+}
+
+define i32 @outer4() {
+; CHECK-LABEL: @outer4
+; CHECK-NOT: call i32 @inner()
+ %r = call i32 @inner()
+ ret i32 %r
+}
+
+define i32 @outer5() {
+; CHECK-LABEL: @outer5
+; CHECK-NOT: call i32 @inner2()
+ %r = call i32 @inner2()
+ ret i32 %r
+}
+
+define i32 @outer6() {
+; CHECK-LABEL: @outer6
+; CHECK: call i32 @inner3()
+ %r = call i32 @inner3()
+ ret i32 %r
+}
+
+declare void @extern()
More information about the llvm-commits
mailing list