Skip to content

Commit 39f58fb

Browse files
committed
[RISCV] fix SP recovery in varargs functions
1 parent 4a04dd4 commit 39f58fb

File tree

2 files changed

+2
-4
lines changed

2 files changed

+2
-4
lines changed

llvm/lib/Target/RISCV/RISCVFrameLowering.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -809,9 +809,7 @@ void RISCVFrameLowering::emitEpilogue(MachineFunction &MF,
809809
uint64_t StackSize = FirstSPAdjustAmount ? FirstSPAdjustAmount
810810
: getStackSizeWithRVVPadding(MF) -
811811
RVFI->getReservedSpillsSize();
812-
uint64_t FPOffset = FirstSPAdjustAmount ? FirstSPAdjustAmount
813-
: getStackSizeWithRVVPadding(MF) -
814-
RVFI->getVarArgsSaveSize();
812+
uint64_t FPOffset = RealStackSize - RVFI->getVarArgsSaveSize();
815813
uint64_t RVVStackSize = RVFI->getRVVStackSize();
816814

817815
bool RestoreFP = RI->hasStackRealignment(MF) || MFI.hasVarSizedObjects() ||

llvm/test/CodeGen/RISCV/varargs-with-fp-and-second-adj.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ define dso_local void @_Z3fooPKcz(ptr noundef %0, ...) "frame-pointer"="all" {
2828
; RV64V-NEXT: sd a0, -32(s0)
2929
; RV64V-NEXT: addi a0, s0, 8
3030
; RV64V-NEXT: sd a0, -40(s0)
31-
; RV64V-NEXT: addi sp, s0, -496
31+
; RV64V-NEXT: addi sp, s0, -432
3232
; RV64V-NEXT: ld ra, 424(sp) # 8-byte Folded Reload
3333
; RV64V-NEXT: ld s0, 416(sp) # 8-byte Folded Reload
3434
; RV64V-NEXT: addi sp, sp, 496

0 commit comments

Comments
 (0)