[clang] [X86] Add ABI handling for __float128 (PR #75156)

Phoebe Wang via cfe-commits cfe-commits at lists.llvm.org
Thu Jan 4 19:15:08 PST 2024


https://github.com/phoebewang updated https://github.com/llvm/llvm-project/pull/75156

>From 9860e5454bdf3ee3a4283ab7102a8d70c3ebcbbc Mon Sep 17 00:00:00 2001
From: Phoebe Wang <phoebe.wang at intel.com>
Date: Tue, 12 Dec 2023 17:27:33 +0800
Subject: [PATCH 1/4] [X86] Add ABI handling for fp128

Fixes #74601
---
 clang/lib/CodeGen/Targets/X86.cpp  |  3 ++-
 clang/test/CodeGen/X86/fp128-abi.c | 35 ++++++++++++++++++++++++++++++
 2 files changed, 37 insertions(+), 1 deletion(-)
 create mode 100644 clang/test/CodeGen/X86/fp128-abi.c

diff --git a/clang/lib/CodeGen/Targets/X86.cpp b/clang/lib/CodeGen/Targets/X86.cpp
index 2af24035043884..c4bf38056a673f 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -1795,7 +1795,8 @@ void X86_64ABIInfo::classify(QualType Ty, uint64_t OffsetBase, Class &Lo,
     } else if (k >= BuiltinType::Bool && k <= BuiltinType::LongLong) {
       Current = Integer;
     } else if (k == BuiltinType::Float || k == BuiltinType::Double ||
-               k == BuiltinType::Float16 || k == BuiltinType::BFloat16) {
+               k == BuiltinType::Float16 || k == BuiltinType::BFloat16 ||
+               k == BuiltinType::Float128) {
       Current = SSE;
     } else if (k == BuiltinType::LongDouble) {
       const llvm::fltSemantics *LDF = &getTarget().getLongDoubleFormat();
diff --git a/clang/test/CodeGen/X86/fp128-abi.c b/clang/test/CodeGen/X86/fp128-abi.c
new file mode 100644
index 00000000000000..1c5d7cf1166ee1
--- /dev/null
+++ b/clang/test/CodeGen/X86/fp128-abi.c
@@ -0,0 +1,35 @@
+// RUN: %clang_cc1 -triple x86_64-linux -emit-llvm  -target-feature +sse2 < %s | FileCheck %s --check-prefixes=CHECK
+
+struct st1 {
+  __float128 a;
+};
+
+struct st1 h1(__float128 a) {
+  // CHECK: define{{.*}}fp128 @h1(fp128
+  struct st1 x;
+  x.a = a;
+  return x;
+}
+
+__float128 h2(struct st1 x) {
+  // CHECK: define{{.*}}fp128 @h2(fp128
+  return x.a;
+}
+
+struct st2 {
+  __float128 a;
+  int b;
+};
+
+struct st2 h3(__float128 a, int b) {
+  // CHECK: define{{.*}}void @h3(ptr {{.*}}sret(%struct.st2)
+  struct st2 x;
+  x.a = a;
+  x.b = b;
+  return x;
+}
+
+__float128 h4(struct st2 x) {
+  // CHECK: define{{.*}}fp128 @h4(ptr {{.*}}byval(%struct.st2)
+  return x.a;
+}

>From 2619d6840965fb7447182f2026d5e48eca7b064b Mon Sep 17 00:00:00 2001
From: Phoebe Wang <phoebe.wang at intel.com>
Date: Thu, 21 Dec 2023 15:33:52 +0800
Subject: [PATCH 2/4] Add non-SSE RUN

---
 clang/lib/CodeGen/Targets/X86.cpp  | 6 ++++--
 clang/test/CodeGen/X86/fp128-abi.c | 1 +
 2 files changed, 5 insertions(+), 2 deletions(-)

diff --git a/clang/lib/CodeGen/Targets/X86.cpp b/clang/lib/CodeGen/Targets/X86.cpp
index c4bf38056a673f..d053f41ab168f5 100644
--- a/clang/lib/CodeGen/Targets/X86.cpp
+++ b/clang/lib/CodeGen/Targets/X86.cpp
@@ -1795,9 +1795,11 @@ void X86_64ABIInfo::classify(QualType Ty, uint64_t OffsetBase, Class &Lo,
     } else if (k >= BuiltinType::Bool && k <= BuiltinType::LongLong) {
       Current = Integer;
     } else if (k == BuiltinType::Float || k == BuiltinType::Double ||
-               k == BuiltinType::Float16 || k == BuiltinType::BFloat16 ||
-               k == BuiltinType::Float128) {
+               k == BuiltinType::Float16 || k == BuiltinType::BFloat16) {
       Current = SSE;
+    } else if (k == BuiltinType::Float128) {
+      Lo = SSE;
+      Hi = SSEUp;
     } else if (k == BuiltinType::LongDouble) {
       const llvm::fltSemantics *LDF = &getTarget().getLongDoubleFormat();
       if (LDF == &llvm::APFloat::IEEEquad()) {
diff --git a/clang/test/CodeGen/X86/fp128-abi.c b/clang/test/CodeGen/X86/fp128-abi.c
index 1c5d7cf1166ee1..2a0ae5009338a4 100644
--- a/clang/test/CodeGen/X86/fp128-abi.c
+++ b/clang/test/CodeGen/X86/fp128-abi.c
@@ -1,4 +1,5 @@
 // RUN: %clang_cc1 -triple x86_64-linux -emit-llvm  -target-feature +sse2 < %s | FileCheck %s --check-prefixes=CHECK
+// RUN: %clang_cc1 -triple x86_64-linux -emit-llvm  -target-feature -sse2 < %s | FileCheck %s --check-prefixes=CHECK
 
 struct st1 {
   __float128 a;

>From 30db4d0a6d74fdc0642801998c8a734c6c82726d Mon Sep 17 00:00:00 2001
From: Phoebe Wang <phoebe.wang at intel.com>
Date: Fri, 5 Jan 2024 11:13:46 +0800
Subject: [PATCH 3/4] Added release note

---
 clang/docs/ReleaseNotes.rst | 1 +
 1 file changed, 1 insertion(+)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index b62293a33bb9ff..902f64bc9aa144 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -906,6 +906,7 @@ X86 Support
   * Support intrinsic of ``_uwrmsr``.
 - Support ISA of ``AVX10.1``.
 - ``-march=pantherlake`` and ``-march=clearwaterforest`` are now supported.
+- Added ABI handling for ``fp128``.
 
 Arm and AArch64 Support
 ^^^^^^^^^^^^^^^^^^^^^^^

>From af71a05c89240b866154da79cced93eae17821db Mon Sep 17 00:00:00 2001
From: Phoebe Wang <phoebe.wang at intel.com>
Date: Fri, 5 Jan 2024 11:14:52 +0800
Subject: [PATCH 4/4] Fix typo

---
 clang/docs/ReleaseNotes.rst | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst
index 902f64bc9aa144..4bb10cd2df27f8 100644
--- a/clang/docs/ReleaseNotes.rst
+++ b/clang/docs/ReleaseNotes.rst
@@ -906,7 +906,7 @@ X86 Support
   * Support intrinsic of ``_uwrmsr``.
 - Support ISA of ``AVX10.1``.
 - ``-march=pantherlake`` and ``-march=clearwaterforest`` are now supported.
-- Added ABI handling for ``fp128``.
+- Added ABI handling for ``__float128``.
 
 Arm and AArch64 Support
 ^^^^^^^^^^^^^^^^^^^^^^^



More information about the cfe-commits mailing list