[llvm] Enable logf128 constant folding for AArch64 (PR #96287)

Matthew Devereau via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 21 01:39:30 PDT 2024


https://github.com/MDevereau updated https://github.com/llvm/llvm-project/pull/96287

>From 4cc6905d7020140bf1facad3ad9c0888cb7e4734 Mon Sep 17 00:00:00 2001
From: Matt Devereau <matthew.devereau at arm.com>
Date: Fri, 21 Jun 2024 08:34:04 +0000
Subject: [PATCH] Enable logf128 constant folding for AArch64

AArch64 has a long double bit length of 128. Therefore, it can benefit
from constant fp128 folding. GCC versions more recent than version 12
must use the _Float128 type for logf128.
---
 llvm/include/llvm/Support/float128.h  | 9 ++++++++-
 llvm/lib/Analysis/ConstantFolding.cpp | 4 ++--
 2 files changed, 10 insertions(+), 3 deletions(-)

diff --git a/llvm/include/llvm/Support/float128.h b/llvm/include/llvm/Support/float128.h
index e15a98dc5a677..f1931c145f0fc 100644
--- a/llvm/include/llvm/Support/float128.h
+++ b/llvm/include/llvm/Support/float128.h
@@ -11,7 +11,14 @@
 
 namespace llvm {
 
-#if defined(__clang__) && defined(__FLOAT128__) &&                             \
+#if defined(__aarch64__)
+#define HAS_IEE754_FLOAT128
+#if (defined(__GNUC__) && __GNUC__ > 12)
+typedef _Float128 float128;
+#else
+typedef long double float128;
+#endif
+#elif defined(__clang__) && defined(__FLOAT128__) &&                           \
     defined(__SIZEOF_INT128__) && !defined(__LONG_DOUBLE_IBM128__)
 #define HAS_IEE754_FLOAT128
 typedef __float128 float128;
diff --git a/llvm/lib/Analysis/ConstantFolding.cpp b/llvm/lib/Analysis/ConstantFolding.cpp
index 512d1aadd5346..4329d2e9a0556 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -1784,8 +1784,8 @@ Constant *ConstantFoldFP(double (*NativeFP)(double), const APFloat &V,
 }
 
 #if defined(HAS_IEE754_FLOAT128) && defined(HAS_LOGF128)
-Constant *ConstantFoldFP128(long double (*NativeFP)(long double),
-                            const APFloat &V, Type *Ty) {
+Constant *ConstantFoldFP128(float128 (*NativeFP)(float128), const APFloat &V,
+                            Type *Ty) {
   llvm_fenv_clearexcept();
   float128 Result = NativeFP(V.convertToQuad());
   if (llvm_fenv_testexcept()) {



More information about the llvm-commits mailing list