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

via llvm-commits llvm-commits at lists.llvm.org
Sat Sep 23 06:05:15 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:

How about just CreateBinaryIntrinsic and avoid types array?

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


More information about the llvm-commits mailing list