[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:49 PDT 2026
================
@@ -0,0 +1,89 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 6
+; RUN: llc -verify-machineinstrs < %s | FileCheck %s
+; RUN: llc -verify-machineinstrs -early-live-intervals < %s | FileCheck %s
+
+; A gc.relocate of a directly-lowered value (a constant or an alloca)
+; in an invoke's landing pad must rematerialize the value at the
+; relocate, not export a vreg defined after the statepoint call in the
+; invoke block.
+
+target triple = "x86_64-pc-linux-gnu"
+
+declare void @foo()
+
+define ptr addrspace(1) @relocate_constant_in_landing_pad() gc "statepoint-example" personality ptr null {
+; CHECK-LABEL: relocate_constant_in_landing_pad:
+; CHECK: # %bb.0: # %entry
+; CHECK-NEXT: pushq %rax
+; CHECK-NEXT: .cfi_def_cfa_offset 16
+; CHECK-NEXT: .Ltmp0: # EH_LABEL
+; CHECK-NEXT: xorl %eax, %eax
+; CHECK-NEXT: xorl %edi, %edi
+; CHECK-NEXT: callq *%rax
+; CHECK-NEXT: .Ltmp3:
+; CHECK-NEXT: .Ltmp1: # EH_LABEL
+; CHECK-NEXT: # %bb.1: # %common.ret
+; CHECK-NEXT: xorl %eax, %eax
+; CHECK-NEXT: popq %rcx
+; CHECK-NEXT: .cfi_def_cfa_offset 8
+; CHECK-NEXT: retq
+; CHECK-NEXT: .LBB0_2: # %exceptional_return
+; CHECK-NEXT: .cfi_def_cfa_offset 16
+; CHECK-NEXT: .Ltmp2: # EH_LABEL
+; CHECK-NEXT: movl $1, %eax
+; CHECK-NEXT: popq %rcx
+; CHECK-NEXT: .cfi_def_cfa_offset 8
+; CHECK-NEXT: retq
+entry:
+ %c = inttoptr i64 1 to ptr addrspace(1)
----------------
kazutakahirata wrote:
May I suggest another test just like this, but with `undef` instead of `1` (`%c = inttoptr i64 undef to ptr addrspace(1)`)?
With the current patch, it fails `-verify-machineinstrs` right after ISel:
```text
*** Bad machine code: Reading virtual register without a def ***
- function: relocate_undef_in_landing_pad
- basic block: %bb.2 exceptional_return
- instruction: $rax = COPY %4:gr64
- operand 1: %4:gr64
```
Because `SDV.isUndef()` is `true` in `LowerAsSTATEPOINT`, `Record.RematLeaf` is skipped and `ExportFromCurrentBlock(V)` is no longer called, so `getValue(DerivedPtr)` in `visitGCRelocate` allocates `%4:gr64` with no definition in `entry`.
https://github.com/llvm/llvm-project/pull/222894
More information about the llvm-commits
mailing list