Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[SPARC] Align i128 to 16 bytes in SPARC datalayouts #106951

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions clang/lib/Basic/Targets/Sparc.h
Original file line number Diff line number Diff line change
Expand Up @@ -151,7 +151,7 @@ class LLVM_LIBRARY_VISIBILITY SparcV8TargetInfo : public SparcTargetInfo {
public:
SparcV8TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
: SparcTargetInfo(Triple, Opts) {
resetDataLayout("E-m:e-p:32:32-i64:64-f128:64-n32-S64");
resetDataLayout("E-m:e-p:32:32-i64:64-i128:128-f128:64-n32-S64");
// NetBSD / OpenBSD use long (same as llvm default); everyone else uses int.
switch (getTriple().getOS()) {
default:
Expand Down Expand Up @@ -188,7 +188,7 @@ class LLVM_LIBRARY_VISIBILITY SparcV8elTargetInfo : public SparcV8TargetInfo {
public:
SparcV8elTargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
: SparcV8TargetInfo(Triple, Opts) {
resetDataLayout("e-m:e-p:32:32-i64:64-f128:64-n32-S64");
resetDataLayout("e-m:e-p:32:32-i64:64-i128:128-f128:64-n32-S64");
}
};

Expand All @@ -198,7 +198,7 @@ class LLVM_LIBRARY_VISIBILITY SparcV9TargetInfo : public SparcTargetInfo {
SparcV9TargetInfo(const llvm::Triple &Triple, const TargetOptions &Opts)
: SparcTargetInfo(Triple, Opts) {
// FIXME: Support Sparc quad-precision long double?
resetDataLayout("E-m:e-i64:64-n32:64-S128");
resetDataLayout("E-m:e-i64:64-i128:128-n32:64-S128");
// This is an LP64 platform.
LongWidth = LongAlign = PointerWidth = PointerAlign = 64;

Expand Down
4 changes: 2 additions & 2 deletions clang/test/CodeGen/target-data.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,11 +28,11 @@

// RUN: %clang_cc1 -triple sparc-sun-solaris -emit-llvm -o - %s | \
// RUN: FileCheck %s --check-prefix=SPARC-V8
// SPARC-V8: target datalayout = "E-m:e-p:32:32-i64:64-f128:64-n32-S64"
// SPARC-V8: target datalayout = "E-m:e-p:32:32-i64:64-i128:128-f128:64-n32-S64"

// RUN: %clang_cc1 -triple sparcv9-sun-solaris -emit-llvm -o - %s | \
// RUN: FileCheck %s --check-prefix=SPARC-V9
// SPARC-V9: target datalayout = "E-m:e-i64:64-n32:64-S128"
// SPARC-V9: target datalayout = "E-m:e-i64:64-i128:128-n32:64-S128"

// RUN: %clang_cc1 -triple mipsel-linux-gnu -o - -emit-llvm %s | \
// RUN: FileCheck %s -check-prefix=MIPS-32EL
Expand Down
12 changes: 12 additions & 0 deletions llvm/lib/IR/AutoUpgrade.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5461,6 +5461,18 @@ std::string llvm::UpgradeDataLayoutString(StringRef DL, StringRef TT) {
return Res;
}

if (T.isSPARC()) {
// Add "-i128:128"
std::string I128 = "-i128:128";
if (StringRef Ref = Res; !Ref.contains(I128)) {
SmallVector<StringRef, 4> Groups;
Regex R("^([Ee](-[mpi][^-]*)*)((-[^mpi][^-]*)*)$");
Copy link
Contributor

Choose a reason for hiding this comment

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

I think it would be easier to match for -i64:64- here? It looks like that part doesn't vary across subtargets, so we don't need more generic matching.

if (R.match(Res, &Groups))
Res = (Groups[1] + I128 + Groups[3]).str();
}
return Res;
}
nikic marked this conversation as resolved.
Show resolved Hide resolved

if (!T.isX86())
return Res;

Expand Down
4 changes: 4 additions & 0 deletions llvm/lib/Target/Sparc/SparcTargetMachine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,10 @@ static std::string computeDataLayout(const Triple &T, bool is64Bit) {
// Alignments for 64 bit integers.
Ret += "-i64:64";

// Alignments for 128 bit integers.
// This is not specified in the ABI document but is the de facto standard.
Ret += "-i128:128";

// On SparcV9 128 floats are aligned to 128 bits, on others only to 64.
// On SparcV9 registers can hold 64 or 32 bits, on others only 32.
if (is64Bit)
Expand Down
27 changes: 27 additions & 0 deletions llvm/test/CodeGen/SPARC/data-align.ll
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
; RUN: llc < %s -march=sparc | FileCheck %s
; RUN: llc < %s -march=sparcel | FileCheck %s
; RUN: llc < %s -march=sparcv9 | FileCheck %s

; CHECK: .Li8:
; CHECK-DAG: .size .Li8, 1
@i8 = private constant i8 42

; CHECK: .p2align 1
; CHECK-NEXT: .Li16:
; CHECK-DAG: .size .Li16, 2
@i16 = private constant i16 42

; CHECK: .p2align 2
; CHECK-NEXT: .Li32:
; CHECK-DAG: .size .Li32, 4
@i32 = private constant i32 42

; CHECK: .p2align 3
; CHECK-NEXT: .Li64:
; CHECK-DAG: .size .Li64, 8
@i64 = private constant i64 42

; CHECK: .p2align 4
; CHECK-NEXT: .Li128:
; CHECK-DAG: .size .Li128, 16
@i128 = private constant i128 42
7 changes: 7 additions & 0 deletions llvm/unittests/Bitcode/DataLayoutUpgradeTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,13 @@ TEST(DataLayoutUpgradeTest, ValidDataLayoutUpgrade) {
"loongarch64"),
"e-m:e-p:64:64-i64:64-i128:128-n32:64-S128");

// Check that SPARC targets add -i128:128.
EXPECT_EQ(
UpgradeDataLayoutString("E-m:e-p:32:32-i64:64-f128:64-n32-S64", "sparc"),
"E-m:e-p:32:32-i64:64-i128:128-f128:64-n32-S64");
EXPECT_EQ(UpgradeDataLayoutString("E-m:e-i64:64-n32:64-S128", "sparcv9"),
"E-m:e-i64:64-i128:128-n32:64-S128");

// Check that SPIR && SPIRV targets add -G1 if it's not present.
EXPECT_EQ(UpgradeDataLayoutString("e-p:32:32", "spir"), "e-p:32:32-G1");
EXPECT_EQ(UpgradeDataLayoutString("e-p:32:32", "spir64"), "e-p:32:32-G1");
Expand Down
Loading