[llvm] [RISCV] Adjust max stack-threshold on 64bit systems (PR #208223)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 8 06:48:02 PDT 2026
llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-risc-v
Author: Philipp Rados (prados-oc)
<details>
<summary>Changes</summary>
Shouldn't emit [-Wframe-larger-than] warning on 64-bit systems, when stack-size is greater than UINT32_MAX (the previous default). Update the maximum stack-size-threshold on 64-bit systems to INT64_MAX.
NOTE: GCC has both rv32/rv64 thresholds set to the respective signed maximum unlike LLVM.
---
Full diff: https://github.com/llvm/llvm-project/pull/208223.diff
3 Files Affected:
- (modified) llvm/lib/Target/RISCV/RISCVFrameLowering.cpp (+10)
- (modified) llvm/lib/Target/RISCV/RISCVFrameLowering.h (+2)
- (modified) llvm/test/CodeGen/RISCV/stack-offset-large.ll (+11-1)
``````````diff
diff --git a/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp b/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
index 5c5d081007796..5672ec9f9a4de 100644
--- a/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
@@ -27,6 +27,7 @@
#include "llvm/Support/LEB128.h"
#include <algorithm>
+#include <cstdint>
#define DEBUG_TYPE "riscv-frame"
@@ -2722,3 +2723,12 @@ Register
RISCVFrameLowering::getInitialCFARegister(const MachineFunction &MF) const {
return RISCV::X2;
}
+
+// On 64-bit systems the fixed stack can hold INT64_MAX bytes, since
+// stack-offset calculation is done in 2s-complement.
+// NOTE: In theory a register can hold any 64-bit number, so this constraint
+// might be relaxed to UINT64_MAX in the future, if anyone actually needs
+// that.
+uint64_t RISCVFrameLowering::getStackThreshold() const {
+ return STI.is64Bit() ? INT64_MAX : UINT32_MAX;
+}
diff --git a/llvm/lib/Target/RISCV/RISCVFrameLowering.h b/llvm/lib/Target/RISCV/RISCVFrameLowering.h
index 496af9b9fd9cc..d79e402e13fbc 100644
--- a/llvm/lib/Target/RISCV/RISCVFrameLowering.h
+++ b/llvm/lib/Target/RISCV/RISCVFrameLowering.h
@@ -86,6 +86,8 @@ class RISCVFrameLowering : public TargetFrameLowering {
uint64_t ProbeSize, bool DynAllocation,
MachineInstr::MIFlag Flag) const;
+ uint64_t getStackThreshold() const override;
+
protected:
const RISCVSubtarget &STI;
diff --git a/llvm/test/CodeGen/RISCV/stack-offset-large.ll b/llvm/test/CodeGen/RISCV/stack-offset-large.ll
index ed422d1fa76d9..958071b3655f9 100644
--- a/llvm/test/CodeGen/RISCV/stack-offset-large.ll
+++ b/llvm/test/CodeGen/RISCV/stack-offset-large.ll
@@ -1,7 +1,7 @@
; NOTE: Assertions have been autogenerated by utils/update_llc_test_checks.py UTC_ARGS: --version 6
; RUN: not llc -mtriple=riscv32 -mattr=+v -verify-machineinstrs < %s 2>&1 \
; RUN: | FileCheck %s -check-prefixes=RV32
-; RUN: llc -mtriple=riscv64 -mattr=+v -verify-machineinstrs < %s \
+; RUN: llc -mtriple=riscv64 -mattr=+v -verify-machineinstrs < %s 2>&1 \
; RUN: | FileCheck %s -check-prefixes=RV64
declare void @inspect(...)
@@ -11,6 +11,9 @@ declare void @inspect(...)
; Should fail on 32-bit systems.
; RV32: LLVM ERROR: Frame offsets outside of the signed 32-bit range not supported on RV32
+; RV64-NOT: warning: {{.*}} stack frame size ({{.*}}) exceeds limit (9223372036854775807) in function 'stack_bigger_than_32bit'
+; RV64: warning: {{.*}} stack frame size ({{.*}}) exceeds limit (9223372036854775807) in function 'stack_larger_than_signed_64bit_warning'
+
define void @stack_bigger_than_32bit() {
; RV64-LABEL: stack_bigger_than_32bit:
; RV64: # %bb.0:
@@ -190,3 +193,10 @@ define <vscale x 1 x i64> @rvv_spill(<vscale x 1 x i64> %vector) {
call void (...) @inspect(ptr %p1, ptr %p2)
ret <vscale x 1 x i64> %vector
}
+
+define void @stack_larger_than_signed_64bit_warning() {
+ %p1 = alloca [2 x i8], align 1
+ %p2 = alloca [9223372036854775807 x i8], align 1
+ call void (...) @inspect(ptr %p1, ptr %p2)
+ ret void
+}
``````````
</details>
https://github.com/llvm/llvm-project/pull/208223
More information about the llvm-commits
mailing list