[llvm] [InstCombine] fold `ldexp(x, zext(i1 y))` to `fmul x, (select y, 2.0, 1.0)` (PR #94887)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 9 05:40:37 PDT 2024
================
@@ -2618,6 +2618,18 @@ Instruction *InstCombinerImpl::visitCallInst(CallInst &CI) {
}
}
+ // ldexp(x, zext(i1 y)) -> fmul x, (select y, 2.0, 1.0)
+ Value *ExtSrc;
+ if (match(Exp, m_ZExt(m_Value(ExtSrc))) &&
+ ExtSrc->getType()->getScalarSizeInBits() == 1) {
+ Value *Cmp = Builder.CreateICmp(
+ ICmpInst::ICMP_NE, ExtSrc, Constant::getNullValue(ExtSrc->getType()));
+ Value *Select =
+ Builder.CreateSelect(Cmp, ConstantFP::get(II->getType(), 2.0),
+ ConstantFP::get(II->getType(), 1.0));
----------------
c8ef wrote:
I get it. Thanks for your suggestion!
https://github.com/llvm/llvm-project/pull/94887
More information about the llvm-commits
mailing list