Skip to content

Conversation

@JonPsson1
Copy link
Contributor

@JonPsson1 JonPsson1 commented Jan 14, 2026

Add '-S64' to the SystemZ datalayout string, to avoid overalignment of stack objects.

Fixes #173402

This changes 25 files on SPEC over 5 benchmarks, with fewer cases of runtime-alignment (NILL instructions).

@uweigand @nikic

@llvmbot
Copy link
Member

llvmbot commented Jan 14, 2026

@llvm/pr-subscribers-llvm-ir

@llvm/pr-subscribers-backend-systemz

Author: Jonas Paulsson (JonPsson1)

Changes

Add '-S64' to the SystemZ datalayout string, to avoid overalignment of stack objects.

This changes 25 files on SPEC over 5 benchmarks, with fewer cases of runtime-alignment (NILL instructions).

@uweigand @nikic


Full diff: https://github.com/llvm/llvm-project/pull/176041.diff

3 Files Affected:

  • (modified) clang/test/CodeGen/target-data.c (+3-3)
  • (modified) llvm/lib/TargetParser/TargetDataLayout.cpp (+3)
  • (added) llvm/test/CodeGen/SystemZ/stack-align.ll (+17)
diff --git a/clang/test/CodeGen/target-data.c b/clang/test/CodeGen/target-data.c
index e95079490bd3c..ee8e45511720c 100644
--- a/clang/test/CodeGen/target-data.c
+++ b/clang/test/CodeGen/target-data.c
@@ -207,11 +207,11 @@
 // RUN: FileCheck %s -check-prefix=SYSTEMZ
 // RUN: %clang_cc1 -triple s390x-unknown -target-cpu z13 -target-feature +soft-float -o - -emit-llvm %s | \
 // RUN: FileCheck %s -check-prefix=SYSTEMZ
-// SYSTEMZ: target datalayout = "E-m:e-i1:8:16-i8:8:16-i64:64-f128:64-v128:64-a:8:16-n32:64"
+// SYSTEMZ: target datalayout = "E-S64-m:e-i1:8:16-i8:8:16-i64:64-f128:64-v128:64-a:8:16-n32:64"
 
 // RUN: %clang_cc1 -triple s390x-unknown -target-cpu z13 -o - -emit-llvm %s | \
 // RUN: FileCheck %s -check-prefix=SYSTEMZ-VECTOR
-// SYSTEMZ-VECTOR: target datalayout = "E-m:e-i1:8:16-i8:8:16-i64:64-f128:64-v128:64-a:8:16-n32:64"
+// SYSTEMZ-VECTOR: target datalayout = "E-S64-m:e-i1:8:16-i8:8:16-i64:64-f128:64-v128:64-a:8:16-n32:64"
 
 // RUN: %clang_cc1 -triple s390x-none-zos -target-cpu z10 -o - -emit-llvm %s | \
 // RUN: FileCheck %s -check-prefix=ZOS
@@ -219,7 +219,7 @@
 // RUN: FileCheck %s -check-prefix=ZOS
 // RUN: %clang_cc1 -triple s390x-none-zos -target-cpu z13 -o - -emit-llvm %s | \
 // RUN: FileCheck %s -check-prefix=ZOS
-// ZOS: target datalayout = "E-m:l-p1:32:32-i1:8:16-i8:8:16-i64:64-f128:64-v128:64-a:8:16-n32:64"
+// ZOS: target datalayout = "E-S64-m:l-p1:32:32-i1:8:16-i8:8:16-i64:64-f128:64-v128:64-a:8:16-n32:64"
 
 // RUN: %clang_cc1 -triple msp430-unknown -o - -emit-llvm %s | \
 // RUN: FileCheck %s -check-prefix=MSP430
