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

NAKAMURA Takumi via llvm-commits llvm-commits at lists.llvm.org
Sat Aug 24 17:14:42 PDT 2024


================
@@ -2114,13 +2129,16 @@ static Constant *ConstantFoldScalarCall1(StringRef Name,
     if (IntrinsicID == Intrinsic::canonicalize)
       return constantFoldCanonicalize(Ty, Call, U);
 
-#if defined(HAS_IEE754_FLOAT128) && defined(HAS_LOGF128)
+#if defined(HAS_IEE754_FLOAT128)
     if (Ty->isFP128Ty()) {
       if (IntrinsicID == Intrinsic::log) {
-        float128 Result = logf128(Op->getValueAPF().convertToQuad());
+        APFloat Value = Op->getValueAPF();
+        if (!Value.isValidIEEEQuad())
+          return nullptr;
+
+        float128 Result = logf128(ConvertToQuad(Value));
----------------
chapuni wrote:

`APFloat` should have a software emulator that behaves bit-identical.
Then, the native `logf128` may be used as an optimization in it.

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


More information about the llvm-commits mailing list