[llvm] [InstCombine] optimize powi(X,Y) * X with Ofast (PR #69998)

Matt Arsenault via llvm-commits llvm-commits at lists.llvm.org
Wed Mar 6 22:46:10 PST 2024


================
@@ -572,37 +572,35 @@ Instruction *InstCombinerImpl::foldFPSignBitOps(BinaryOperator &I) {
 }
 
 Instruction *InstCombinerImpl::foldPowiReassoc(BinaryOperator &I) {
-  Value *X, *Y, *Z;
   auto createPowiExpr = [](BinaryOperator &I, InstCombinerImpl &IC, Value *X,
                            Value *Y, Value *Z) {
-    Value *YZ;
     InstCombiner::BuilderTy &Builder = IC.Builder;
-
-    if (auto *C = dyn_cast<ConstantInt>(Z)) {
-      if (C->isOne())
-        YZ = Builder.CreateAdd(Y, ConstantInt::get(Y->getType(), 1));
-    } else
-      YZ = Builder.CreateAdd(Y, Z);
-
+    Value *YZ = Builder.CreateAdd(Y, Z);
     auto *NewPow = Builder.CreateIntrinsic(
         Intrinsic::powi, {X->getType(), YZ->getType()}, {X, YZ}, &I);
     return IC.replaceInstUsesWith(I, NewPow);
   };
 
+  Value *X, *Y, *Z;
+
   // powi(X, Y) * X --> powi(X, Y+1)
   // X * powi(X, Y) --> powi(X, Y+1)
-  if (match(&I, m_c_FMul(m_OneUse(m_Intrinsic<Intrinsic::powi>(m_Value(X),
-                                                               m_Value(Y))),
-                         m_Deferred(X))) &&
-      willNotOverflowSignedAdd(Y, ConstantInt::get(Y->getType(), 1), I))
-    return createPowiExpr(I, *this, X, Y, ConstantInt::get(Y->getType(), 1));
+  if (match(&I, m_c_FMul(m_AllowReassoc(m_OneUse(m_Intrinsic<Intrinsic::powi>(
----------------
arsenm wrote:

the m_AllowReassoc should be paired with the m_Intrinsic part, not after the oneUse 

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


More information about the llvm-commits mailing list