[llvm] [InstCombine] optimize powi(X,Y)/X with Ofast (PR #67236)
Yingwei Zheng via llvm-commits
llvm-commits at lists.llvm.org
Thu Oct 12 01:51:33 PDT 2023
================
@@ -1764,6 +1764,20 @@ Instruction *InstCombinerImpl::visitFDiv(BinaryOperator &I) {
return replaceInstUsesWith(I, Pow);
}
+ // powi(X, Y) / X --> powi(X, Y-1)
+ // This is legal when (Y - 1) can't wraparound, in which case reassoc and nnan
+ // are required.
+ // Todo: Multi-use may be also better off creating Powi(x,y-1)
+ if (I.hasAllowReassoc() && I.hasNoNaNs() &&
+ match(Op0, m_OneUse(m_Intrinsic<Intrinsic::powi>(m_Specific(Op1),
+ m_Value(Y))))) {
----------------
dtcxzyw wrote:
Please check overflow for `Y-1` here and add a negative test.
```
&& computeOverflowForSignedSub(Y, ConstantInt::getAllOnesValue(Y->getType()), &I) == OverflowResult::NeverOverflows
```
https://github.com/llvm/llvm-project/pull/67236
More information about the llvm-commits
mailing list