Skip to content

Commit 5d2c4df

Browse files
committed
[RISCV] fix SP recovery in varargs functions
1 parent fedb9fd commit 5d2c4df

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
@@ -872,9 +872,7 @@ void RISCVFrameLowering::emitEpilogue(MachineFunction &MF,
872872
uint64_t StackSize = FirstSPAdjustAmount ? FirstSPAdjustAmount
873873
: getStackSizeWithRVVPadding(MF) -
874874
RVFI->getReservedSpillsSize();
875-
uint64_t FPOffset = FirstSPAdjustAmount ? FirstSPAdjustAmount
876-
: getStackSizeWithRVVPadding(MF) -
877-
RVFI->getVarArgsSaveSize();
875+
uint64_t FPOffset = RealStackSize - RVFI->getVarArgsSaveSize();
878876
uint64_t RVVStackSize = RVFI->getRVVStackSize();
879877

880878
bool RestoreSPFromFP = RI->hasStackRealignment(MF) ||

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: .cfi_def_cfa sp, 496
3333
; RV64V-NEXT: ld ra, 424(sp) # 8-byte Folded Reload
3434
; RV64V-NEXT: ld s0, 416(sp) # 8-byte Folded Reload

0 commit comments

Comments
 (0)