[llvm] [LV] Bundle (partial) reductions with a mul of a constant (PR #162503)
    Sander de Smalen via llvm-commits 
    llvm-commits at lists.llvm.org
       
    Thu Oct 23 07:19:13 PDT 2025
    
    
  
================
@@ -3668,18 +3701,23 @@ tryToMatchAndCreateMulAccumulateReduction(VPReductionRecipe *Red,
   // variants.
   if (Sub)
     return nullptr;
-  // Match reduce.add(ext(mul(ext(A), ext(B)))).
-  // All extend recipes must have same opcode or A == B
-  // which can be transform to reduce.add(zext(mul(sext(A), sext(B)))).
-  if (match(VecOp, m_ZExtOrSExt(m_Mul(m_ZExtOrSExt(m_VPValue()),
-                                      m_ZExtOrSExt(m_VPValue()))))) {
+
+  // Match reduce.add(ext(mul(A, B))).
+  if (match(VecOp, m_ZExtOrSExt(m_Mul(m_VPValue(A), m_VPValue(B))))) {
     auto *Ext = cast<VPWidenCastRecipe>(VecOp->getDefiningRecipe());
     auto *Mul = cast<VPWidenRecipe>(Ext->getOperand(0)->getDefiningRecipe());
-    auto *Ext0 =
-        cast<VPWidenCastRecipe>(Mul->getOperand(0)->getDefiningRecipe());
-    auto *Ext1 =
-        cast<VPWidenCastRecipe>(Mul->getOperand(1)->getDefiningRecipe());
-    if ((Ext->getOpcode() == Ext0->getOpcode() || Ext0 == Ext1) &&
+    auto *Ext0 = dyn_cast_if_present<VPWidenCastRecipe>(A->getDefiningRecipe());
+    auto *Ext1 = dyn_cast_if_present<VPWidenCastRecipe>(B->getDefiningRecipe());
+
+    // Convert reduce.add(ext(mul(ext, const))) to reduce.add(ext(mul(ext,
+    // ext(const))))
----------------
sdesmalen-arm wrote:
nit: unfortunate formatting
```suggestion
    // reduce.add(ext(mul(ext, const)))
    // -> reduce.add(ext(mul(ext, ext(trunc(const)))))
```
https://github.com/llvm/llvm-project/pull/162503
    
    
More information about the llvm-commits
mailing list