[llvm] [InstCombine] optimize powi(X,Y)/X with Ofast (PR #67236)

Yingwei Zheng via llvm-commits llvm-commits at lists.llvm.org
Mon Oct 16 22:49:38 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::getAllOnesValue(Y->getType()),
----------------
dtcxzyw wrote:

```suggestion
      computeOverflowForSignedSub(Y, ConstantInt::get(Y->getType(), 1),
```
Apologize for my mistake.


https://github.com/llvm/llvm-project/pull/67236


More information about the llvm-commits mailing list