[llvm] [VectorCombine] Fold binary op of reductions. (PR #121567)

Simon Pilgrim via llvm-commits llvm-commits at lists.llvm.org
Wed Jan 29 08:11:49 PST 2025


================
@@ -1182,6 +1189,62 @@ bool VectorCombine::foldExtractedCmps(Instruction &I) {
   return true;
 }
 
+bool VectorCombine::foldBinopOfReductions(Instruction &I) {
+  Instruction::BinaryOps BinOpOpc = cast<BinaryOperator>(&I)->getOpcode();
+  Intrinsic::ID ReductionIID = getReductionForBinop(BinOpOpc);
+  if (BinOpOpc == Instruction::Sub)
+    ReductionIID = Intrinsic::vector_reduce_add;
+  if (ReductionIID == Intrinsic::not_intrinsic)
+    return false;
+
+  auto checkIntrinsicAndGetItsArgument = [](Value *V,
+                                            Intrinsic::ID IID) -> Value * {
+    IntrinsicInst *II = dyn_cast<IntrinsicInst>(V);
+    if (!II)
+      return nullptr;
+    if (II->getIntrinsicID() == IID && II->hasOneUse())
+      return II->getArgOperand(0);
+    return nullptr;
----------------
RKSimon wrote:

This would be a lot simpler if m_Intrinsic wasn't limited to matching IID as a template arg :( 

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


More information about the llvm-commits mailing list