Skip to content

Commit 83ba148

Browse files
committed
[SLP]Include cost of the reshuffling for same nodes with resizing.
Need to account reshuffling, required for the reused elements in the buildvector nodes, which are copies (perfect match) of other nodes, but include reused elements. Differential Revision: https://reviews.llvm.org/D149966
1 parent 343e204 commit 83ba148

File tree

2 files changed

+23
-2
lines changed

2 files changed

+23
-2
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7006,6 +7006,17 @@ class BoUpSLP::ShuffleCostEstimator : public BaseShuffleAnalysis {
70067006
const TreeEntry *E2 = P2.get<const TreeEntry *>();
70077007
if (E->Scalars.size() == E2->Scalars.size())
70087008
CommonVF = VF = E->Scalars.size();
7009+
} else {
7010+
// P2 is empty, check that we have same node + reshuffle (if any).
7011+
if (E->Scalars.size() == Mask.size() && VF != Mask.size()) {
7012+
VF = E->Scalars.size();
7013+
SmallVector<int> CommonMask(Mask.begin(), Mask.end());
7014+
::addMask(CommonMask, E->getCommonMask());
7015+
V1 = Constant::getNullValue(
7016+
FixedVectorType::get(E->Scalars.front()->getType(), VF));
7017+
return BaseShuffleAnalysis::createShuffle<InstructionCost>(
7018+
V1, nullptr, CommonMask, Builder);
7019+
}
70097020
}
70107021
V1 = Constant::getNullValue(
70117022
FixedVectorType::get(E->Scalars.front()->getType(), VF));
@@ -7286,7 +7297,17 @@ BoUpSLP::getEntryCost(const TreeEntry *E, ArrayRef<Value *> VectorizedVals,
72867297
dbgs()
72877298
<< "SLP: perfect diamond match for gather bundle that starts with "
72887299
<< *VL.front() << ".\n");
7289-
return 0;
7300+
// Restore the mask for previous partially matched values.
7301+
for (auto [I, V] : enumerate(E->Scalars)) {
7302+
if (isa<PoisonValue>(V)) {
7303+
Mask[I] = PoisonMaskElem;
7304+
continue;
7305+
}
7306+
if (Mask[I] == PoisonMaskElem)
7307+
Mask[I] = Entries.front()->findLaneForValue(V);
7308+
}
7309+
Estimator.add(Entries.front(), Mask);
7310+
return Estimator.finalize(E->ReuseShuffleIndices);
72907311
}
72917312
if (!Resized) {
72927313
unsigned VF1 = Entries.front()->getVectorFactor();

llvm/test/Transforms/SLPVectorizer/X86/crash_clear_undefs.ll

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ target datalayout = "e-m:e-p270:32:32-p271:32:32-p272:64:64-i64:64-f80:128-n8:16
99
; YAML-NEXT: Function: foo
1010
; YAML-NEXT: Args:
1111
; YAML-NEXT: - String: 'SLP vectorized with cost '
12-
; YAML-NEXT: - Cost: '-6'
12+
; YAML-NEXT: - Cost: '-5'
1313
; YAML-NEXT: - String: ' and with tree size '
1414
; YAML-NEXT: - TreeSize: '10'
1515
; YAML-NEXT: ...

0 commit comments

Comments
 (0)