@@ -822,15 +822,16 @@ void RISCVFrameLowering::emitEpilogue(MachineFunction &MF,
822822 RVFI->getVarArgsSaveSize ();
823823 uint64_t RVVStackSize = RVFI->getRVVStackSize ();
824824
825- bool RestoreFP = RI->hasStackRealignment (MF) || MFI. hasVarSizedObjects ( ) ||
826- !hasReservedCallFrame (MF);
825+ bool RestoreSPFromFP = RI->hasStackRealignment (MF) ||
826+ MFI. hasVarSizedObjects () || !hasReservedCallFrame (MF);
827827 if (RVVStackSize) {
828- // If RestoreFP the stack pointer will be restored using the frame pointer
829- // value.
830- if (!RestoreFP) {
828+ // If RestoreSPFromFP the stack pointer will be restored using the frame
829+ // pointer value.
830+ if (!RestoreSPFromFP)
831831 adjustStackForRVV (MF, MBB, LastFrameDestroy, DL, RVVStackSize,
832832 MachineInstr::FrameDestroy);
833833
834+ if (!hasFP (MF)) {
834835 unsigned CFIIndex = MF.addFrameInst (MCCFIInstruction::cfiDefCfa (
835836 nullptr , RI->getDwarfRegNum (SPReg, true ), RealStackSize));
836837 BuildMI (MBB, LastFrameDestroy, DL,
@@ -848,13 +849,14 @@ void RISCVFrameLowering::emitEpilogue(MachineFunction &MF,
848849 assert (SecondSPAdjustAmount > 0 &&
849850 " SecondSPAdjustAmount should be greater than zero" );
850851
851- // If RestoreFP the stack pointer will be restored using the frame pointer
852- // value.
853- if (!RestoreFP) {
852+ // If RestoreSPFromFP the stack pointer will be restored using the frame
853+ // pointer value.
854+ if (!RestoreSPFromFP)
854855 RI->adjustReg (MBB, LastFrameDestroy, DL, SPReg, SPReg,
855856 StackOffset::getFixed (SecondSPAdjustAmount),
856857 MachineInstr::FrameDestroy, getStackAlign ());
857858
859+ if (!hasFP (MF)) {
858860 unsigned CFIIndex = MF.addFrameInst (
859861 MCCFIInstruction::cfiDefCfaOffset (nullptr , FirstSPAdjustAmount));
860862 BuildMI (MBB, LastFrameDestroy, DL,
@@ -874,13 +876,15 @@ void RISCVFrameLowering::emitEpilogue(MachineFunction &MF,
874876 // normally it's just checking the variable sized object is present or not
875877 // is enough, but we also don't preserve that at prologue/epilogue when
876878 // have vector objects in stack.
877- if (RestoreFP ) {
879+ if (RestoreSPFromFP ) {
878880 assert (hasFP (MF) && " frame pointer should not have been eliminated" );
879881
880882 RI->adjustReg (MBB, LastFrameDestroy, DL, SPReg, FPReg,
881883 StackOffset::getFixed (-FPOffset), MachineInstr::FrameDestroy,
882884 getStackAlign ());
885+ }
883886
887+ if (hasFP (MF)) {
884888 unsigned CFIIndex = MF.addFrameInst (MCCFIInstruction::cfiDefCfa (
885889 nullptr , RI->getDwarfRegNum (SPReg, true ), RealStackSize));
886890 BuildMI (MBB, LastFrameDestroy, DL, TII->get (TargetOpcode::CFI_INSTRUCTION))
0 commit comments