[llvm] [AArch64][SME] Fix restoring callee-saves from FP with hazard padding (PR #143371)
Sander de Smalen via llvm-commits
llvm-commits at lists.llvm.org
Mon Jun 16 04:00:20 PDT 2025
================
@@ -2535,27 +2535,69 @@ void AArch64FrameLowering::emitEpilogue(MachineFunction &MF,
DeallocateAfter, TII, MachineInstr::FrameDestroy, false,
NeedsWinCFI, &HasWinCFI);
} else if (SVEStackSize) {
- // If we have stack realignment or variable sized objects on the stack,
- // restore the stack pointer from the frame pointer prior to SVE CSR
- // restoration.
- if (AFI->isStackRealigned() || MFI.hasVarSizedObjects()) {
- if (int64_t CalleeSavedSize = AFI->getSVECalleeSavedStackSize()) {
- // Set SP to start of SVE callee-save area from which they can
- // be reloaded. The code below will deallocate the stack space
- // space by moving FP -> SP.
- emitFrameOffset(MBB, RestoreBegin, DL, AArch64::SP, AArch64::FP,
- StackOffset::getScalable(-CalleeSavedSize), TII,
----------------
sdesmalen-arm wrote:
You mentioned offline that it may not make sense to update `emitFrameOffset` because it is specifically an issue when deallocating stack space (and not when allocating), so I agree that this not something that can be fixed in that function.
I did realise that the register scavenger runs after PEI/FrameLowering meaning that you can use virtual registers which will get allocated aftewards. That makes things simpler and means you could instead write:
```
if (int64_t HazardSize = getStackHazardSize(MF)) {
Register TmpReg = MBB.getParent()->getRegInfo().createVirtualRegister(
&AArch64::GPR64RegClass);
emitFrameOffset(MBB, RestoreBegin, DL, TmpReg, AArch64::FP,
StackOffset::getFixed(-HazardSize),
TII, MachineInstr::FrameDestroy);
emitFrameOffset(MBB, RestoreBegin, DL, AArch64::SP, TmpReg,
StackOffset::getScalable(-CalleeSavedSize), TII,
MachineInstr::FrameDestroy);
} else {
// Set SP to start of SVE callee-save area from which they can
// be reloaded. The code below will deallocate the stack space
// space by moving FP -> SP.
emitFrameOffset(MBB, RestoreBegin, DL, AArch64::SP, AArch64::FP,
StackOffset::getScalable(-CalleeSavedSize), TII,
MachineInstr::FrameDestroy);
}
```
https://github.com/llvm/llvm-project/pull/143371
More information about the llvm-commits
mailing list