[llvm] [PEI][PowerPC] Fix false alarm of stack size limit (PR #65559)
via llvm-commits
llvm-commits at lists.llvm.org
Wed Sep 6 22:14:42 PDT 2023
https://github.com/bzEq updated https://github.com/llvm/llvm-project/pull/65559:
>From 9e1899daa873ba62acc1d81e7f7b60bd454a6e36 Mon Sep 17 00:00:00 2001
From: Kai Luo <lkail at cn.ibm.com>
Date: Thu, 7 Sep 2023 02:39:14 +0000
Subject: [PATCH 1/4] Override stack threshold
---
.../include/llvm/CodeGen/TargetFrameLowering.h | 4 ++++
llvm/lib/CodeGen/PrologEpilogInserter.cpp | 2 +-
llvm/lib/Target/PowerPC/PPCFrameLowering.cpp | 7 +++++++
llvm/lib/Target/PowerPC/PPCFrameLowering.h | 2 ++
llvm/test/CodeGen/PowerPC/warn-on-size.ll | 18 ++++++++++++++++++
5 files changed, 32 insertions(+), 1 deletion(-)
create mode 100644 llvm/test/CodeGen/PowerPC/warn-on-size.ll
diff --git a/llvm/include/llvm/CodeGen/TargetFrameLowering.h b/llvm/include/llvm/CodeGen/TargetFrameLowering.h
index 94de30461547e9d..35551d45af43abe 100644
--- a/llvm/include/llvm/CodeGen/TargetFrameLowering.h
+++ b/llvm/include/llvm/CodeGen/TargetFrameLowering.h
@@ -102,6 +102,10 @@ class TargetFrameLowering {
///
Align getStackAlign() const { return StackAlignment; }
+ /// getStackThreshold - Return the maximum stack size
+ ///
+ virtual uint64_t getStackThreshold() const { return UINT_MAX; }
+
/// alignSPAdjust - This method aligns the stack adjustment to the correct
/// alignment.
///
diff --git a/llvm/lib/CodeGen/PrologEpilogInserter.cpp b/llvm/lib/CodeGen/PrologEpilogInserter.cpp
index fe88a360e832f31..6c8be5cff75360e 100644
--- a/llvm/lib/CodeGen/PrologEpilogInserter.cpp
+++ b/llvm/lib/CodeGen/PrologEpilogInserter.cpp
@@ -293,7 +293,7 @@ bool PEI::runOnMachineFunction(MachineFunction &MF) {
MachineFrameInfo &MFI = MF.getFrameInfo();
uint64_t StackSize = MFI.getStackSize();
- unsigned Threshold = UINT_MAX;
+ uint64_t Threshold = TFI->getStackThreshold();
if (MF.getFunction().hasFnAttribute("warn-stack-size")) {
bool Failed = MF.getFunction()
.getFnAttribute("warn-stack-size")
diff --git a/llvm/lib/Target/PowerPC/PPCFrameLowering.cpp b/llvm/lib/Target/PowerPC/PPCFrameLowering.cpp
index d5e4ae34dde73a3..ec0be7570a2f396 100644
--- a/llvm/lib/Target/PowerPC/PPCFrameLowering.cpp
+++ b/llvm/lib/Target/PowerPC/PPCFrameLowering.cpp
@@ -2740,3 +2740,10 @@ bool PPCFrameLowering::enableShrinkWrapping(const MachineFunction &MF) const {
return false;
return !MF.getSubtarget<PPCSubtarget>().is32BitELFABI();
}
+
+uint64_t PPCFrameLowering::getStackThreshold() const {
+ if (Subtarget.isPPC64())
+ return 1UL << 63;
+
+ return TargetFrameLowering::getStackThreshold();
+}
diff --git a/llvm/lib/Target/PowerPC/PPCFrameLowering.h b/llvm/lib/Target/PowerPC/PPCFrameLowering.h
index 21883b19a57559f..e19087ce0e18694 100644
--- a/llvm/lib/Target/PowerPC/PPCFrameLowering.h
+++ b/llvm/lib/Target/PowerPC/PPCFrameLowering.h
@@ -173,6 +173,8 @@ class PPCFrameLowering: public TargetFrameLowering {
/// function prologue/epilogue.
bool canUseAsPrologue(const MachineBasicBlock &MBB) const override;
bool canUseAsEpilogue(const MachineBasicBlock &MBB) const override;
+
+ uint64_t getStackThreshold() const override;
};
} // End llvm namespace
diff --git a/llvm/test/CodeGen/PowerPC/warn-on-size.ll b/llvm/test/CodeGen/PowerPC/warn-on-size.ll
new file mode 100644
index 000000000000000..dfae2326939446f
--- /dev/null
+++ b/llvm/test/CodeGen/PowerPC/warn-on-size.ll
@@ -0,0 +1,18 @@
+; RUN: llc -mtriple=powerpc64-unknown-unknown < %s 2>&1 | FileCheck %s
+; RUN: llc -mtriple=powerpc64le-unknown-unknown < %s 2>&1 | FileCheck %s
+
+; CHECK-NOT: warning
+; CHECK-Label: large_stack
+define i8* @large_stack() {
+ %s = alloca [281474976710656 x i8], align 1
+ %e = getelementptr i8, i8* %s, i64 0
+ ret i8* %e
+}
+
+; CHECK: warning: {{.*}} stack frame size {{.*}} exceeds limit (4294967295) in function 'warn_on_large_stack'
+; CHECK-Label: warn_on_large_stack
+define i8* @warn_on_large_stack() "warn-stack-size"="4294967295" {
+ %s = alloca [281474976710656 x i8], align 1
+ %e = getelementptr i8, i8* %s, i64 0
+ ret i8* %e
+}
>From 0f9ea07d6157ed1f81b9b3c8a41ef4ca108ab620 Mon Sep 17 00:00:00 2001
From: Kai Luo <lkail at cn.ibm.com>
Date: Thu, 7 Sep 2023 02:50:12 +0000
Subject: [PATCH 2/4] Correct test
---
llvm/test/CodeGen/PowerPC/warn-on-size.ll | 6 ++----
1 file changed, 2 insertions(+), 4 deletions(-)
diff --git a/llvm/test/CodeGen/PowerPC/warn-on-size.ll b/llvm/test/CodeGen/PowerPC/warn-on-size.ll
index dfae2326939446f..3d56302bb6b8992 100644
--- a/llvm/test/CodeGen/PowerPC/warn-on-size.ll
+++ b/llvm/test/CodeGen/PowerPC/warn-on-size.ll
@@ -1,16 +1,14 @@
; RUN: llc -mtriple=powerpc64-unknown-unknown < %s 2>&1 | FileCheck %s
; RUN: llc -mtriple=powerpc64le-unknown-unknown < %s 2>&1 | FileCheck %s
-; CHECK-NOT: warning
-; CHECK-Label: large_stack
+; CHECK-NOT: warning: {{.*}} stack frame size ({{.*}}) exceeds limit (4294967295) in function 'large_stack'
define i8* @large_stack() {
%s = alloca [281474976710656 x i8], align 1
%e = getelementptr i8, i8* %s, i64 0
ret i8* %e
}
-; CHECK: warning: {{.*}} stack frame size {{.*}} exceeds limit (4294967295) in function 'warn_on_large_stack'
-; CHECK-Label: warn_on_large_stack
+; CHECK: warning: {{.*}} stack frame size ({{.*}}) exceeds limit (4294967295) in function 'warn_on_large_stack'
define i8* @warn_on_large_stack() "warn-stack-size"="4294967295" {
%s = alloca [281474976710656 x i8], align 1
%e = getelementptr i8, i8* %s, i64 0
>From 8e2eba74f1b1149d48dec7c37e433bc62c5f2dd2 Mon Sep 17 00:00:00 2001
From: Kai Luo <lkail at cn.ibm.com>
Date: Thu, 7 Sep 2023 02:52:05 +0000
Subject: [PATCH 3/4] Rename
---
llvm/test/CodeGen/PowerPC/{warn-on-size.ll => warn-stack-size.ll} | 0
1 file changed, 0 insertions(+), 0 deletions(-)
rename llvm/test/CodeGen/PowerPC/{warn-on-size.ll => warn-stack-size.ll} (100%)
diff --git a/llvm/test/CodeGen/PowerPC/warn-on-size.ll b/llvm/test/CodeGen/PowerPC/warn-stack-size.ll
similarity index 100%
rename from llvm/test/CodeGen/PowerPC/warn-on-size.ll
rename to llvm/test/CodeGen/PowerPC/warn-stack-size.ll
>From 07084a9ecefd44040b111f075a5ff5ac924c5189 Mon Sep 17 00:00:00 2001
From: Kai Luo <lkail at cn.ibm.com>
Date: Thu, 7 Sep 2023 05:13:45 +0000
Subject: [PATCH 4/4] Use opaque pointer
---
llvm/test/CodeGen/PowerPC/warn-stack-size.ll | 12 ++++++------
1 file changed, 6 insertions(+), 6 deletions(-)
diff --git a/llvm/test/CodeGen/PowerPC/warn-stack-size.ll b/llvm/test/CodeGen/PowerPC/warn-stack-size.ll
index 3d56302bb6b8992..03a4aa7e0db9514 100644
--- a/llvm/test/CodeGen/PowerPC/warn-stack-size.ll
+++ b/llvm/test/CodeGen/PowerPC/warn-stack-size.ll
@@ -2,15 +2,15 @@
; RUN: llc -mtriple=powerpc64le-unknown-unknown < %s 2>&1 | FileCheck %s
; CHECK-NOT: warning: {{.*}} stack frame size ({{.*}}) exceeds limit (4294967295) in function 'large_stack'
-define i8* @large_stack() {
+define ptr @large_stack() {
%s = alloca [281474976710656 x i8], align 1
- %e = getelementptr i8, i8* %s, i64 0
- ret i8* %e
+ %e = getelementptr i8, ptr %s, i64 0
+ ret ptr %e
}
; CHECK: warning: {{.*}} stack frame size ({{.*}}) exceeds limit (4294967295) in function 'warn_on_large_stack'
-define i8* @warn_on_large_stack() "warn-stack-size"="4294967295" {
+define ptr @warn_on_large_stack() "warn-stack-size"="4294967295" {
%s = alloca [281474976710656 x i8], align 1
- %e = getelementptr i8, i8* %s, i64 0
- ret i8* %e
+ %e = getelementptr i8, ptr %s, i64 0
+ ret ptr %e
}
More information about the llvm-commits
mailing list