[llvm] [InstCombine] optimize powi(X,Y)/X with Ofast (PR #67236)
Nikita Popov via llvm-commits
llvm-commits at lists.llvm.org
Fri Oct 20 02:46:41 PDT 2023
================
@@ -1764,6 +1764,22 @@ 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)))) &&
+ computeOverflowForSignedSub(Y, ConstantInt::get(Y->getType(), 1), &I) ==
+ OverflowResult::NeverOverflows) {
----------------
nikic wrote:
```suggestion
willNotOverflowSignedSub(Y, ConstantInt::get(Y->getType(), 1), &I)) {
```
https://github.com/llvm/llvm-project/pull/67236
More information about the llvm-commits
mailing list