[llvm] [RISCV] fix SP recovery in varargs functions (PR #114316)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Oct 30 16:58:10 PDT 2024
https://github.com/dlav-sc updated https://github.com/llvm/llvm-project/pull/114316
>From 039e64837ba1a8d52af272732fcb9a65182977f7 Mon Sep 17 00:00:00 2001
From: Daniil Avdeev <daniil.avdeev at syntacore.com>
Date: Wed, 30 Oct 2024 23:56:00 +0000
Subject: [PATCH 1/3] [RISCV] add varargs SP recovery test
---
llvm/test/CodeGen/RISCV/pr114316.ll | 46 +++++++++++++++++++++++++++++
1 file changed, 46 insertions(+)
create mode 100644 llvm/test/CodeGen/RISCV/pr114316.ll
diff --git a/llvm/test/CodeGen/RISCV/pr114316.ll b/llvm/test/CodeGen/RISCV/pr114316.ll
new file mode 100644
index 00000000000000..b350ceeee22d1b
--- /dev/null
+++ b/llvm/test/CodeGen/RISCV/pr114316.ll
@@ -0,0 +1,46 @@
+; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 5
+; RUN: llc -mtriple=riscv64 -mattr=+m,+c,+v < %s | FileCheck --check-prefix=RV64V %s
+
+declare void @llvm.va_copy.p0(ptr, ptr)
+declare void @llvm.va_end.p0(ptr)
+
+define dso_local void @_Z3fooPKcz(ptr noundef %0, ...) "frame-pointer"="all" {
+; RV64V-LABEL: _Z3fooPKcz:
+; RV64V: # %bb.0:
+; RV64V-NEXT: addi sp, sp, -496
+; RV64V-NEXT: .cfi_def_cfa_offset 496
+; RV64V-NEXT: sd ra, 424(sp) # 8-byte Folded Spill
+; RV64V-NEXT: sd s0, 416(sp) # 8-byte Folded Spill
+; RV64V-NEXT: .cfi_offset ra, -72
+; RV64V-NEXT: .cfi_offset s0, -80
+; RV64V-NEXT: addi s0, sp, 432
+; RV64V-NEXT: .cfi_def_cfa s0, 64
+; RV64V-NEXT: lui t0, 2
+; RV64V-NEXT: addiw t0, t0, -576
+; RV64V-NEXT: sub sp, sp, t0
+; RV64V-NEXT: sd a5, 40(s0)
+; RV64V-NEXT: sd a6, 48(s0)
+; RV64V-NEXT: sd a7, 56(s0)
+; RV64V-NEXT: sd a1, 8(s0)
+; RV64V-NEXT: sd a2, 16(s0)
+; RV64V-NEXT: sd a3, 24(s0)
+; RV64V-NEXT: sd a4, 32(s0)
+; 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: ld ra, 424(sp) # 8-byte Folded Reload
+; RV64V-NEXT: ld s0, 416(sp) # 8-byte Folded Reload
+; RV64V-NEXT: addi sp, sp, 496
+; RV64V-NEXT: ret
+ %2 = alloca ptr, align 8
+ %3 = alloca ptr, align 8
+ %4 = alloca [8000 x i8], align 1
+ store ptr %0, ptr %2, align 8
+ call void @llvm.va_start.p0(ptr %3)
+ %5 = getelementptr inbounds [8000 x i8], ptr %4, i64 0, i64 0
+ %6 = load ptr, ptr %2, align 8
+ %7 = load ptr, ptr %3, align 8
+ call void @llvm.va_end.p0(ptr %3)
+ ret void
+}
>From 0bd9da1659f92e0a413af836c7d9d03ec9b1d054 Mon Sep 17 00:00:00 2001
From: Daniil Avdeev <daniil.avdeev at syntacore.com>
Date: Wed, 30 Oct 2024 21:07:49 +0000
Subject: [PATCH 2/3] [RISCV] fix SP recovery in varargs functions
---
llvm/lib/Target/RISCV/RISCVFrameLowering.cpp | 4 +---
1 file changed, 1 insertion(+), 3 deletions(-)
diff --git a/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp b/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
index f5851f37154519..2ff78ce9ea9c65 100644
--- a/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
@@ -809,9 +809,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 RestoreFP = RI->hasStackRealignment(MF) || MFI.hasVarSizedObjects() ||
>From e48208c430fd5e96976688104fb99b59ee1c5f91 Mon Sep 17 00:00:00 2001
From: Daniil Avdeev <daniil.avdeev at syntacore.com>
Date: Wed, 30 Oct 2024 23:57:31 +0000
Subject: [PATCH 3/3] [RISCV] update test
---
llvm/test/CodeGen/RISCV/pr114316.ll | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/llvm/test/CodeGen/RISCV/pr114316.ll b/llvm/test/CodeGen/RISCV/pr114316.ll
index b350ceeee22d1b..0bc77cbef5b5a0 100644
--- a/llvm/test/CodeGen/RISCV/pr114316.ll
+++ b/llvm/test/CodeGen/RISCV/pr114316.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: ld ra, 424(sp) # 8-byte Folded Reload
; RV64V-NEXT: ld s0, 416(sp) # 8-byte Folded Reload
; RV64V-NEXT: addi sp, sp, 496
More information about the llvm-commits
mailing list