[RISCV] Adjust max stack-threshold on 64bit systems (#208223)
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.
diff --git a/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp b/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
index 5c5d081..5672ec9f 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 @@
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 496af9b..d79e402 100644
--- a/llvm/lib/Target/RISCV/RISCVFrameLowering.h
+++ b/llvm/lib/Target/RISCV/RISCVFrameLowering.h
@@ -86,6 +86,8 @@
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 ed422d1..958071b 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 @@
; 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 @@
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
+}