[PATCH] D29169: Do not apply redundant LastCallToStaticBonus
Taewook Oh via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 26 21:57:09 PST 2017
twoh updated this revision to Diff 86015.
twoh added a comment.
Test case added. As InlineConstants::LastCallToStaticBonus has a massive value,
I use the loop unrolling pass with a big threshold to preprocess the test.
Without the patch, the cost of inlining 'bar' into 'foo' is largely undervalued
because LastCallToStaticBonus is applied twice. This prevents the inlining of
'baz' into 'bar', as inliner thinks that inlining 'bar' into 'foo' is more
beneficial (and inlining 'baz' into 'bar' will prevent the inlining of 'bar'
into 'foo'). Later, inliner inlines 'bar' into 'foo', then 'baz' into 'foo' as
well. Therefore, there's only 'foo' left in the end.
With the patch, inliner precisely computes the cost of inlining 'bar' into
'foo', and let 'baz' inlined into 'bar'. This prevents the inlining of 'bar'
into 'foo' by increasing the inlining cost of 'bar'.
https://reviews.llvm.org/D29169
Files:
lib/Transforms/IPO/Inliner.cpp
test/Transforms/Inline/last-call-bonus.ll
Index: test/Transforms/Inline/last-call-bonus.ll
===================================================================
--- /dev/null
+++ test/Transforms/Inline/last-call-bonus.ll
@@ -0,0 +1,41 @@
+; RUN: opt < %s -loop-unroll -inline -unroll-threshold=15000 -inline-threshold=250 -S | FileCheck %s
+; CHECK-LABEL: define internal i32 @bar()
+
+define internal i32 @baz() {
+entry:
+ br label %bb1
+
+bb1:
+ %ind = phi i32 [ 0, %entry ], [ %inc, %bb1 ]
+ call void @extern()
+ %inc = add nsw i32 %ind, 1
+ %cmp = icmp sgt i32 %inc, 510
+ br i1 %cmp, label %ret, label %bb1
+
+ret:
+ ret i32 0
+}
+
+define internal i32 @bar() {
+entry:
+ br label %bb1
+
+bb1:
+ %ind = phi i32 [ 0, %entry ], [ %inc, %bb1 ]
+ call void @extern()
+ %inc = add nsw i32 %ind, 1
+ %cmp = icmp sgt i32 %inc, 510
+ br i1 %cmp, label %ret, label %bb1
+
+ret:
+ call i32 @baz()
+ ret i32 0
+}
+
+define i32 @foo() {
+entry:
+ call i32 @bar()
+ ret i32 0
+}
+
+declare void @extern()
Index: lib/Transforms/IPO/Inliner.cpp
===================================================================
--- lib/Transforms/IPO/Inliner.cpp
+++ lib/Transforms/IPO/Inliner.cpp
@@ -326,7 +326,7 @@
// one is set very low by getInlineCost, in anticipation that Caller will
// be removed entirely. We did not account for this above unless there
// is only one caller of Caller.
- if (callerWillBeRemoved && !Caller->use_empty())
+ if (callerWillBeRemoved && !Caller->hasOneUse())
TotalSecondaryCost -= InlineConstants::LastCallToStaticBonus;
if (inliningPreventsSomeOuterInline && TotalSecondaryCost < IC.getCost())
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D29169.86015.patch
Type: text/x-patch
Size: 1606 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170127/d7102031/attachment.bin>
More information about the llvm-commits
mailing list