Skip to content

[SLP] Compute a shuffle mask for SK_InsertSubvector #85408

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Mar 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 11 additions & 4 deletions llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4328,9 +4328,12 @@ BoUpSLP::LoadsState BoUpSLP::canVectorizeLoads(
llvm_unreachable(
"Expected only consecutive, strided or masked gather loads.");
}
SmallVector<int> ShuffleMask(VL.size());
for (int Idx : seq<int>(0, VL.size()))
ShuffleMask[Idx] = Idx / VF == I ? VL.size() + Idx % VF : Idx;
VecLdCost +=
TTI.getShuffleCost(TTI ::SK_InsertSubvector, VecTy,
std::nullopt, CostKind, I * VF, SubVecTy);
ShuffleMask, CostKind, I * VF, SubVecTy);
}
// If masked gather cost is higher - better to vectorize, so
// consider it as a gather node. It will be better estimated
Expand Down Expand Up @@ -7454,7 +7457,7 @@ getShuffleCost(const TargetTransformInfo &TTI, TTI::ShuffleKind Kind,
Index + NumSrcElts <= static_cast<int>(Mask.size()))
return TTI.getShuffleCost(
TTI::SK_InsertSubvector,
FixedVectorType::get(Tp->getElementType(), Mask.size()), std::nullopt,
FixedVectorType::get(Tp->getElementType(), Mask.size()), Mask,
TTI::TCK_RecipThroughput, Index, Tp);
}
return TTI.getShuffleCost(Kind, Tp, Mask, CostKind, Index, SubTp, Args);
Expand Down Expand Up @@ -7727,9 +7730,13 @@ class BoUpSLP::ShuffleCostEstimator : public BaseShuffleAnalysis {
}
if (NeedInsertSubvectorAnalysis) {
// Add the cost for the subvectors insert.
for (int I = VF, E = VL.size(); I < E; I += VF)
SmallVector<int> ShuffleMask(VL.size());
for (int I = VF, E = VL.size(); I < E; I += VF) {
for (int Idx : seq<int>(0, E))
ShuffleMask[Idx] = Idx / VF == I ? E + Idx % VF : Idx;
GatherCost += TTI.getShuffleCost(TTI::SK_InsertSubvector, VecTy,
std::nullopt, CostKind, I, LoadTy);
ShuffleMask, CostKind, I, LoadTy);
}
}
GatherCost -= ScalarsCost;
}
Expand Down