[llvm] [LV] Allow partial reductions with an extended bin op (PR #165536)

Sam Tebbs via llvm-commits llvm-commits at lists.llvm.org
Tue Nov 4 02:09:29 PST 2025


================
@@ -7946,6 +7946,15 @@ bool VPRecipeBuilder::getScaledReductions(
   if (Op == PHI)
     std::swap(Op, PhiOp);
 
+  using namespace llvm::PatternMatch;
+  // If Op is an extend, then it's still a valid partial reduction if the
+  // extended mul fulfills the other requirements.
+  // For example, reduce.add(ext(mul(ext(A), ext(B)))) is still a valid partial
+  // reduction since the inner extends will be widened. We already have oneUse
+  // checks on the inner extends so widening them is safe.
+  if (match(Op, m_ZExtOrSExt(m_Mul(m_Value(), m_Value()))))
----------------
SamTebbs33 wrote:

We don't need to check what the operands are since the later checks in this function do that, but that does make me realise that we need to make sure the outer extend is compatible with the inner extends (i.e. the outer is sext or the same as the inner extends).

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


More information about the llvm-commits mailing list