[PATCH] D158286: [Inline] Avoid incompatible return attributes on deoptimize

Anna Thomas via Phabricator via llvm-commits llvm-commits at lists.llvm.org
Fri Aug 18 08:16:25 PDT 2023


anna created this revision.
anna added reviewers: nikic, goldstein.w.n, danilaml.
Herald added subscribers: StephenFan, hiraditya.
Herald added a project: All.
anna requested review of this revision.
Herald added a project: LLVM.
Herald added a subscriber: llvm-commits.

When adding return attributes to calls within a callee, we need to
specially handle deoptimize intrinsic call. This bug came about once we
relaxed the contraint of adding the attributes through 4d51c6 (with that
change deoptimize which is not marked `willreturn` will start having
return attributes added to it).

Deoptimize calls have their return type changed to the caller's return
type during inlining, which means the attribute being added based on the
callee's return type maybe incompatible.

Fix PR64804.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D158286

Files:
  llvm/lib/Transforms/Utils/InlineFunction.cpp
  llvm/test/Transforms/Inline/pr64804.ll


Index: llvm/test/Transforms/Inline/pr64804.ll
===================================================================
--- /dev/null
+++ llvm/test/Transforms/Inline/pr64804.ll
@@ -0,0 +1,18 @@
+; RUN: opt -S -passes=inline < %s | FileCheck %s
+
+declare ptr @llvm.experimental.deoptimize.p0(...)
+
+; Make sure we do not add incompatible attribute (noalias) to the deoptimize call.
+
+define ptr @callee_noalias(ptr %c) {
+  %v2 = call ptr (...) @llvm.experimental.deoptimize.p0(i32 42 ) [ "deopt"(i32 1) ]
+  ret ptr %v2
+}
+
+; CHECK-LABEL: caller_noalias
+; CHECK: call void (...) @llvm.experimental.deoptimize.isVoid(i32 42) [ "deopt"(i32 2, i32 1) ]
+define void @caller_noalias(ptr %c) {
+entry:
+  %v = call noalias ptr @callee_noalias(ptr %c)  [ "deopt"(i32 2) ]
+  ret void
+}
Index: llvm/lib/Transforms/Utils/InlineFunction.cpp
===================================================================
--- llvm/lib/Transforms/Utils/InlineFunction.cpp
+++ llvm/lib/Transforms/Utils/InlineFunction.cpp
@@ -1376,6 +1376,13 @@
     auto *NewRetVal = dyn_cast_or_null<CallBase>(VMap.lookup(RetVal));
     if (!NewRetVal)
       continue;
+    // Deoptimize calls are special since their deopt bundles are updated with
+    // the caller deopt bundle and the return type is updated to the caller
+    // return type later during inlining. So, we cannot update the return
+    // attribute(s) of the deopt call with that of the callee.
+    if (auto *F = NewRetVal->getCalledFunction())
+      if (F->getIntrinsicID() == Intrinsic::experimental_deoptimize)
+        continue;
     // Backward propagation of attributes to the returned value may be incorrect
     // if it is control flow dependent.
     // Consider:


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D158286.551522.patch
Type: text/x-patch
Size: 1709 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/llvm-commits/attachments/20230818/e4cd48f4/attachment.bin>


More information about the llvm-commits mailing list