[PATCH] D34471: [Inliner] Boost inlining of an indirect call to always_inline function.
Easwaran Raman via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Wed Jun 21 12:11:29 PDT 2017
eraman created this revision.
Herald added a subscriber: mehdi_amini.
If inlining baz->bar makes an indirect call inside bar to be a direct
call to foo with always_inline hint, boost the chances of baz->bar
inlining (and therefore bar->foo inlining) by adding a large negative
cost. I have used LastCallToStaticBonus here, but if that makes it
confusing I will create another constant with similar high value.
https://reviews.llvm.org/D34471
Files:
lib/Analysis/InlineCost.cpp
test/Transforms/Inline/inline-indirect-always.ll
Index: test/Transforms/Inline/inline-indirect-always.ll
===================================================================
--- /dev/null
+++ test/Transforms/Inline/inline-indirect-always.ll
@@ -0,0 +1,32 @@
+; RUN: opt -S -inline -inline-threshold=0 < %s | FileCheck %s
+declare void @ext();
+
+define void @foo() #1 {
+ call void @ext();
+ ret void
+}
+
+define void @bar(void ()* %fptr) {
+ call void %fptr();
+ call void @ext();
+ call void @ext();
+ call void @ext();
+ call void @ext();
+ call void @ext();
+ call void @ext();
+ call void @ext();
+ call void @ext();
+ call void @ext();
+ call void @ext();
+ call void @ext();
+ ret void
+}
+; CHECK-LABEL: @baz
+define void @baz() {
+; CHECK-NOT: call void @bar
+ call void @bar(void ()* @foo)
+; CHECK: ret
+ ret void
+}
+
+attributes #1 = { alwaysinline }
Index: lib/Analysis/InlineCost.cpp
===================================================================
--- lib/Analysis/InlineCost.cpp
+++ lib/Analysis/InlineCost.cpp
@@ -970,7 +970,17 @@
// through it and see the function target. This happens not infrequently
// during devirtualization and so we want to give it a hefty bonus for
// inlining, but cap that bonus in the event that inlining wouldn't pan
- // out. Pretend to inline the function, with a custom threshold.
+ // out.
+
+ // First, check if the function has AlwaysInline attribute and give a huge
+ // bonus if that is the case.
+ if (F->hasFnAttribute(Attribute::AlwaysInline)) {
+ Cost -= InlineConstants::LastCallToStaticBonus;
+ return Base::visitCallSite(CS);
+ }
+
+ // Otherwise, pretend to inline the function, with a custom threshold and give
+ // a bonus based on this threshold and the cost of inlining F.
auto IndirectCallParams = Params;
IndirectCallParams.DefaultThreshold = InlineConstants::IndirectCallThreshold;
CallAnalyzer CA(TTI, GetAssumptionCache, GetBFI, PSI, *F, CS,
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D34471.103438.patch
Type: text/x-patch
Size: 1919 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20170621/2fc5be20/attachment.bin>
More information about the llvm-commits
mailing list