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

Ulrich Weigand via llvm-commits llvm-commits at lists.llvm.org
Fri Apr 25 08:06:10 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);
+      }
+    }
----------------
uweigand wrote:

Yes, they're already in the live-ins list of the EH landing pad.  But that for loop only adds them to `RUDefs`, which is not sufficient - they need to be added to `RUClobbers`; their values are not inherited from the predecessor block as for a "normal" live-in, but their values are actually clobbered by the EH runtime library, which is not visible to the analysis at this point.

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


More information about the llvm-commits mailing list