[llvm] ConstantFold logl calls (PR #94944)

Matthew Devereau via llvm-commits llvm-commits at lists.llvm.org
Fri Jun 14 01:20:01 PDT 2024


================
@@ -2085,15 +2085,18 @@ static Constant *ConstantFoldScalarCall1(StringRef Name,
     if (IntrinsicID == Intrinsic::canonicalize)
       return constantFoldCanonicalize(Ty, Call, U);
 
+      // Try to handle special fp128 cases before bailing
 #if defined(HAS_IEE754_FLOAT128) && defined(HAS_LOGF128)
     if (Ty->isFP128Ty()) {
-      switch (IntrinsicID) {
-      default:
-        return nullptr;
-      case Intrinsic::log:
-        return ConstantFP::get(Ty, logf128(Op->getValueAPF().convertToQuad()));
-      }
+      const APFloat &Fp128APF = Op->getValueAPF();
+      if (IntrinsicID == Intrinsic::log)
+        return ConstantFP::get(Ty, logf128(Fp128APF.convertToQuad()));
     }
+
+    LibFunc Fp128Func = NotLibFunc;
+    if (Ty->isFP128Ty() && TLI->getLibFunc(Name, Fp128Func) &&
+        TLI->has(Fp128Func) && Fp128Func == LibFunc_logl)
+      return ConstantFP::get(Ty, logf128(Op->getValueAPF().convertToQuad()));
----------------
MDevereau wrote:

Done

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


More information about the llvm-commits mailing list