[llvm] DAG: Fix latent verifier error in statepoint lowering (PR #222894)

Kazu Hirata via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 21 22:46:50 PDT 2026


================
@@ -931,18 +954,19 @@ SDValue SelectionDAGBuilder::LowerAsSTATEPOINT(
       Record.payload.FI = cast<FrameIndexSDNode>(Loc)->getIndex();
     } else {
       Record.type = RecordType::NoRelocate;
-      // If we didn't relocate a value, we'll essentialy end up inserting an
-      // additional use of the original value when lowering the gc.relocate.
-      // We need to make sure the value is available at the new use, which
-      // might be in another block.
-      if (Relocate->getParent() != StatepointInstr->getParent())
-        ExportFromCurrentBlock(V);
+      assert(willLowerDirectly(SDV) && "NoRelocate value must lower directly");
+
+      // A gc.relocate in another block needs the value there. Exporting it
+      // would define a vreg after the call that does not dominate a use on the
+      // unwind edge, so record the leaf and rebuild it in visitGCRelocate
+      // instead. undef re-lowers trivially and is left to the fallback path.
+      if (Relocate->getParent() != StatepointInstr->getParent() &&
+          !SDV.isUndef())
----------------
kazutakahirata wrote:

May I suggest dropping `&& !SDV.isUndef()` here and handling `V.isUndef()` in `StatepointDirectLeaf`? Otherwise, if `V` is an instruction that lowers to `undef` (e.g., `%c = inttoptr i64 undef to ptr addrspace(1)`), `getValue(DerivedPtr)` in `visitGCRelocate` would allocate a new vreg with no def.

https://github.com/llvm/llvm-project/pull/222894


More information about the llvm-commits mailing list