[llvm] [SLP][REVEC] Make tryToReduce and related functions support vector instructions. (PR #102327)
Alexey Bataev via llvm-commits
llvm-commits at lists.llvm.org
Wed Aug 7 09:29:35 PDT 2024
================
@@ -17710,8 +17710,25 @@ class HorizontalReduction {
SameValuesCounter, TrackedToOrig);
}
- Value *ReducedSubTree =
- emitReduction(VectorizedRoot, Builder, ReduxWidth, TTI);
+ Value *ReducedSubTree;
+ Type *ScalarTy = VL.front()->getType();
+ if (isa<FixedVectorType>(ScalarTy)) {
+ assert(SLPReVec && "FixedVectorType is not expected.");
+ unsigned ScalarTyNumElements = getNumElements(ScalarTy);
+ ReducedSubTree = PoisonValue::get(FixedVectorType::get(
+ VectorizedRoot->getType()->getScalarType(), ScalarTyNumElements));
+ for (unsigned I = 0; I != ScalarTyNumElements; ++I) {
+ // Do reduction for each lane.
+ SmallVector<int, 16> Mask =
+ createStrideMask(I, ScalarTyNumElements, VL.size());
+ Value *Lane = Builder.CreateShuffleVector(VectorizedRoot, Mask);
+ ReducedSubTree = Builder.CreateInsertElement(
+ ReducedSubTree, emitReduction(Lane, Builder, ReduxWidth, TTI),
+ I);
+ }
+ } else
+ ReducedSubTree =
+ emitReduction(VectorizedRoot, Builder, ReduxWidth, TTI);
----------------
alexey-bataev wrote:
Enclose in braces
https://github.com/llvm/llvm-project/pull/102327
More information about the llvm-commits
mailing list