[llvm] [X86] Fix RegAlloc issue by implementing TRI::getCustomEHPadPreservedMask (PR #135518)

Sergei Barannikov via llvm-commits llvm-commits at lists.llvm.org
Tue Apr 15 06:46:04 PDT 2025


================
@@ -525,6 +525,13 @@ X86RegisterInfo::getNoPreservedMask() const {
   return CSR_NoRegs_RegMask;
 }
 
+const uint32_t *
+X86RegisterInfo::getCustomEHPadPreservedMask(const MachineFunction &MF) const {
+  if (MF.getTarget().Options.ExceptionModel == ExceptionHandling::SjLj)
----------------
s-barannikov wrote:

Good question! I never thought about supporting SJLJ on Windows, but I think it should be the same there.
Unlike DWARF unwinder, SJLJ implementation does not actually unwind the stack (does not step through frames), it just does "__builtin_longjmp" to the dispatch block. The builtin only restores program counter and stack pointer(s), as that is all that is saved at the beginning of each function that can potentially throw an exception. (Saving all registers at the beginning of each function would be too expensive.)

Also, there is a related [workaround](https://github.com/llvm/llvm-project/blob/07b439605a4cc838a9157f6a948edb0369adeada/llvm/lib/Target/X86/X86ISelLowering.cpp#L37306) that adds the same "no-preserved" mask to an arbitrary instruction in the dispatch block. (It should be removed and any remaining issues fixed in the generic code, but I'm hesitant to do this as test SJLJ test coverage is pretty poor.)


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


More information about the llvm-commits mailing list