@@ -2541,13 +2541,33 @@ void AArch64FrameLowering::emitEpilogue(MachineFunction &MF,
2541
2541
if (AFI->isStackRealigned () || MFI.hasVarSizedObjects ()) {
2542
2542
if (int64_t SVECalleeSavedSize = AFI->getSVECalleeSavedStackSize ()) {
2543
2543
// Set SP to start of SVE callee-save area from which they can
2544
- // be reloaded. The code below will deallocate the stack space
2545
- // space by moving FP -> SP.
2546
- emitFrameOffset (
2547
- MBB, RestoreBegin, DL, AArch64::SP, AArch64::FP,
2548
- StackOffset::get (-AFI->getCalleeSaveBaseToFrameRecordOffset (),
2549
- -SVECalleeSavedSize),
2550
- TII, MachineInstr::FrameDestroy);
2544
+ // be reloaded.
2545
+ const AArch64RegisterInfo *RegInfo = Subtarget.getRegisterInfo ();
2546
+ if (!AFI->isStackRealigned () && RegInfo->hasBasePointer (MF)) {
2547
+ // If the stack is not realigned we can use the base pointer to find
2548
+ // the start of the SVE callee-saves.
2549
+ emitFrameOffset (
2550
+ MBB, RestoreBegin, DL, AArch64::SP, RegInfo->getBaseRegister (),
2551
+ StackOffset::getFixed (NumBytes), TII, MachineInstr::FrameDestroy);
2552
+ } else {
2553
+ Register CalleeSaveBase = AArch64::FP;
2554
+ if (int64_t CalleeSaveBaseOffset =
2555
+ AFI->getCalleeSaveBaseToFrameRecordOffset ()) {
2556
+ assert (RegInfo->hasBasePointer (MF) && " Expected base pointer!" );
2557
+ // NOTE: This base pointer is clobbered from this point on! The next
2558
+ // step in eplilogue emission restoring callee-saves, so it should
2559
+ // not be used after this point anyway.
2560
+ CalleeSaveBase = RegInfo->getBaseRegister ();
2561
+ emitFrameOffset (MBB, RestoreBegin, DL, CalleeSaveBase, AArch64::FP,
2562
+ StackOffset::getFixed (-CalleeSaveBaseOffset), TII,
2563
+ MachineInstr::FrameDestroy);
2564
+ }
2565
+ // The code below will deallocate the stack space space by moving FP
2566
+ // -> SP.
2567
+ emitFrameOffset (MBB, RestoreBegin, DL, AArch64::SP, CalleeSaveBase,
2568
+ StackOffset::getScalable (-SVECalleeSavedSize), TII,
2569
+ MachineInstr::FrameDestroy);
2570
+ }
2551
2571
}
2552
2572
} else {
2553
2573
if (AFI->getSVECalleeSavedStackSize ()) {
0 commit comments