diff --git a/llvm/lib/TargetParser/TargetDataLayout.cpp b/llvm/lib/TargetParser/TargetDataLayout.cpp
index b8c3b4325558c..b985c1eec4244 100644
--- a/llvm/lib/TargetParser/TargetDataLayout.cpp
+++ b/llvm/lib/TargetParser/TargetDataLayout.cpp
@@ -357,6 +357,9 @@ static std::string computeSystemZDataLayout(const Triple &TT) {
   // Big endian.
   Ret += "E";
 
+  // The natural stack alignment is 64 bits.
+  Ret += "-S64";
+
   // Data mangling.
   Ret += getManglingComponent(TT);
 
diff --git a/llvm/test/CodeGen/SystemZ/stack-align.ll b/llvm/test/CodeGen/SystemZ/stack-align.ll
new file mode 100644
index 0000000000000..d7f6b1e8a46f2
--- /dev/null
+++ b/llvm/test/CodeGen/SystemZ/stack-align.ll
@@ -0,0 +1,17 @@
+; RUN: opt < %s -mtriple=s390x-unknown-linux-gnu -mcpu=z16 -S -passes=infer-alignment \
+; RUN:   2>&1 | FileCheck %s
+;
+; Test that the alignment of the alloca is not increased beyond the stack
+; alignment of 8 bytes.
+
+declare void @foo(ptr)
+
+define void @f1(<4 x i64> %Arg) {
+; CHECK-LABEL: define void @f1
+; CHECK-NEXT:    %param = alloca <4 x i64>, align 8
+; CHECK-NEXT:    store <4 x i64> %Arg, ptr %param, align 8
+  %param = alloca <4 x i64>, align 8
+  store <4 x i64> %Arg, ptr %param, align 8
+  call void @foo(ptr %param)
+  ret void
+}

@github-actions
Copy link

github-actions bot commented Jan 14, 2026

🪟 Windows x64 Test Results

  • 131220 tests passed
  • 4192 tests skipped

✅ The build succeeded and all tests passed.

@github-actions
Copy link

github-actions bot commented Jan 14, 2026

🐧 Linux x64 Test Results

  • 195421 tests passed
  • 6400 tests skipped

✅ The build succeeded and all tests passed.

Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You'll have to handle this in

std::string llvm::UpgradeDataLayoutString(StringRef DL, StringRef TT) {
as well.

@alexrp alexrp mentioned this pull request Jan 15, 2026
17 tasks
@JonPsson1
Copy link
Contributor Author

@nikic Thanks for review - I handled this in UpgradeDataLayoutString() as well. LGTY?

@github-actions
Copy link

github-actions bot commented Jan 19, 2026

✅ With the latest revision this PR passed the C/C++ code formatter.

Copy link
Contributor

@nikic nikic left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use update_test_checks.py please.

Copy link
Member

@uweigand uweigand left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM as well.

@JonPsson1 JonPsson1 merged commit 8eccda1 into llvm:main Jan 20, 2026
11 checks passed
maurer added a commit to maurer/rust that referenced this pull request Jan 20, 2026
LLVM 23 will mark the stack as aligned for more efficient code:

llvm/llvm-project#176041
jhpratt pushed a commit to jhpratt/rust that referenced this pull request Jan 21, 2026
LLVM 23 will mark the stack as aligned for more efficient code:

llvm/llvm-project#176041
jhpratt added a commit to jhpratt/rust that referenced this pull request Jan 21, 2026
s390x: Support aligned stack datalayout

LLVM 23 will mark the stack as aligned for more efficient code:

llvm/llvm-project#176041

r? durin42

@rustbot label llvm-main
rust-timer added a commit to rust-lang/rust that referenced this pull request Jan 21, 2026
Rollup merge of #151429 - s390x, r=durin42

s390x: Support aligned stack datalayout

LLVM 23 will mark the stack as aligned for more efficient code:

llvm/llvm-project#176041

r? durin42

@rustbot label llvm-main
BStott6 pushed a commit to BStott6/llvm-project that referenced this pull request Jan 22, 2026
Add '-S64' to the SystemZ datalayout string, to avoid overalignment of
stack objects.

Fixes llvm#173402
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[InferAlignmentPass, SystemZ] Over-aligned vectors

4 participants