[llvm] [RISCV] Use implicit def/use of SP for PROBED_STACKALLOC*. (PR #139153)
Craig Topper via llvm-commits
llvm-commits at lists.llvm.org
Thu May 8 13:57:03 PDT 2025
https://github.com/topperc updated https://github.com/llvm/llvm-project/pull/139153
>From bfa811cf4d7077760c11af405b51bd51514b78cd Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Thu, 8 May 2025 13:45:24 -0700
Subject: [PATCH 1/2] [RISCV] Use implicit def/use of SP for
PROBED_STACKALLOC*.
---
llvm/lib/Target/RISCV/RISCVFrameLowering.cpp | 4 +---
llvm/lib/Target/RISCV/RISCVInstrInfo.td | 15 ++++++++-------
2 files changed, 9 insertions(+), 10 deletions(-)
diff --git a/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp b/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
index 72bec74584059..68907ba4a85d9 100644
--- a/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
@@ -633,7 +633,6 @@ void RISCVFrameLowering::allocateAndProbeStackForRVV(
// It will be expanded to a probe loop in `inlineStackProbe`.
BuildMI(MBB, MBBI, DL, TII->get(RISCV::PROBED_STACKALLOC_RVV))
- .addReg(SPReg)
.addReg(TargetReg);
if (EmitCFI) {
@@ -829,7 +828,6 @@ void RISCVFrameLowering::allocateStack(MachineBasicBlock &MBB,
// It will be expanded to a probe loop in `inlineStackProbe`.
BuildMI(MBB, MBBI, DL, TII->get(RISCV::PROBED_STACKALLOC))
- .addReg(SPReg)
.addReg(TargetReg);
if (EmitCFI) {
@@ -2420,7 +2418,7 @@ void RISCVFrameLowering::inlineStackProbe(MachineFunction &MF,
MI->getOpcode() == RISCV::PROBED_STACKALLOC_RVV) {
MachineBasicBlock::iterator MBBI = MI->getIterator();
DebugLoc DL = MBB.findDebugLoc(MBBI);
- Register TargetReg = MI->getOperand(1).getReg();
+ Register TargetReg = MI->getOperand(0).getReg();
emitStackProbeInline(MBBI, DL, TargetReg,
(MI->getOpcode() == RISCV::PROBED_STACKALLOC_RVV));
MBBI->eraseFromParent();
diff --git a/llvm/lib/Target/RISCV/RISCVInstrInfo.td b/llvm/lib/Target/RISCV/RISCVInstrInfo.td
index 4a4290483e94b..e4ab8ff40b079 100644
--- a/llvm/lib/Target/RISCV/RISCVInstrInfo.td
+++ b/llvm/lib/Target/RISCV/RISCVInstrInfo.td
@@ -1452,17 +1452,18 @@ def GIAddrRegImm :
/// Stack probing
-let hasSideEffects = 1, mayLoad = 1, mayStore = 1, isCodeGenOnly = 1 in {
+let hasSideEffects = 1, mayLoad = 1, mayStore = 1, isCodeGenOnly = 1,
+ Defs = [X2], Uses = [X2] in {
// Probed stack allocation of a constant size, used in function prologues when
// stack-clash protection is enabled.
-def PROBED_STACKALLOC : Pseudo<(outs GPR:$sp),
- (ins GPR:$scratch),
- []>,
- Sched<[]>;
-def PROBED_STACKALLOC_RVV : Pseudo<(outs GPR:$sp),
- (ins GPR:$scratch),
+def PROBED_STACKALLOC : Pseudo<(outs),
+ (ins GPR:$target),
[]>,
Sched<[]>;
+def PROBED_STACKALLOC_RVV : Pseudo<(outs),
+ (ins GPR:$target),
+ []>,
+ Sched<[]>;
let usesCustomInserter = 1 in
def PROBED_STACKALLOC_DYN : Pseudo<(outs GPR:$rd),
(ins GPR:$scratch),
>From 82fd7c785a05a6152e528785e9cd7a444fe443f1 Mon Sep 17 00:00:00 2001
From: Craig Topper <craig.topper at sifive.com>
Date: Thu, 8 May 2025 13:56:42 -0700
Subject: [PATCH 2/2] fixup! clang-format
---
llvm/lib/Target/RISCV/RISCVFrameLowering.cpp | 3 +--
1 file changed, 1 insertion(+), 2 deletions(-)
diff --git a/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp b/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
index 68907ba4a85d9..37caf25cce15c 100644
--- a/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
+++ b/llvm/lib/Target/RISCV/RISCVFrameLowering.cpp
@@ -827,8 +827,7 @@ void RISCVFrameLowering::allocateStack(MachineBasicBlock &MBB,
}
// It will be expanded to a probe loop in `inlineStackProbe`.
- BuildMI(MBB, MBBI, DL, TII->get(RISCV::PROBED_STACKALLOC))
- .addReg(TargetReg);
+ BuildMI(MBB, MBBI, DL, TII->get(RISCV::PROBED_STACKALLOC)).addReg(TargetReg);
if (EmitCFI) {
// Set the CFA register back to SP.
More information about the llvm-commits
mailing list