[llvm] [InstCombine] Fold scalbn libcalls to llvm.ldexp (PR #216573)

Hadong Lee via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 23 04:07:45 PDT 2026


================
@@ -4103,6 +4103,18 @@ Value *LibCallSimplifier::optimizeFloatingPointLibCall(CallInst *CI,
   case LibFunc_exp2:
   case LibFunc_exp2f:
     return optimizeExp2(CI, Builder);
+  case LibFunc_scalbn:
+  case LibFunc_scalbnf:
+  case LibFunc_scalbnl:
+    // LLVM floating-point types have radix 2, so scalbn is equivalent to
+    // ldexp. Do not replace a libcall that may set errno.
+    if (CI->getType()->isFloatingPointTy() && CI->doesNotAccessMemory()) {
+      Value *NewCall =
+          Builder.CreateLdexp(CI->getArgOperand(0), CI->getArgOperand(1), CI);
+      NewCall->takeName(CI);
----------------
ChrisLee02 wrote:

As mentioned above, the available way I see to guard against a future decimal FP type is an explicit whitelist.

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


More information about the llvm-commits mailing list