-
Notifications
You must be signed in to change notification settings - Fork 14.3k
[SLP] Enable reordering for non-power-of-two vectors #106638
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
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3388,6 +3388,10 @@ class BoUpSLP { | |
TreeEntry *Last = VectorizableTree.back().get(); | ||
Last->Idx = VectorizableTree.size() - 1; | ||
Last->State = EntryState; | ||
// FIXME: Remove once support for ReuseShuffleIndices has been implemented | ||
// for non-power-of-two vectors. | ||
assert((has_single_bit(VL.size()) || ReuseShuffleIndices.empty()) && | ||
"Reshuffling scalars not yet supported for nodes with padding"); | ||
Last->ReuseShuffleIndices.append(ReuseShuffleIndices.begin(), | ||
ReuseShuffleIndices.end()); | ||
if (ReorderIndices.empty()) { | ||
|
@@ -3452,11 +3456,8 @@ class BoUpSLP { | |
MustGather.insert(VL.begin(), VL.end()); | ||
} | ||
|
||
if (UserTreeIdx.UserTE) { | ||
if (UserTreeIdx.UserTE) | ||
Last->UserTreeIndices.push_back(UserTreeIdx); | ||
assert((!Last->isNonPowOf2Vec() || Last->ReorderIndices.empty()) && | ||
"Reordering isn't implemented for non-power-of-2 nodes yet"); | ||
} | ||
return Last; | ||
} | ||
|
||
|
@@ -4731,12 +4732,6 @@ BoUpSLP::LoadsState BoUpSLP::canVectorizeLoads( | |
auto *VecTy = getWidenedType(ScalarTy, Sz); | ||
// Check the order of pointer operands or that all pointers are the same. | ||
bool IsSorted = sortPtrAccesses(PointerOps, ScalarTy, *DL, *SE, Order); | ||
// FIXME: Reordering isn't implemented for non-power-of-2 nodes yet. | ||
if (!Order.empty() && !has_single_bit(VL.size())) { | ||
assert(VectorizeNonPowerOf2 && "non-power-of-2 number of loads only " | ||
"supported with VectorizeNonPowerOf2"); | ||
return LoadsState::Gather; | ||
} | ||
|
||
Align CommonAlignment = computeCommonAlignment<LoadInst>(VL); | ||
if (!IsSorted && Sz > MinProfitableStridedLoads && TTI->isTypeLegal(VecTy) && | ||
|
@@ -4824,6 +4819,12 @@ BoUpSLP::LoadsState BoUpSLP::canVectorizeLoads( | |
// representation is better than just gather. | ||
auto CheckForShuffledLoads = [&, &TTI = *TTI](Align CommonAlignment, | ||
bool ProfitableGatherPointers) { | ||
// FIXME: The following code has not been updated for non-power-of-2 | ||
// vectors. The splitting logic here does not cover the original | ||
// vector if the vector factor is not a power of two. FIXME | ||
if (!has_single_bit(VL.size())) | ||
return false; | ||
|
||
// Compare masked gather cost and loads + insert subvector costs. | ||
TTI::TargetCostKind CostKind = TTI::TCK_RecipThroughput; | ||
auto [ScalarGEPCost, VectorGEPCost] = | ||
|
@@ -5195,13 +5196,13 @@ static bool areTwoInsertFromSameBuildVector( | |
|
||
std::optional<BoUpSLP::OrdersType> | ||
BoUpSLP::getReorderingData(const TreeEntry &TE, bool TopToBottom) { | ||
// FIXME: Vectorizing is not supported yet for non-power-of-2 ops. | ||
if (TE.isNonPowOf2Vec()) | ||
return std::nullopt; | ||
|
||
// No need to reorder if need to shuffle reuses, still need to shuffle the | ||
// node. | ||
if (!TE.ReuseShuffleIndices.empty()) { | ||
// FIXME: Support ReuseShuffleIndices for non-power-of-two vectors. | ||
assert(!TE.isNonPowOf2Vec() && | ||
"Reshuffling scalars not yet supported for nodes with padding"); | ||
Comment on lines
+5203
to
+5204
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a FIXME |
||
|
||
if (isSplat(TE.Scalars)) | ||
return std::nullopt; | ||
// Check if reuse shuffle indices can be improved by reordering. | ||
|
@@ -5424,11 +5425,15 @@ BoUpSLP::getReorderingData(const TreeEntry &TE, bool TopToBottom) { | |
} | ||
if (isSplat(TE.Scalars)) | ||
return std::nullopt; | ||
if (TE.Scalars.size() >= 4) | ||
if (TE.Scalars.size() >= 3) | ||
if (std::optional<OrdersType> Order = findPartiallyOrderedLoads(TE)) | ||
return Order; | ||
if (std::optional<OrdersType> CurrentOrder = findReusedOrderedScalars(TE)) | ||
return CurrentOrder; | ||
|
||
// FIXME: Remove the non-power-of-two check once findReusedOrderedScalars | ||
// has been auditted for correctness with non-power-of-two vectors. | ||
if (!TE.isNonPowOf2Vec()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a FIXME to remove this check later |
||
if (std::optional<OrdersType> CurrentOrder = findReusedOrderedScalars(TE)) | ||
return CurrentOrder; | ||
} | ||
return std::nullopt; | ||
} | ||
|
@@ -5580,7 +5585,7 @@ void BoUpSLP::reorderTopToBottom() { | |
|
||
// Reorder the graph nodes according to their vectorization factor. | ||
for (unsigned VF = VectorizableTree.front()->getVectorFactor(); VF > 1; | ||
VF /= 2) { | ||
VF = bit_ceil(VF) / 2) { | ||
auto It = VFToOrderedEntries.find(VF); | ||
if (It == VFToOrderedEntries.end()) | ||
continue; | ||
|
@@ -5752,10 +5757,6 @@ bool BoUpSLP::canReorderOperands( | |
TreeEntry *UserTE, SmallVectorImpl<std::pair<unsigned, TreeEntry *>> &Edges, | ||
ArrayRef<TreeEntry *> ReorderableGathers, | ||
SmallVectorImpl<TreeEntry *> &GatherOps) { | ||
// FIXME: Reordering isn't implemented for non-power-of-2 nodes yet. | ||
if (UserTE->isNonPowOf2Vec()) | ||
return false; | ||
|
||
for (unsigned I = 0, E = UserTE->getNumOperands(); I < E; ++I) { | ||
if (any_of(Edges, [I](const std::pair<unsigned, TreeEntry *> &OpData) { | ||
return OpData.first == I && | ||
|
@@ -5927,9 +5928,6 @@ void BoUpSLP::reorderBottomToTop(bool IgnoreReorder) { | |
} | ||
auto Res = OrdersUses.insert(std::make_pair(OrdersType(), 0)); | ||
const auto AllowsReordering = [&](const TreeEntry *TE) { | ||
// FIXME: Reordering isn't implemented for non-power-of-2 nodes yet. | ||
if (TE->isNonPowOf2Vec()) | ||
return false; | ||
if (!TE->ReorderIndices.empty() || !TE->ReuseShuffleIndices.empty() || | ||
(TE->State == TreeEntry::Vectorize && TE->isAltShuffle()) || | ||
(IgnoreReorder && TE->Idx == 0)) | ||
|
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add a FIXME to remove this later