[llvm] [InstCombine] optimize powi(X,Y)/X with Ofast (PR #67236)
via llvm-commits
llvm-commits at lists.llvm.org
Sun Sep 24 06:20:43 PDT 2023
================
@@ -1764,6 +1764,16 @@ Instruction *InstCombinerImpl::visitFDiv(BinaryOperator &I) {
return replaceInstUsesWith(I, Pow);
}
+ if (I.hasAllowReassoc() && I.hasNoInfs() &&
+ match(Op0, m_OneUse(m_Intrinsic<Intrinsic::powi>(m_Specific(Op1),
+ m_Value(Y))))) {
+ Constant *NegOne = ConstantInt::getAllOnesValue(Y->getType());
+ Value *Y1 = Builder.CreateAdd(Y, NegOne);
+ Type *Types[] = {Op1->getType(), Y1->getType()};
+ Value *Pow = Builder.CreateIntrinsic(Intrinsic::powi, Types, {Op1, Y1}, &I);
+ return replaceInstUsesWith(I, Pow);
----------------
goldsteinn wrote:
> It will crash with **ArrayRef.h:257: Assertion `Index < Length && "Invalid index!"' failed** when I change it to
>
> ```
> Value *Pow = Builder.CreateBinaryIntrinsic(Intrinsic::powi, Op1, Y1, &I);
> ```
Its properly invalid, I forgot different types :(
https://github.com/llvm/llvm-project/pull/67236
More information about the llvm-commits
mailing list