[PATCH] D102602: [Inliner] Copy attributes when deoptimize intrinsic is inlined

Serguei Katkov via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Mon May 17 02:32:13 PDT 2021


skatkov created this revision.
skatkov added reviewers: reames, apilipenko.
Herald added a subscriber: hiraditya.
skatkov requested review of this revision.
Herald added a project: LLVM.

During this inlining of call-site with deoptimize intrinsic callee we miss
attributes set on this call site. As a result attributes like deopt-lowering are
disappeared resulting in in-efficient behavior of register allocator in codegen.

Just copy attributes for deoptimize call like we do for others calls.


https://reviews.llvm.org/D102602

Files:
  llvm/lib/Transforms/Utils/InlineFunction.cpp
  llvm/test/Transforms/Inline/deoptimize-intrinsic-attrs.ll


Index: llvm/test/Transforms/Inline/deoptimize-intrinsic-attrs.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/Inline/deoptimize-intrinsic-attrs.ll
@@ -0,0 +1,22 @@
+; RUN: opt -S -always-inline < %s | FileCheck %s
+
+declare cc42 i32 @llvm.experimental.deoptimize.i32(...)
+
+define i32 @callee_with_coldcc() alwaysinline {
+  %v0 = call cc42 i32(...) @llvm.experimental.deoptimize.i32(i32 1) #0 [ "deopt"() ]
+  ret i32 %v0
+}
+
+define void @caller_with_coldcc() {
+; CHECK-LABEL: @caller_with_coldcc(
+; CHECK-NEXT:  call cc42 void (...) @llvm.experimental.deoptimize.isVoid(i32 1) #1 [ "deopt"() ]
+; CHECK-NEXT:  ret void
+
+  %val = call i32 @callee_with_coldcc()
+  ret void
+}
+
+attributes #0 = { "deopt-lowering"="live-in" }
+
+; CHECK: declare cc42 void @llvm.experimental.deoptimize.isVoid(...)
+; CHECK: attributes #1 = { "deopt-lowering"="live-in" }
\ No newline at end of file
Index: llvm/lib/Transforms/Utils/InlineFunction.cpp
===================================================================
--- llvm/lib/Transforms/Utils/InlineFunction.cpp
+++ llvm/lib/Transforms/Utils/InlineFunction.cpp
@@ -2374,6 +2374,7 @@
 
         SmallVector<OperandBundleDef, 1> OpBundles;
         DeoptCall->getOperandBundlesAsDefs(OpBundles);
+        auto DeoptAttributes = DeoptCall->getAttributes();
         DeoptCall->eraseFromParent();
         assert(!OpBundles.empty() &&
                "Expected at least the deopt operand bundle");
@@ -2382,6 +2383,7 @@
         CallInst *NewDeoptCall =
             Builder.CreateCall(NewDeoptIntrinsic, CallArgs, OpBundles);
         NewDeoptCall->setCallingConv(CallingConv);
+        NewDeoptCall->setAttributes(DeoptAttributes);
         if (NewDeoptCall->getType()->isVoidTy())
           Builder.CreateRetVoid();
         else


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D102602.345799.patch
Type: text/x-patch
Size: 1841 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20210517/dfbc79b8/attachment.bin>


More information about the llvm-commits mailing list