[llvm] [MachineLICM] Recognize registers clobbered at EH landing pad entry (PR #122446)

Sergei Barannikov via llvm-commits llvm-commits at lists.llvm.org
Sat Apr 12 11:51:51 PDT 2025


================
@@ -639,6 +639,21 @@ void MachineLICMImpl::HoistRegionPostRA(MachineLoop *CurLoop,
     if (const uint32_t *Mask = BB->getBeginClobberMask(TRI))
       applyBitsNotInRegMaskToRegUnitsMask(*TRI, RUClobbers, Mask);
 
+    // EH landing pads clobber exception pointer/selector registers
+    if (BB->isEHPad()) {
+      const MachineFunction &MF = *BB->getParent();
+      if (MF.getFunction().hasPersonalityFn()) {
+        auto PersonalityFn = MF.getFunction().getPersonalityFn();
+        const TargetLowering &TLI = *MF.getSubtarget().getTargetLowering();
+        if (unsigned Reg = TLI.getExceptionPointerRegister(PersonalityFn))
+          for (MCRegUnitIterator RUI(Reg, TRI); RUI.isValid(); ++RUI)
+            RUClobbers.set(*RUI);
+        if (unsigned Reg = TLI.getExceptionSelectorRegister(PersonalityFn))
+          for (MCRegUnitIterator RUI(Reg, TRI); RUI.isValid(); ++RUI)
+            RUClobbers.set(*RUI);
+      }
+    }
----------------
s-barannikov wrote:

This should be just
```
    if (BB->isEHPad()) {
      if (const uint32_t *Mask =
              TRI->getCustomEHPadPreservedMask(*BB->getParent()))
        applyBitsNotInRegMaskToRegUnitsMask(*TRI, RUClobbers, Mask);
    }
```

Note however that this only partly addresses the issue. The `continue` at the beginning of the loop is wrong because it results in un-analyzed instructions. If an inner loop had a register def/clobber, it won't be taken into account by the loop over Candidates below.

I've been debugging a similar issue for quite some time now, but I'm struggling to reproduce it on an upstream target =\


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


More information about the llvm-commits mailing list