[llvm] [SimplifyLibCalls] Constant fold scalbxx (PR #114417)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Sun Nov 3 08:33:55 PST 2024


================
@@ -2621,6 +2623,26 @@ static Constant *ConstantFoldLibCall2(StringRef Name, Type *Ty,
   switch (Func) {
   default:
     break;
+  case LibFunc_ldexp:
+  case LibFunc_ldexpf:
+  case LibFunc_ldexpl:
+  case LibFunc_scalbn:
+  case LibFunc_scalbnf:
+  case LibFunc_scalbnl:
+  case LibFunc_scalbln:
+  case LibFunc_scalblnf:
+  case LibFunc_scalblnl:
+    if (TLI->has(Func)) {
+      Constant *tmp = ConstantFoldBinaryFP(pow, APFloat(2.0), Op2V, Ty);
+      const auto *tmp1 = dyn_cast<ConstantFP>(tmp);
+      if (!tmp1)
+        return nullptr;
+      APFloat Op1V2(Op1V);
+      auto eval_ret = Op1V2.multiply(tmp1->getValueAPF(), RoundingMode::TowardZero);
+      if (APFloat::opStatus::opOK == eval_ret)
+        return ConstantFP::get(Ty->getContext(), Op1V2);
----------------
arsenm wrote:

APFloat already directly has scalbn, you do not need to emulate it with pow and multiply 


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


More information about the llvm-commits mailing list