[llvm] Enable logf128 constant folding for hosts with 128bit long double (PR #104929)
David Green via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 21 00:04:11 PDT 2024
================
@@ -1781,11 +1782,19 @@ Constant *ConstantFoldFP(double (*NativeFP)(double), const APFloat &V,
return GetConstantFoldFPValue(Result, Ty);
}
-#if defined(HAS_IEE754_FLOAT128) && defined(HAS_LOGF128)
+#if defined(HAS_IEE754_FLOAT128)
Constant *ConstantFoldFP128(float128 (*NativeFP)(float128), const APFloat &V,
Type *Ty) {
llvm_fenv_clearexcept();
- float128 Result = NativeFP(V.convertToQuad());
+
+ if (!V.isValidIEEEQuad())
+ return nullptr;
+
+ APInt Api = V.bitcastToAPInt();
+ __uint128_t Int128 = ((__uint128_t)Api.extractBitsAsZExtValue(64, 64) << 64) +
+ Api.extractBitsAsZExtValue(64, 0);
+ float128 Result = NativeFP(llvm::bit_cast<float128>(Int128));
----------------
davemgreen wrote:
It might be worth having a method to abstract the two converts in this file.
https://github.com/llvm/llvm-project/pull/104929
More information about the llvm-commits
mailing list