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

Matthew Devereau via llvm-commits llvm-commits at lists.llvm.org
Tue Jun 25 06:04:47 PDT 2024


MDevereau wrote:

> Oh, I see, gcc 13 has _Float128, and on older versions glibc typedefs it to long double.
> 
> Can we make this not AArch64-specific? It seems like it affects any target where long double is 128 its.

I'm not opposed to the idea of making this non AArch64-specific, but on further inspection it seems logf128 using _Float128/__float128/long double isn't consistent with GCC/Clang versions across hosts.

While trying to figure out which host/compiler combinations were appropriate to use, it quickly got quite confusing. Including math.h seems to typedef long double to _Float128 under certain circumstances, but support for the original untypedef'd types seems to vary.
I ran this test (https://godbolt.org/z/f1c9q9jh4) while substituting the type to check which compiler/host combination works for the types without including math.h. I'm interested in AArch64/x86 supporting this predominantly so I've included those:

AArch64:
| Type | GCC-13.1 | GCC-12.4 | Clang-18.1 |
| ---------- |  ---------- | ---------- | ---------- |
| _Float128 | pass | fail | fail |
| __float128 | fail | fail | fail |
| long double | pass | pass | pass |

x86:
| Type | GCC-13.1 | GCC-12.4 | Clang-18.1 |
| ---------- |  ---------- | ---------- | ---------- |
| _Float128 | pass | fail | fail |
| __float128 | pass | pass | pass |
| long double | pass | pass | pass |
 
Where it gets interesting is when using these types as parameters to logf128 from math.h. In GCC-13 and over logf128 appears to be a builtin which takes _Float128 and does not allow implicit conversions, but on x86 logf128 seems to take a typedef of _Float128/__float128 which throws when given long double. I then ran this logf128 function pointer test (https://godbolt.org/z/GvM78hbbh) for the same host/target combinations and got these results:

AArch64:
| Type | GCC-13.1 | GCC-12.4 | Clang-18.1 |
| ---------- |  ---------- | ---------- | ---------- |
| _Float128 | pass | pass | pass |
| __float128 | fail | fail | fail |
| long double | fail | pass | pass |

x86:
| Type | GCC-13.1 | GCC-12.4 | Clang-18.1 |
| ---------- |  ---------- | ---------- | ---------- |
| _Float128 | pass | pass | fail |
| __float128 | fail | pass | fail |
| long double | fail | fail | fail |

So while x86 has a long double length of 128 bits, I don't think it's ok to enable this based on long double information alone. It looks like the only way to stay sane in this scenario is to do it on a per host and per compiler basis.


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


More information about the llvm-commits mailing list