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

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


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

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.

>From c42e7e44229c24eb59c2286ca0094cb6b6b0d79f 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 for logf128.
---
 llvm/include/llvm/Support/float128.h  | 9 ++++++++-
 llvm/lib/Analysis/ConstantFolding.cpp | 2 +-
 2 files changed, 9 insertions(+), 2 deletions(-)

diff --git a/llvm/include/llvm/Support/float128.h b/llvm/include/llvm/Support/float128.h
index e15a98dc5a677..2d098f2e4fa37 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..6b97d2ac79d0e 100644
--- a/llvm/lib/Analysis/ConstantFolding.cpp
+++ b/llvm/lib/Analysis/ConstantFolding.cpp
@@ -1784,7 +1784,7 @@ Constant *ConstantFoldFP(double (*NativeFP)(double), const APFloat &V,
 }
 
 #if defined(HAS_IEE754_FLOAT128) && defined(HAS_LOGF128)
-Constant *ConstantFoldFP128(long double (*NativeFP)(long double),
+Constant *ConstantFoldFP128(float128 (*NativeFP)(float128),
                             const APFloat &V, Type *Ty) {
   llvm_fenv_clearexcept();
   float128 Result = NativeFP(V.convertToQuad());



More information about the llvm-commits mailing list