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

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Sun Aug 23 00:23:52 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);
----------------
arsenm wrote:

I didn't mean check isFloatingPointTy, I meant some property of the fltSemantics which tells you this is a power of 2 FP type 

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


More information about the llvm-commits mailing list