diff --git a/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp b/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp index e0abc2d812ccfc..30131862c11455 100644 --- a/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp +++ b/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp @@ -872,9 +872,7 @@ void RISCVFrameLowering::emitEpilogue(MachineFunction &MF, uint64_t StackSize = FirstSPAdjustAmount ? FirstSPAdjustAmount : getStackSizeWithRVVPadding(MF) - RVFI->getReservedSpillsSize(); - uint64_t FPOffset = FirstSPAdjustAmount ? FirstSPAdjustAmount - : getStackSizeWithRVVPadding(MF) - - RVFI->getVarArgsSaveSize(); + uint64_t FPOffset = RealStackSize - RVFI->getVarArgsSaveSize(); uint64_t RVVStackSize = RVFI->getRVVStackSize(); bool RestoreSPFromFP = RI->hasStackRealignment(MF) || diff --git a/llvm/test/CodeGen/RISCV/varargs-with-fp-and-second-adj.ll b/llvm/test/CodeGen/RISCV/varargs-with-fp-and-second-adj.ll index 94c2a8d5a73316..73d3827b84758a 100644 --- a/llvm/test/CodeGen/RISCV/varargs-with-fp-and-second-adj.ll +++ b/llvm/test/CodeGen/RISCV/varargs-with-fp-and-second-adj.ll @@ -28,7 +28,7 @@ define dso_local void @_Z3fooPKcz(ptr noundef %0, ...) "frame-pointer"="all" { ; RV64V-NEXT: sd a0, -32(s0) ; RV64V-NEXT: addi a0, s0, 8 ; RV64V-NEXT: sd a0, -40(s0) -; RV64V-NEXT: addi sp, s0, -496 +; RV64V-NEXT: addi sp, s0, -432 ; RV64V-NEXT: .cfi_def_cfa sp, 496 ; RV64V-NEXT: ld ra, 424(sp) # 8-byte Folded Reload ; RV64V-NEXT: ld s0, 416(sp) # 8-byte Folded Reload