[llvm] add `frexp`/`ldexp` expansion in `ExpandIrInsts` (PR #208556)
Matt Arsenault via llvm-commits
llvm-commits at lists.llvm.org
Tue Jul 14 02:19:25 PDT 2026
================
@@ -546,6 +548,220 @@ static bool expandFRem(BinaryOperator &I, std::optional<SimplifyQuery> &SQ) {
return true;
}
+
+static void expandLdexp(IntrinsicInst *II) {
+ LLVM_DEBUG(dbgs() << "Expanding instruction: " << *II << '\n');
+
+ IRBuilder<> B(II);
+ B.SetCurrentDebugLocation(II->getDebugLoc());
+ LLVMContext &Ctx = II->getContext();
+
+ Type *VT = II->getType();
+ Value *X = II->getArgOperand(0);
+ Value *N = II->getArgOperand(1);
+ Type *ExpVT = N->getType();
+ Type *AsIntVT = B.getIntNTy(VT->getScalarSizeInBits());
+
+ const fltSemantics &FltSem = VT->getFltSemantics();
+
+ const APFloat::ExponentType MaxExpVal = APFloat::semanticsMaxExponent(FltSem);
+ const APFloat::ExponentType MinExpVal = APFloat::semanticsMinExponent(FltSem);
+ const int Precision = APFloat::semanticsPrecision(FltSem);
+
+ Constant *MaxExp = ConstantInt::getSigned(ExpVT, MaxExpVal);
+ Constant *MinExp = ConstantInt::getSigned(ExpVT, MinExpVal);
+
+ Constant *DoubleMaxExp = ConstantInt::getSigned(ExpVT, 2 * MaxExpVal);
+
+ const APFloat One(FltSem, "1.0");
----------------
arsenm wrote:
```suggestion
const APFloat One = APFloat::getOne(FltSem);
```
https://github.com/llvm/llvm-project/pull/208556
More information about the llvm-commits
mailing list