diff options
| author | Samuel Tebbs <samuel.tebbs@arm.com> | 2025-10-14 17:26:44 +0100 |
|---|---|---|
| committer | Samuel Tebbs <samuel.tebbs@arm.com> | 2025-10-29 10:06:21 +0000 |
| commit | 7ec2b16f39c07a490db8ada3cc7e49f9d03487aa (patch) | |
| tree | 512bbe9faeb0d223277150d6463723d19b3bcb89 /llvm/lib/Transforms/Vectorize/LoopVectorize.cpp | |
| parent | dda95d90c91cf8c20b00778ee1366d0a9754d704 (diff) | |
[LV] Allow partial reductions with an extended bin opusers/SamTebbs33/partialred-extended-binop
A pattern of the form reduce.add(ext(mul)) is valid for a partial
reduction as long as the mul and its operands fulfill the requirements
of a normal partial reduction. The mul's extend operands will be
optimised to the wider extend, and we already have oneUse checks in
place to make sure the mul and operands can be modified safely.
Diffstat (limited to 'llvm/lib/Transforms/Vectorize/LoopVectorize.cpp')
| -rw-r--r-- | llvm/lib/Transforms/Vectorize/LoopVectorize.cpp | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp index f7968abbe5b6..f83fe82c2dfb 100644 --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -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())))) + Op = cast<Instruction>(Op)->getOperand(0); + // Try and get a scaled reduction from the first non-phi operand. // If one is found, we use the discovered reduction instruction in // place of the accumulator for costing. @@ -7962,8 +7971,6 @@ bool VPRecipeBuilder::getScaledReductions( if (PhiOp != PHI) return false; - using namespace llvm::PatternMatch; - // If the update is a binary operator, check both of its operands to see if // they are extends. Otherwise, see if the update comes directly from an // extend. |
