[PATCH] D150989: [Inliner] Mark inlinings stopped with inlining history as noinline

Arthur Eubanks via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri May 19 12:40:27 PDT 2023

aeubanks created this revision.
aeubanks added reviewers: davidxl, mtrofin, nikic, jmorse.
Herald added subscribers: hoy, ormris, StephenFan, hiraditya, Prazek.
Herald added a project: All.
aeubanks requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

The inline history makes sure that we don't keep inlining due to mutual devirtualization. But this gets forgotten between inliner invocations.

So mark the inlined calls as noinline so we respect previous inline history decisions.

This overlaps with D121084 <https://reviews.llvm.org/D121084>, but they're not redundant since we may not inline completely through a child SCC, but we still want a cost multiplier when that happens.

See discussions in D145516 <https://reviews.llvm.org/D145516>.

  rG LLVM Github Monorepo



Index: llvm/test/Transforms/Inline/inline-history-noinline.ll
--- /dev/null
+++ llvm/test/Transforms/Inline/inline-history-noinline.ll
@@ -0,0 +1,32 @@
+; RUN: opt -passes=inline -S < %s | FileCheck %s
+; This will inline @f1 into @a, causing two new calls to @f2, which will get inlined for two calls to @f1.
+; The inline history should stop recursive inlining here, and make sure to mark the inlined calls as noinline so we don't repeat the inlining later on when @a gets inlined into @b.
+define internal void @f1(ptr %p) {
+  call void %p(ptr @f1)
+  ret void
+define internal void @f2(ptr %p) {
+  call void %p(ptr @f2)
+  call void %p(ptr @f2)
+  ret void
+define void @b() {
+; CHECK-LABEL: define void @b() {
+; CHECK-NEXT:    call void @f1(ptr @f2) #[[NOINLINE:[0-9]+]]
+; CHECK-NEXT:    call void @f1(ptr @f2) #[[NOINLINE]]
+; CHECK-NEXT:    ret void
+  call void @a()
+  ret void
+define internal void @a() {
+  call void @f1(ptr @f2)
+  ret void
+; CHECK: [[NOINLINE]] = { noinline }
Index: llvm/lib/Transforms/IPO/Inliner.cpp
--- llvm/lib/Transforms/IPO/Inliner.cpp
+++ llvm/lib/Transforms/IPO/Inliner.cpp
@@ -333,6 +333,7 @@
         LLVM_DEBUG(dbgs() << "Skipping inlining due to history: " << F.getName()
                           << " -> " << Callee.getName() << "\n");
         setInlineRemark(*CB, "recursive");
+        CB->setIsNoInline();

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D150989.523900.patch
Type: text/x-patch
Size: 1556 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230519/4ca410c1/attachment.bin>

More information about the llvm-commits mailing list