[llvm] 253db65 - VE: Fix ill-typed setjmp result in emitEHSjLjSetJmp (#221549)
via llvm-commits
llvm-commits at lists.llvm.org
Mon Oct 5 01:41:19 PDT 2026
Author: Matt Arsenault
Date: 2026-10-05T10:41:11+02:00
New Revision: 253db65c295d52a80e7903d116bce8354cb219a0
URL: https://github.com/llvm/llvm-project/commit/253db65c295d52a80e7903d116bce8354cb219a0
DIFF: https://github.com/llvm/llvm-project/commit/253db65c295d52a80e7903d116bce8354cb219a0.diff
LOG: VE: Fix ill-typed setjmp result in emitEHSjLjSetJmp (#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)
Added:
Modified:
llvm/lib/Target/VE/VEISelLowering.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Target/VE/VEISelLowering.cpp b/llvm/lib/Target/VE/VEISelLowering.cpp
index 0d60fb036b28c..1a64f1aacc9b8 100644
--- a/llvm/lib/Target/VE/VEISelLowering.cpp
+++ b/llvm/lib/Target/VE/VEISelLowering.cpp
@@ -2140,8 +2140,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`.
@@ -2216,13 +2221,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:
@@ -2241,6 +2248,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