Skip to content

Commit

Permalink
Enable logf128 constant folding for AArch64
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
MDevereau committed Jun 21, 2024
1 parent 0f1b627 commit 4cc6905
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 3 deletions.
9 changes: 8 additions & 1 deletion llvm/include/llvm/Support/float128.h
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
4 changes: 2 additions & 2 deletions llvm/lib/Analysis/ConstantFolding.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand Down

0 comments on commit 4cc6905

Please sign in to comment.