Skip to content

Commit 884d7c1

Browse files
committed
Revert "[SLP]Check for the whole vector vectorization in unique scalars analysis"
This reverts commit b74e09c after post-commit review. The number of parts is calculated incorrectly.
1 parent 24b6b82 commit 884d7c1

File tree

2 files changed

+14
-78
lines changed

2 files changed

+14
-78
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -408,7 +408,7 @@ static bool isVectorLikeInstWithConstOps(Value *V) {
408408
/// total number of elements \p Size and number of registers (parts) \p
409409
/// NumParts.
410410
static unsigned getPartNumElems(unsigned Size, unsigned NumParts) {
411-
return std::min<unsigned>(Size, PowerOf2Ceil(divideCeil(Size, NumParts)));
411+
return PowerOf2Ceil(divideCeil(Size, NumParts));
412412
}
413413

414414
/// Returns correct remaining number of elements, considering total amount \p
@@ -7021,11 +7021,7 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
70217021
UniqueValues.emplace_back(V);
70227022
}
70237023
size_t NumUniqueScalarValues = UniqueValues.size();
7024-
bool IsFullVectors =
7025-
hasFullVectorsOnly(*TTI, UniqueValues.front()->getType(),
7026-
NumUniqueScalarValues);
7027-
if (NumUniqueScalarValues == VL.size() &&
7028-
(VectorizeNonPowerOf2 || IsFullVectors)) {
7024+
if (NumUniqueScalarValues == VL.size()) {
70297025
ReuseShuffleIndices.clear();
70307026
} else {
70317027
// FIXME: Reshuffing scalars is not supported yet for non-power-of-2 ops.
@@ -7036,10 +7032,14 @@ void BoUpSLP::buildTree_rec(ArrayRef<Value *> VL, unsigned Depth,
70367032
return false;
70377033
}
70387034
LLVM_DEBUG(dbgs() << "SLP: Shuffle for reused scalars.\n");
7039-
if (NumUniqueScalarValues <= 1 || !IsFullVectors ||
7040-
(UniquePositions.size() == 1 && all_of(UniqueValues, [](Value *V) {
7041-
return isa<UndefValue>(V) || !isConstant(V);
7042-
}))) {
7035+
if (NumUniqueScalarValues <= 1 ||
7036+
(UniquePositions.size() == 1 && all_of(UniqueValues,
7037+
[](Value *V) {
7038+
return isa<UndefValue>(V) ||
7039+
!isConstant(V);
7040+
})) ||
7041+
!hasFullVectorsOnly(*TTI, UniqueValues.front()->getType(),
7042+
NumUniqueScalarValues)) {
70437043
if (DoNotFail && UniquePositions.size() > 1 &&
70447044
NumUniqueScalarValues > 1 && S.MainOp->isSafeToRemove() &&
70457045
all_of(UniqueValues, [=](Value *V) {
@@ -9143,6 +9143,9 @@ class BoUpSLP::ShuffleCostEstimator : public BaseShuffleAnalysis {
91439143
return nullptr;
91449144
Value *VecBase = nullptr;
91459145
ArrayRef<Value *> VL = E->Scalars;
9146+
// If the resulting type is scalarized, do not adjust the cost.
9147+
if (NumParts == VL.size())
9148+
return nullptr;
91469149
// Check if it can be considered reused if same extractelements were
91479150
// vectorized already.
91489151
bool PrevNodeFound = any_of(
@@ -9795,7 +9798,7 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
97959798
InsertMask[Idx] = I + 1;
97969799
}
97979800
unsigned VecScalarsSz = PowerOf2Ceil(NumElts);
9798-
if (NumOfParts > 0 && NumOfParts < NumElts)
9801+
if (NumOfParts > 0)
97999802
VecScalarsSz = PowerOf2Ceil((NumElts + NumOfParts - 1) / NumOfParts);
98009803
unsigned VecSz = (1 + OffsetEnd / VecScalarsSz - OffsetBeg / VecScalarsSz) *
98019804
VecScalarsSz;

llvm/test/Transforms/SLPVectorizer/RISCV/unique-loads-insert-non-power-of-2.ll

Lines changed: 0 additions & 67 deletions
This file was deleted.

0 commit comments

Comments
 (0)