[clang] 7a8d72f - [PowerPC] Use the 16-byte stack and vector alignment on OpenBSD (#245115)
via cfe-commits
cfe-commits at lists.llvm.org
Mon Nov 23 15:01:01 PST 2026
Author: Brad Smith
Date: 2026-11-23T18:00:55-05:00
New Revision: 7a8d72ff584050e1abbc387ec177a4dcf25633e6
URL: https://github.com/llvm/llvm-project/commit/7a8d72ff584050e1abbc387ec177a4dcf25633e6
DIFF: https://github.com/llvm/llvm-project/commit/7a8d72ff584050e1abbc387ec177a4dcf25633e6.diff
LOG: [PowerPC] Use the 16-byte stack and vector alignment on OpenBSD (#245115)
The 64-bit PowerPC data layout appends the stack and vector alignment
components only for AIX, Linux and FreeBSD, so powerpc64-openbsd gets a
shorter layout. OpenBSD also uses the ELFv2 ABI on powerpc64, so there
is no ABI reason for the difference. Without them the natural stack
alignment is left unspecified, which can cause unnecessary dynamic
stack realignment.
Follow-up to #232336, which did the same for FreeBSD.
Co-authored-by: Claude Opus 5.5 <noreply at anthropic.com>
Added:
Modified:
clang/test/CodeGen/target-data.c
llvm/lib/TargetParser/TargetDataLayout.cpp
llvm/unittests/TargetParser/TripleTest.cpp
Removed:
################################################################################
diff --git a/clang/test/CodeGen/target-data.c b/clang/test/CodeGen/target-data.c
index 0d70611254b03d..52c2baf7d0a281 100644
--- a/clang/test/CodeGen/target-data.c
+++ b/clang/test/CodeGen/target-data.c
@@ -118,6 +118,10 @@
// RUN: FileCheck %s -check-prefix=PPC64LE-FREEBSD
// PPC64LE-FREEBSD: target datalayout = "e-m:e-Fn32-i64:64-i128:128-n32:64-S128-v256:256:256-v512:512:512"
+// RUN: %clang_cc1 -triple powerpc64-openbsd -o - -emit-llvm %s | \
+// RUN: FileCheck %s -check-prefix=PPC64-OPENBSD
+// PPC64-OPENBSD: target datalayout = "E-m:e-Fn32-i64:64-i128:128-n32:64-S128-v256:256:256-v512:512:512"
+
// RUN: %clang_cc1 -triple powerpc64-linux -o - -emit-llvm %s | \
// RUN: FileCheck %s -check-prefix=PPC64-LINUX
// PPC64-LINUX: target datalayout = "E-m:e-Fi64-i64:64-i128:128-n32:64-S128-v256:256:256-v512:512:512"
diff --git a/llvm/lib/TargetParser/TargetDataLayout.cpp b/llvm/lib/TargetParser/TargetDataLayout.cpp
index 641e2c5134df92..c35765aaf4b023 100644
--- a/llvm/lib/TargetParser/TargetDataLayout.cpp
+++ b/llvm/lib/TargetParser/TargetDataLayout.cpp
@@ -235,9 +235,10 @@ static std::string computePowerDataLayout(const Triple &T, StringRef ABIName) {
// Specify the vector alignment explicitly. For v256i1 and v512i1, the
// calculated alignment would be 256*alignment(i1) and 512*alignment(i1),
// which is 256 and 512 bytes - way over aligned.
- // FreeBSD uses the ELFv2 ABI and has the same 16-byte stack alignment as
- // Linux.
- if (is64Bit && (T.isOSAIX() || T.isOSLinux() || T.isOSFreeBSD()))
+ // FreeBSD and OpenBSD use the ELFv2 ABI and have the same 16-byte stack
+ // alignment as Linux.
+ if (is64Bit &&
+ (T.isOSAIX() || T.isOSLinux() || T.isOSFreeBSD() || T.isOSOpenBSD()))
Ret += "-S128-v256:256:256-v512:512:512";
return Ret;
diff --git a/llvm/unittests/TargetParser/TripleTest.cpp b/llvm/unittests/TargetParser/TripleTest.cpp
index 5d2858fd3b7a52..5032b38eb631df 100644
--- a/llvm/unittests/TargetParser/TripleTest.cpp
+++ b/llvm/unittests/TargetParser/TripleTest.cpp
@@ -4146,6 +4146,15 @@ TEST(DataLayoutTest, PowerPC64FreeBSD) {
"E-m:e-Fn32-i64:64-i128:128-n32:64-S128-v256:256:256-v512:512:512");
}
+TEST(DataLayoutTest, PowerPC64OpenBSD) {
+ // OpenBSD uses the ELFv2 ABI on big-endian powerpc64 and shares the
+ // 16-byte stack alignment and the vector alignment of Linux.
+ EXPECT_EQ(Triple("powerpc64-unknown-openbsd").computeDataLayout(),
+ Triple("powerpc64-unknown-freebsd").computeDataLayout());
+ EXPECT_EQ(Triple("powerpc64-unknown-openbsd").computeDataLayout(),
+ "E-m:e-Fn32-i64:64-i128:128-n32:64-S128-v256:256:256-v512:512:512");
+}
+
TEST(DataLayoutTest, CheriRISCV32) {
Triple TT = Triple("riscv32-unknown-unknown");
More information about the cfe-commits
mailing list