Skip to content

Commit

Permalink
[SLP] Improve horizontal vectorization for non-power-of-2 number of
Browse files Browse the repository at this point in the history
instructions.

If number of instructions in horizontal reduction list is not power of 2
then only PowerOf2Floor(NumberOfInstructions) last elements are actually
vectorized, other instructions remain scalar. Patch tries to vectorize
the remaining elements either.

Differential Revision: https://reviews.llvm.org/D28959

llvm-svn: 293042
  • Loading branch information
alexey-bataev committed Jan 25, 2017
1 parent 16f1e5f commit d28ab55
Show file tree
Hide file tree
Showing 2 changed files with 76 additions and 100 deletions.
6 changes: 4 additions & 2 deletions llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
Expand Up @@ -4262,15 +4262,15 @@ class HorizontalReduction {
Builder.setFastMathFlags(Unsafe);
unsigned i = 0;

for (; i < NumReducedVals - ReduxWidth + 1; i += ReduxWidth) {
while (i < NumReducedVals - ReduxWidth + 1 && ReduxWidth > 2) {
auto VL = makeArrayRef(&ReducedVals[i], ReduxWidth);
V.buildTree(VL, ReductionOps);
if (V.shouldReorder()) {
SmallVector<Value *, 8> Reversed(VL.rbegin(), VL.rend());
V.buildTree(Reversed, ReductionOps);
}
if (V.isTreeTinyAndNotFullyVectorizable())
continue;
break;

V.computeMinimumValueSizes();

Expand All @@ -4296,6 +4296,8 @@ class HorizontalReduction {
ReducedSubTree, "bin.rdx");
} else
VectorizedTree = ReducedSubTree;
i += ReduxWidth;
ReduxWidth = PowerOf2Floor(NumReducedVals - i);
}

if (VectorizedTree) {
Expand Down

0 comments on commit d28ab55

Please sign in to comment.