[llvm] Enable logf128 constant folding for AArch64 (PR #96287)
via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 21 04:44:39 PDT 2024
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-llvm-support
@llvm/pr-subscribers-llvm-analysis
Author: Matthew Devereau (MDevereau)
<details>
<summary>Changes</summary>
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.
---
Full diff: https://github.com/llvm/llvm-project/pull/96287.diff
2 Files Affected:
- (modified) llvm/include/llvm/Support/float128.h (+8-1)
- (modified) llvm/lib/Analysis/ConstantFolding.cpp (+2-2)
``````````diff
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()) {
``````````
</details>
https://github.com/llvm/llvm-project/pull/96287
More information about the llvm-commits
mailing list