[PATCH] D92623: [inliner] Apply nomerge attribute to all call sites inside inlined function.
Zequan Wu via Phabricator via llvm-commits
llvm-commits at lists.llvm.org
Thu Dec 3 17:29:27 PST 2020
zequanwu created this revision.
zequanwu added reviewers: rnk, craig.topper.
Herald added a subscriber: hiraditya.
zequanwu requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.
[[clang::nomerge]] statement attribute stops optimizer from merging multiple calls into one. When inlining happends, the attribute got lost, which is not desired.
Repository:
rG LLVM Github Monorepo
https://reviews.llvm.org/D92623
Files:
llvm/lib/Transforms/Utils/InlineFunction.cpp
llvm/test/Transforms/Inline/inline_nomerge.ll
Index: llvm/test/Transforms/Inline/inline_nomerge.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/Inline/inline_nomerge.ll
@@ -0,0 +1,37 @@
+; Check nomerge attribute at call sites applying to all call sites inside the inlined function.
+; RUN: opt < %s -O3 -S | FileCheck %s
+
+declare void @f()
+declare void @g()
+
+define void @bar() {
+entry:
+ call void @f()
+ call void @g()
+ ret void
+}
+
+define void @foo(i32 %i) {
+entry:
+ switch i32 %i, label %if.end [
+ i32 5, label %if.then
+ i32 7, label %if.then2
+ ]
+
+if.then:
+ call void @bar() #0 ; CHECK: call void @f() #0
+ ; CHECK-NEXT: call void @g() #0
+ br label %if.end
+
+if.then2:
+ call void @bar() #0 ; CHECK: call void @f() #0
+ ; CHECK-NEXT: call void @g() #0
+ br label %if.end
+
+if.end:
+ call void @bar() #0 ; CHECK: call void @f() #0
+ ; CHECK-NEXT: call void @g() #0
+ ret void
+}
+
+attributes #0 = { nomerge }
Index: llvm/lib/Transforms/Utils/InlineFunction.cpp
===================================================================
--- llvm/lib/Transforms/Utils/InlineFunction.cpp
+++ llvm/lib/Transforms/Utils/InlineFunction.cpp
@@ -1970,6 +1970,10 @@
if (!CI)
continue;
+ // Apply nomerge attribute to all call sites inside inlined function.
+ if (CB.hasFnAttr(Attribute::NoMerge))
+ CI->setCannotMerge();
+
// Forward varargs from inlined call site to calls to the
// ForwardVarArgsTo function, if requested, and to musttail calls.
if (!VarArgsToForward.empty() &&
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D92623.309416.patch
Type: text/x-patch
Size: 1669 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20201204/2c5944d8/attachment.bin>
More information about the llvm-commits
mailing list