Skip to content

Conversation

@arsenm
Copy link
Contributor

@arsenm arsenm commented Dec 5, 2025

No description provided.

Copy link
Contributor Author

arsenm commented Dec 5, 2025

Warning

This pull request is not mergeable via GitHub because a downstack PR is open. Once all requirements are satisfied, merge this PR as a stack on Graphite.
Learn more

This stack of pull requests is managed by Graphite. Learn more about stacking.

@llvmbot
Copy link
Member

llvmbot commented Dec 5, 2025

@llvm/pr-subscribers-llvm-selectiondag

@llvm/pr-subscribers-backend-amdgpu

Author: Matt Arsenault (arsenm)

Changes

Full diff: https://github.com/llvm/llvm-project/pull/170940.diff

2 Files Affected:

  • (modified) llvm/lib/CodeGen/SelectionDAG/StatepointLowering.cpp (+10-2)
  • (modified) llvm/test/CodeGen/AMDGPU/llvm.deoptimize.ll (+2-6)
diff --git a/llvm/lib/CodeGen/SelectionDAG/StatepointLowering.cpp b/llvm/lib/CodeGen/SelectionDAG/StatepointLowering.cpp
index 5b8cd343557fa..d34f3211dc463 100644
--- a/llvm/lib/CodeGen/SelectionDAG/StatepointLowering.cpp
+++ b/llvm/lib/CodeGen/SelectionDAG/StatepointLowering.cpp
@@ -1307,9 +1307,17 @@ void SelectionDAGBuilder::visitGCRelocate(const GCRelocateInst &Relocate) {
 
 void SelectionDAGBuilder::LowerDeoptimizeCall(const CallInst *CI) {
   const auto &TLI = DAG.getTargetLoweringInfo();
-  SDValue Callee = DAG.getExternalSymbol(TLI.getLibcallName(RTLIB::DEOPTIMIZE),
-                                         TLI.getPointerTy(DAG.getDataLayout()));
 
+  RTLIB::LibcallImpl DeoptImpl = TLI.getLibcallImpl(RTLIB::DEOPTIMIZE);
+  if (DeoptImpl == RTLIB::Unsupported) {
+    DAG.getContext()->emitError("no deoptimize libcall available");
+    return;
+  }
+
+  SDValue Callee =
+      DAG.getExternalSymbol(DeoptImpl, TLI.getPointerTy(DAG.getDataLayout()));
+
+  // FIXME: Should pass in the calling convention for the LibcallImpl.
   // We don't lower calls to __llvm_deoptimize as varargs, but as a regular
   // call.  We also do not lower the return value to any virtual register, and
   // change the immediately following return to a trap instruction.
diff --git a/llvm/test/CodeGen/AMDGPU/llvm.deoptimize.ll b/llvm/test/CodeGen/AMDGPU/llvm.deoptimize.ll
index ef8c00bb3b4b0..53446b644445a 100644
--- a/llvm/test/CodeGen/AMDGPU/llvm.deoptimize.ll
+++ b/llvm/test/CodeGen/AMDGPU/llvm.deoptimize.ll
@@ -1,10 +1,6 @@
-; RUN: not llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 < %s 2> %t.err | FileCheck %s
-; RUN: FileCheck -check-prefix=ERR %s < %t.err
+; RUN: not llc -mtriple=amdgcn-amd-amdhsa -mcpu=gfx900 < %s 2>&1 | FileCheck %s
 
-; ERR: error: <unknown>:0:0: in function caller_0 i32 (): unsupported external symbol
-; ERR: error: unhandled statepoint-like instruction
-
-; CHECK: ;unsupported statepoint/stackmap/patchpoint
+; CHECK: error: no deoptimize libcall available
 declare i32 @llvm.experimental.deoptimize.i32(...)
 declare i8  @llvm.experimental.deoptimize.i8(...)
 

@arsenm arsenm marked this pull request as ready for review December 5, 2025 22:46
Copy link
Contributor

@dantrushin dantrushin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, though I wonder if deoptimize is unavailable, where it comes from then?
(Why it is generated in IR?)

@arsenm
Copy link
Contributor Author

arsenm commented Dec 6, 2025

Looks good, though I wonder if deoptimize is unavailable, where it comes from then? (Why it is generated in IR?)

Nothing is stopping you from writing IR with an intrinsic on it. And nothing may be keeping the optimize libcall alive if it depends on codegen.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend:AMDGPU llvm:SelectionDAG SelectionDAGISel as well

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants