[llvm] [InstCombine] fold `ldexp(x, zext(i1 y))` to `fmul x, (select y, 2.0, 1.0)` (PR #94887)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Sun Jun 9 01:27:22 PDT 2024
================
@@ -2618,6 +2618,19 @@ 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()));
+ SelectInst *Select = SelectInst::Create(
+ Cmp, ConstantFP::get(Type::getFloatTy(II->getContext()), 2.0),
+ ConstantFP::get(Type::getFloatTy(II->getContext()), 1.0));
+ Builder.Insert(Select);
----------------
dtcxzyw wrote:
1. Use `Builder.CreateSelect` instead.
2. Use `II->getType()` instead of `Type::getFloatTy`.
3. Please provide alive2 proofs
4. Please add double tests and vector tests.
https://github.com/llvm/llvm-project/pull/94887
More information about the llvm-commits
mailing list