[llvm] VE: Fix ill-typed setjmp result in emitEHSjLjSetJmp (PR #221549)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Sun Sep 6 02:43:58 PDT 2026


https://github.com/arsenm created https://github.com/llvm/llvm-project/pull/221549

Partially fixes machine verifier failures in existing tests;
they still fail due to other issues.

emitEHSjLjSetJmp materialized the 0/1 return values with LEAzii, which
defines an i64 register, into vregs with the i32 result register class.
This ill-typed MIR is rejected by -verify-machineinstrs.

Materialize the values in i64 and copy the low 32 bits (sub_i32) into the
i32 result. NFC on the emitted code.

Co-authored-by: Claude (Claude-Opus-4.8)

>From f9eced23808ac41154e3465f9ef13cd19a928382 Mon Sep 17 00:00:00 2001
From: Matt Arsenault <Matthew.Arsenault at amd.com>
Date: Sun, 6 Sep 2026 05:25:39 +0200
Subject: [PATCH] VE: Fix ill-typed setjmp result in emitEHSjLjSetJmp

Partially fixes machine verifier failures in existing tests;
they still fail due to other issues.

emitEHSjLjSetJmp materialized the 0/1 return values with LEAzii, which
defines an i64 register, into vregs with the i32 result register class.
This ill-typed MIR is rejected by -verify-machineinstrs.

Materialize the values in i64 and copy the low 32 bits (sub_i32) into the
i32 result. NFC on the emitted code.

Co-authored-by: Claude (Claude-Opus-4.8)
---
 llvm/lib/Target/VE/VEISelLowering.cpp | 17 +++++++++++++----
 1 file changed, 13 insertions(+), 4 deletions(-)

diff --git a/llvm/lib/Target/VE/VEISelLowering.cpp b/llvm/lib/Target/VE/VEISelLowering.cpp
index 1f9173dc481cf..aa8f25e68fd13 100644
--- a/llvm/lib/Target/VE/VEISelLowering.cpp
+++ b/llvm/lib/Target/VE/VEISelLowering.cpp
@@ -2141,8 +2141,13 @@ VETargetLowering::emitEHSjLjSetJmp(MachineInstr &MI,
   const TargetRegisterClass *RC = MRI.getRegClass(DstReg);
   assert(TRI->isTypeLegalForClass(*RC, MVT::i32) && "Invalid destination!");
   (void)TRI;
-  Register MainDestReg = MRI.createVirtualRegister(RC);
-  Register RestoreDestReg = MRI.createVirtualRegister(RC);
+  // The setjmp result is i32, but the 0/1 values are materialized with LEAzii,
+  // which defines a full i64 register. Produce i64 values and take their low
+  // 32 bits for the i32 result.
+  Register MainDestReg = MRI.createVirtualRegister(&VE::I64RegClass);
+  Register RestoreDestReg = MRI.createVirtualRegister(&VE::I64RegClass);
+  Register MainDestReg32 = MRI.createVirtualRegister(RC);
+  Register RestoreDestReg32 = MRI.createVirtualRegister(RC);
 
   // For `v = call @llvm.eh.sjlj.setjmp(buf)`, we generate following
   // instructions.  SP/FP must be saved in jmpbuf before `llvm.eh.sjlj.setjmp`.
@@ -2217,13 +2222,15 @@ VETargetLowering::emitEHSjLjSetJmp(MachineInstr &MI,
       .addImm(0)
       .addImm(0)
       .addImm(0);
+  BuildMI(MainMBB, DL, TII->get(TargetOpcode::COPY), MainDestReg32)
+      .addReg(MainDestReg, RegState::Kill, VE::sub_i32);
   MainMBB->addSuccessor(SinkMBB);
 
   // SinkMBB:
   BuildMI(*SinkMBB, SinkMBB->begin(), DL, TII->get(VE::PHI), DstReg)
-      .addReg(MainDestReg)
+      .addReg(MainDestReg32)
       .addMBB(MainMBB)
-      .addReg(RestoreDestReg)
+      .addReg(RestoreDestReg32)
       .addMBB(RestoreMBB);
 
   // RestoreMBB:
@@ -2242,6 +2249,8 @@ VETargetLowering::emitEHSjLjSetJmp(MachineInstr &MI,
       .addImm(0)
       .addImm(0)
       .addImm(1);
+  BuildMI(RestoreMBB, DL, TII->get(TargetOpcode::COPY), RestoreDestReg32)
+      .addReg(RestoreDestReg, RegState::Kill, VE::sub_i32);
   BuildMI(RestoreMBB, DL, TII->get(VE::BRCFLa_t)).addMBB(SinkMBB);
   RestoreMBB->addSuccessor(SinkMBB);
 



More information about the llvm-commits mailing list