[llvm] 92ae2ca - [SLP][NFC]Improve BottomTopTop reordering of orders for multi-iterations
Alexey Bataev via llvm-commits
llvm-commits at lists.llvm.org
Thu Jan 25 13:06:49 PST 2024
Author: Alexey Bataev
Date: 2024-01-25T13:04:01-08:00
New Revision: 92ae2ca12be58dd581084f6d952c2158b6fd42aa
URL: https://github.com/llvm/llvm-project/commit/92ae2ca12be58dd581084f6d952c2158b6fd42aa
DIFF: https://github.com/llvm/llvm-project/commit/92ae2ca12be58dd581084f6d952c2158b6fd42aa.diff
LOG: [SLP][NFC]Improve BottomTopTop reordering of orders for multi-iterations
attempts, NFC.
If several iterations of reodering of orders is required, need to use
different algorithm.
Added:
Modified:
llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
Removed:
################################################################################
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 273229de67df62..7ecf3b244ad2b6 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -3732,22 +3732,45 @@ static void reorderReuses(SmallVectorImpl<int> &Reuses, ArrayRef<int> Mask) {
/// the original order of the scalars. Procedure transforms the provided order
/// in accordance with the given \p Mask. If the resulting \p Order is just an
/// identity order, \p Order is cleared.
-static void reorderOrder(SmallVectorImpl<unsigned> &Order, ArrayRef<int> Mask) {
+static void reorderOrder(SmallVectorImpl<unsigned> &Order, ArrayRef<int> Mask,
+ bool BottomOrder = false) {
assert(!Mask.empty() && "Expected non-empty mask.");
+ unsigned Sz = Mask.size();
+ if (BottomOrder) {
+ SmallVector<unsigned> PrevOrder;
+ if (Order.empty()) {
+ PrevOrder.resize(Sz);
+ std::iota(PrevOrder.begin(), PrevOrder.end(), 0);
+ } else {
+ PrevOrder.swap(Order);
+ }
+ Order.assign(Sz, Sz);
+ for (unsigned I = 0; I < Sz; ++I)
+ if (Mask[I] != PoisonMaskElem)
+ Order[I] = PrevOrder[Mask[I]];
+ if (all_of(enumerate(Order), [&](const auto &Data) {
+ return Data.value() == Sz || Data.index() == Data.value();
+ })) {
+ Order.clear();
+ return;
+ }
+ fixupOrderingIndices(Order);
+ return;
+ }
SmallVector<int> MaskOrder;
if (Order.empty()) {
- MaskOrder.resize(Mask.size());
+ MaskOrder.resize(Sz);
std::iota(MaskOrder.begin(), MaskOrder.end(), 0);
} else {
inversePermutation(Order, MaskOrder);
}
reorderReuses(MaskOrder, Mask);
- if (ShuffleVectorInst::isIdentityMask(MaskOrder, MaskOrder.size())) {
+ if (ShuffleVectorInst::isIdentityMask(MaskOrder, Sz)) {
Order.clear();
return;
}
- Order.assign(Mask.size(), Mask.size());
- for (unsigned I = 0, E = Mask.size(); I < E; ++I)
+ Order.assign(Sz, Sz);
+ for (unsigned I = 0; I < Sz; ++I)
if (MaskOrder[I] != PoisonMaskElem)
Order[MaskOrder[I]] = I;
fixupOrderingIndices(Order);
@@ -4880,7 +4903,8 @@ void BoUpSLP::reorderBottomToTop(bool IgnoreReorder) {
Data.first->isAltShuffle() ||
Data.first->State == TreeEntry::PossibleStridedVectorize) {
reorderScalars(Data.first->Scalars, Mask);
- reorderOrder(Data.first->ReorderIndices, MaskOrder);
+ reorderOrder(Data.first->ReorderIndices, MaskOrder,
+ /*BottomOrder=*/true);
if (Data.first->ReuseShuffleIndices.empty() &&
!Data.first->ReorderIndices.empty() &&
!Data.first->isAltShuffle()) {
@@ -4889,7 +4913,7 @@ void BoUpSLP::reorderBottomToTop(bool IgnoreReorder) {
OrderedEntries.insert(Data.first);
}
} else {
- reorderOrder(Data.first->ReorderIndices, Mask);
+ reorderOrder(Data.first->ReorderIndices, Mask, /*BottomOrder=*/true);
}
}
}
More information about the llvm-commits
mailing list