[PATCH] D119579: [Inliner] Respect noinline call site attribute
Dávid Bolvanský via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Fri Feb 11 12:51:42 PST 2022
xbolva00 updated this revision to Diff 408002.
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D119579/new/
https://reviews.llvm.org/D119579
Files:
llvm/lib/Analysis/InlineCost.cpp
llvm/test/Transforms/Inline/call-site-attrs.ll
Index: llvm/test/Transforms/Inline/call-site-attrs.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/Inline/call-site-attrs.ll
@@ -0,0 +1,59 @@
+; RUN: opt < %s -inline -S | FileCheck %s
+; RUN: opt < %s -passes='cgscc(inline)' -S | FileCheck %s
+
+; Always prefer call site attribute over function attribute
+
+define internal i32 @inner1() {
+; CHECK: @inner1(
+ ret i32 1
+}
+
+define i32 @outer1() {
+; CHECK-LABEL: @outer1(
+; CHECK: call
+
+ %r = call i32 @inner1() noinline
+ ret i32 %r
+}
+
+define internal i32 @inner2() alwaysinline {
+; CHECK: @inner2(
+ ret i32 1
+}
+
+define i32 @outer2() {
+; CHECK-LABEL: @outer2(
+; CHECK: call
+
+ %r = call i32 @inner2() noinline
+ ret i32 %r
+}
+
+define i32 @inner3() alwaysinline {
+; CHECK: @inner3(
+ ret i32 1
+}
+
+define i32 @outer3() {
+; CHECK-LABEL: @outer3(
+; CHECK: call
+
+ %r = call i32 @inner3() noinline
+ ret i32 %r
+}
+
+define i32 @inner4() noinline {
+; CHECK: @inner4(
+ ret i32 1
+}
+
+define i32 @outer4() {
+; CHECK-LABEL: @outer4(
+; CHECK-NOT: call
+; CHECK: ret
+
+ %r = call i32 @inner4() alwaysinline
+
+ ret i32 %r
+}
+
Index: llvm/lib/Analysis/InlineCost.cpp
===================================================================
--- llvm/lib/Analysis/InlineCost.cpp
+++ llvm/lib/Analysis/InlineCost.cpp
@@ -2864,6 +2864,9 @@
// Calls to functions with always-inline attributes should be inlined
// whenever possible.
if (Call.hasFnAttr(Attribute::AlwaysInline)) {
+ if (Callee->hasFnAttribute(Attribute::AlwaysInline) && Call.isNoInline())
+ return InlineResult::failure("noinline call site attribute");
+
auto IsViable = isInlineViable(*Callee);
if (IsViable.isSuccess())
return InlineResult::success();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D119579.408002.patch
Type: text/x-patch
Size: 1802 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20220211/3cb0d122/attachment.bin>
More information about the llvm-commits
mailing list