@@ -2535,43 +2535,14 @@ void AArch64FrameLowering::emitEpilogue(MachineFunction &MF,
25352535 DeallocateAfter, TII, MachineInstr::FrameDestroy, false ,
25362536 NeedsWinCFI, &HasWinCFI);
25372537 } else if (SVEStackSize) {
2538- const AArch64RegisterInfo *RegInfo = Subtarget.getRegisterInfo ();
25392538 int64_t SVECalleeSavedSize = AFI->getSVECalleeSavedStackSize ();
2540- Register BaseForSVEDealloc = [&]() -> Register {
2541- // With stack realignment we must use the FP to restore SVE CSRs (as both
2542- // the SP and BP can't be used due to the unknown alignment padding).
2543- if (AFI->isStackRealigned ())
2544- return AArch64::FP;
2545- // With variable sized objects on the stack, we can use the BP or FP to
2546- // restore the SVE callee saves.
2547- if (MFI.hasVarSizedObjects ()) {
2548- if (DeallocateBefore && !AFI->hasStackHazardSlotIndex ()) {
2549- // If there's SVE locals and no hazard padding we can do:
2550- // ADDVL SP, FP, #(-SVECalleeSavedSize)
2551- return AArch64::FP;
2552- }
2553- // Otherwise, we can choose between:
2554- // SUB TMP, FP, #CalleeSaveBaseOffset
2555- // ADDVL SP, TMP, #(-SVECalleeSavedSize)
2556- // OR:
2557- // ADD SP, BP, #NumBytes
2558- // ADDVL SP, SP, #DeallocateBefore
2559- // Here we choose the latter as the "ADDVL" can be omitted if there's no
2560- // SVE locals (and if we're here we either don't have SVE locals or have
2561- // hazard padding).
2562- assert (RegInfo->hasBasePointer (MF) && " Expected base pointer!" );
2563- return RegInfo->getBaseRegister ();
2564- }
2565- // In the standard case we use the SP.
2566- return AArch64::SP;
2567- }();
2568- // If we have any SVE callee saves they must be restored now.
2569- bool MustRestoreSVECalleeSaves = SVECalleeSavedSize != 0 ;
2570- // If the base for deallocation is the SP we must deallocate the SVE area
2571- // regardless of if we have SVE callee saves. For any other base the SVE
2572- // area will be implicitly deallocated when we set the SP to the FP.
2573- bool MustDeallocateSVEArea = BaseForSVEDealloc == AArch64::SP;
2574- if (MustRestoreSVECalleeSaves && BaseForSVEDealloc == AArch64::FP) {
2539+ // If we have stack realignment or variable-sized objects we must use the
2540+ // FP to restore SVE callee saves (as there is an unknown amount of
2541+ // data/padding between the SP and SVE CS area).
2542+ Register BaseForSVEDealloc =
2543+ AFI->isStackRealigned () || MFI.hasVarSizedObjects () ? AArch64::FP
2544+ : AArch64::SP;
2545+ if (SVECalleeSavedSize && BaseForSVEDealloc == AArch64::FP) {
25752546 Register CalleeSaveBase = AArch64::FP;
25762547 if (int64_t CalleeSaveBaseOffset =
25772548 AFI->getCalleeSaveBaseToFrameRecordOffset ()) {
@@ -2589,12 +2560,12 @@ void AArch64FrameLowering::emitEpilogue(MachineFunction &MF,
25892560 emitFrameOffset (MBB, RestoreBegin, DL, AArch64::SP, CalleeSaveBase,
25902561 StackOffset::getScalable (-SVECalleeSavedSize), TII,
25912562 MachineInstr::FrameDestroy);
2592- } else if (MustRestoreSVECalleeSaves || MustDeallocateSVEArea ) {
2563+ } else if (BaseForSVEDealloc == AArch64::SP ) {
25932564 if (SVECalleeSavedSize) {
25942565 // Deallocate the non-SVE locals first before we can deallocate (and
25952566 // restore callee saves) from the SVE area.
25962567 emitFrameOffset (
2597- MBB, RestoreBegin, DL, AArch64::SP, BaseForSVEDealloc ,
2568+ MBB, RestoreBegin, DL, AArch64::SP, AArch64::SP ,
25982569 StackOffset::getFixed (NumBytes), TII, MachineInstr::FrameDestroy,
25992570 false , NeedsWinCFI, &HasWinCFI, EmitCFI && !hasFP (MF),
26002571 SVEStackSize + StackOffset::getFixed (NumBytes + PrologueSaveSize));
@@ -2607,13 +2578,11 @@ void AArch64FrameLowering::emitEpilogue(MachineFunction &MF,
26072578 SVEStackSize +
26082579 StackOffset::getFixed (NumBytes + PrologueSaveSize));
26092580
2610- if (MustDeallocateSVEArea) {
2611- emitFrameOffset (MBB, RestoreEnd, DL, AArch64::SP, AArch64::SP,
2612- DeallocateAfter, TII, MachineInstr::FrameDestroy, false ,
2613- NeedsWinCFI, &HasWinCFI, EmitCFI && !hasFP (MF),
2614- DeallocateAfter +
2615- StackOffset::getFixed (NumBytes + PrologueSaveSize));
2616- }
2581+ emitFrameOffset (MBB, RestoreEnd, DL, AArch64::SP, AArch64::SP,
2582+ DeallocateAfter, TII, MachineInstr::FrameDestroy, false ,
2583+ NeedsWinCFI, &HasWinCFI, EmitCFI && !hasFP (MF),
2584+ DeallocateAfter +
2585+ StackOffset::getFixed (NumBytes + PrologueSaveSize));
26172586 }
26182587 if (EmitCFI)
26192588 emitCalleeSavedSVERestores (MBB, RestoreEnd);
0 commit comments