[llvm] Enable logf128 constant folding for hosts with 128bit long double (PR #96287)

Matthew Devereau via llvm-commits llvm-commits at lists.llvm.org
Thu Jul 11 07:47:50 PDT 2024


================
@@ -11,7 +11,15 @@
 
 namespace llvm {
 
-#if defined(__clang__) && defined(__FLOAT128__) &&                             \
+#if !defined(__LONG_DOUBLE_IBM128__) && (__SIZEOF_LONG_DOUBLE__ == 16) &&      \
+    (__SIZEOF_INT128__ == 16) && (__LDBL_MANT_DIG__ == 113)
+#define HAS_IEE754_FLOAT128
+#if (defined(__GNUC__) && __GNUC__ > 12)
----------------
MDevereau wrote:

I've instead decided to move to a CMake test which checks the availability of logf128, the availability of a true 128bit float type and that type's compatibility with the logf128 symbol to receive accurate answers instead of trying to do this inside a header file. 

A problem I faced when trying to run this on an x86 machine was that the size of long doubles were defined to be 16 bytes (when they are actually fp80) however calling logf128 with this type caused error codes to be returned from the function while compiling without issue. Using __float128 which is guaranteed to perform a 128 bit calculation even though the machine uses fp80 works OK though. I'm seeing both x86 with fp80 and aarch64 compile and run this without issues now. Instead of explicitly checking the GCC version, the _Float128 type which is available in GCC12+ is now asserted for availability and correctness and used if it is available.

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


More information about the llvm-commits mailing list