[llvm] [AArch64][SME] Fix restoring callee-saves from FP with hazard padding (PR #143371)
Benjamin Maxwell via llvm-commits
llvm-commits at lists.llvm.org
Sat Jun 14 03:47:08 PDT 2025
================
@@ -2535,24 +2535,70 @@ 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,
+ const AArch64RegisterInfo *RegInfo = Subtarget.getRegisterInfo();
+ int64_t SVECalleeSavedSize = AFI->getSVECalleeSavedStackSize();
+ Register BaseForSVEDealloc = [&]() -> Register {
+ // With stack realignment we must use the FP to restore SVE CSRs (as both
+ // the SP and BP can't be used due to the unknown alignment padding).
+ if (AFI->isStackRealigned())
+ return AArch64::FP;
+ // With variable sized objects on the stack, we can use the BP or FP to
+ // restore the SVE callee saves.
+ if (MFI.hasVarSizedObjects()) {
+ if (DeallocateBefore && !AFI->hasStackHazardSlotIndex()) {
+ // If there's SVE locals and no hazard padding we can do:
+ // ADDVL SP, FP, #(-SVECalleeSavedSize)
+ return AArch64::FP;
+ }
+ // Otherwise, we can choose between:
+ // SUB TMP, FP, #(-CalleeSaveBaseOffset)
----------------
MacDue wrote:
```suggestion
// SUB TMP, FP, #CalleeSaveBaseOffset
```
https://github.com/llvm/llvm-project/pull/143371
More information about the llvm-commits
mailing list