[llvm] [SystemZ][z/OS] Add a parameter Align to emitIncrement() and use 32 for XPLINK stack on z/OS. (PR #182348)
via llvm-commits
llvm-commits at lists.llvm.org
Thu Feb 19 11:32:37 PST 2026
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-backend-systemz
Author: None (sujianIBM)
<details>
<summary>Changes</summary>
The stack alignment for 64-bit XPLINK is 32 on z/OS, but not 8.
This PR fixes this and adds a test to verify it.
---
Full diff: https://github.com/llvm/llvm-project/pull/182348.diff
2 Files Affected:
- (modified) llvm/lib/Target/SystemZ/SystemZFrameLowering.cpp (+5-5)
- (modified) llvm/test/CodeGen/SystemZ/zos-prologue-epilog.ll (+12-1)
``````````diff
diff --git a/llvm/lib/Target/SystemZ/SystemZFrameLowering.cpp b/llvm/lib/Target/SystemZ/SystemZFrameLowering.cpp
index d4c8f61245ae1..a11af9f2ef5ae 100644
--- a/llvm/lib/Target/SystemZ/SystemZFrameLowering.cpp
+++ b/llvm/lib/Target/SystemZ/SystemZFrameLowering.cpp
@@ -478,7 +478,7 @@ void SystemZELFFrameLowering::processFunctionBeforeFrameFinalized(
static void emitIncrement(MachineBasicBlock &MBB,
MachineBasicBlock::iterator &MBBI, const DebugLoc &DL,
Register Reg, int64_t NumBytes,
- const TargetInstrInfo *TII) {
+ const TargetInstrInfo *TII, unsigned Align = 8) {
while (NumBytes) {
unsigned Opcode;
int64_t ThisVal = NumBytes;
@@ -486,9 +486,9 @@ static void emitIncrement(MachineBasicBlock &MBB,
Opcode = SystemZ::AGHI;
else {
Opcode = SystemZ::AGFI;
- // Make sure we maintain 8-byte stack alignment.
+ // Make sure we maintain Align-byte stack alignment.
int64_t MinVal = -uint64_t(1) << 31;
- int64_t MaxVal = (int64_t(1) << 31) - 8;
+ int64_t MaxVal = (int64_t(1) << 31) - Align;
if (ThisVal < MinVal)
ThisVal = MinVal;
else if (ThisVal > MaxVal)
@@ -1299,7 +1299,7 @@ void SystemZXPLINKFrameLowering::emitPrologue(MachineFunction &MF,
}
emitIncrement(MBB, InsertPt, DL, Regs.getStackPointerRegister(), Delta,
- ZII);
+ ZII, /* Align = */32);
// If the requested stack size is larger than the guard page, then we need
// to check if we need to call the stack extender. This requires adding a
@@ -1369,7 +1369,7 @@ void SystemZXPLINKFrameLowering::emitEpilogue(MachineFunction &MF,
unsigned SPReg = Regs.getStackPointerRegister();
if (ZFI->getRestoreGPRRegs().LowGPR != SPReg) {
DebugLoc DL = MBBI->getDebugLoc();
- emitIncrement(MBB, MBBI, DL, SPReg, StackSize, ZII);
+ emitIncrement(MBB, MBBI, DL, SPReg, StackSize, ZII, /* Align = */32);
}
}
}
diff --git a/llvm/test/CodeGen/SystemZ/zos-prologue-epilog.ll b/llvm/test/CodeGen/SystemZ/zos-prologue-epilog.ll
index ecf778a36755b..8b00490db47e6 100644
--- a/llvm/test/CodeGen/SystemZ/zos-prologue-epilog.ll
+++ b/llvm/test/CodeGen/SystemZ/zos-prologue-epilog.ll
@@ -376,7 +376,6 @@ define void @large_stack1(i64 %n1, i64 %n2, i64 %n3) {
ret void
}
-
; CHECK-LABEL: large_stack2
; CHECK64: lgr 0,4
; CHECK64: stg 3,2192(4)
@@ -400,6 +399,18 @@ define void @large_stack2(i64 %n1, i64 %n2, i64 %n3) {
ret void
}
+; Verify stack alignment is 32
+; CHECK-LABEL: large_stack3
+; CHECK: agfi 4,-2147483648
+; CHECK-NEXT: aghi 4,-224
+; CHECK: agfi 4,2147483616
+; CHECK-NEXT: aghi 4,256
+define void @large_stack3() {
+ %arr = alloca [268435457 x i64], align 8
+ call i64 (ptr) @fun1(ptr %arr)
+ ret void
+}
+
; CHECK-LABEL: L#EPM_leaf_func0_0 DS 0H
; CHECK: * DSA Size 0x0
; CHECK: * Entry Flags
``````````
</details>
https://github.com/llvm/llvm-project/pull/182348
More information about the llvm-commits
mailing list