[llvm] [LoopVectorizer] Add support for partial reductions (PR #92418)
Graham Hunter via llvm-commits
llvm-commits at lists.llvm.org
Fri Sep 13 03:25:48 PDT 2024
================
@@ -1556,7 +1556,105 @@ class LoopVectorizationCostModel {
getReductionPatternCost(Instruction *I, ElementCount VF, Type *VectorTy,
TTI::TargetCostKind CostKind) const;
+ using PartialReductionList = DenseMap<Instruction *, PartialReductionChain>;
+
+ PartialReductionList getPartialReductionChains() {
+ return PartialReductionChains;
+ }
+
+ bool getInstructionsPartialReduction(Instruction *I,
+ PartialReductionChain &Chain) const {
+ auto PairIt = PartialReductionChains.find(I);
+ if (PairIt == PartialReductionChains.end())
+ return false;
+ Chain = PairIt->second;
+ return true;
+ }
+
+ void addPartialReductionIfSupported(Instruction *Instr, ElementCount VF) {
+ Value *ExpectedPhi;
+ Value *A, *B;
+
+ using namespace llvm::PatternMatch;
+ auto Pattern =
+ m_BinOp(m_OneUse(m_BinOp(m_OneUse(m_ZExtOrSExt(m_OneUse(m_Value(A)))),
+ m_OneUse(m_ZExtOrSExt(m_OneUse(m_Value(B)))))),
----------------
huntergr-arm wrote:
If it's not too much work then we can support the extra matching, but if it turns out to require a lot more work I think I'd prefer to land it with the current restrictions and implement the extra cases in follow-up patches.
You don't need to add the temporaries (`Pattern` and `Matches`) here, you can just call match directly in an if statement.
That said, it may be best to split the matching up a bit; this matcher assumes the phi is always the second argument, but I'm not sure if that's guaranteed.
https://github.com/llvm/llvm-project/pull/92418
More information about the llvm-commits
mailing list