Skip to content

Commit 70319b8

Browse files
committed
[RISCV][CFI] fix CFA in some tests with FP
1 parent 1fd6796 commit 70319b8

File tree

1 file changed

+13
-9
lines changed

1 file changed

+13
-9
lines changed

llvm/lib/Target/RISCV/RISCVFrameLowering.cpp

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -825,15 +825,16 @@ void RISCVFrameLowering::emitEpilogue(MachineFunction &MF,
825825
RVFI->getVarArgsSaveSize();
826826
uint64_t RVVStackSize = RVFI->getRVVStackSize();
827827

828-
bool RestoreFP = RI->hasStackRealignment(MF) || MFI.hasVarSizedObjects() ||
829-
!hasReservedCallFrame(MF);
828+
bool RestoreSPFromFP = RI->hasStackRealignment(MF) ||
829+
MFI.hasVarSizedObjects() || !hasReservedCallFrame(MF);
830830
if (RVVStackSize) {
831-
// If RestoreFP the stack pointer will be restored using the frame pointer
832-
// value.
833-
if (!RestoreFP) {
831+
// If RestoreSPFromFP the stack pointer will be restored using the frame
832+
// pointer value.
833+
if (!RestoreSPFromFP)
834834
adjustStackForRVV(MF, MBB, LastFrameDestroy, DL, RVVStackSize,
835835
MachineInstr::FrameDestroy);
836836

837+
if (!hasFP(MF)) {
837838
unsigned CFIIndex = MF.addFrameInst(MCCFIInstruction::cfiDefCfa(
838839
nullptr, RI->getDwarfRegNum(SPReg, true), RealStackSize));
839840
BuildMI(MBB, LastFrameDestroy, DL,
@@ -851,13 +852,14 @@ void RISCVFrameLowering::emitEpilogue(MachineFunction &MF,
851852
assert(SecondSPAdjustAmount > 0 &&
852853
"SecondSPAdjustAmount should be greater than zero");
853854

854-
// If RestoreFP the stack pointer will be restored using the frame pointer
855-
// value.
856-
if (!RestoreFP) {
855+
// If RestoreSPFromFP the stack pointer will be restored using the frame
856+
// pointer value.
857+
if (!RestoreSPFromFP)
857858
RI->adjustReg(MBB, LastFrameDestroy, DL, SPReg, SPReg,
858859
StackOffset::getFixed(SecondSPAdjustAmount),
859860
MachineInstr::FrameDestroy, getStackAlign());
860861

862+
if (!hasFP(MF)) {
861863
unsigned CFIIndex = MF.addFrameInst(
862864
MCCFIInstruction::cfiDefCfaOffset(nullptr, FirstSPAdjustAmount));
863865
BuildMI(MBB, LastFrameDestroy, DL,
@@ -877,13 +879,15 @@ void RISCVFrameLowering::emitEpilogue(MachineFunction &MF,
877879
// normally it's just checking the variable sized object is present or not
878880
// is enough, but we also don't preserve that at prologue/epilogue when
879881
// have vector objects in stack.
880-
if (RestoreFP) {
882+
if (RestoreSPFromFP) {
881883
assert(hasFP(MF) && "frame pointer should not have been eliminated");
882884

883885
RI->adjustReg(MBB, LastFrameDestroy, DL, SPReg, FPReg,
884886
StackOffset::getFixed(-FPOffset), MachineInstr::FrameDestroy,
885887
getStackAlign());
888+
}
886889

890+
if (hasFP(MF)) {
887891
unsigned CFIIndex = MF.addFrameInst(MCCFIInstruction::cfiDefCfa(
888892
nullptr, RI->getDwarfRegNum(SPReg, true), RealStackSize));
889893
BuildMI(MBB, LastFrameDestroy, DL, TII->get(TargetOpcode::CFI_INSTRUCTION))

0 commit comments

Comments
 (0)