-
Notifications
You must be signed in to change notification settings - Fork 15.1k
[SLP][NFC] Use range-based for in matchAssociativeReduction
#149029
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
Conversation
|
@llvm/pr-subscribers-vectorizers Author: Piotr Fusik (pfusik) ChangesFull diff: https://github.com/llvm/llvm-project/pull/149029.diff 1 Files Affected:
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 87de28044b2ae..9bc30a4895f7a 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -5540,8 +5540,7 @@ BoUpSLP::findReusedOrderedScalars(const BoUpSLP::TreeEntry &TE,
return std::max(Entries[I].front()->getVectorFactor(),
Entries[I].back()->getVectorFactor());
});
- unsigned NumUndefs =
- count_if(CurrentOrder, [&](unsigned Idx) { return Idx == NumScalars; });
+ unsigned NumUndefs = count(CurrentOrder, NumScalars);
if (ShuffledSubMasks.all() || (NumScalars > 2 && NumUndefs >= NumScalars / 2))
return std::nullopt;
return std::move(CurrentOrder);
@@ -8623,11 +8622,10 @@ void BoUpSLP::tryToVectorizeGatheredLoads(
State == LoadsState::CompressVectorize)
return false;
ConsecutiveNodesSize += VL.size();
- unsigned Start = std::distance(Slice.begin(), It);
- unsigned Sz = Slice.size() - Start;
+ size_t Start = std::distance(Slice.begin(), It);
+ size_t Sz = Slice.size() - Start;
return Sz < VL.size() ||
- Slice.slice(std::distance(Slice.begin(), It),
- VL.size()) != VL;
+ Slice.slice(Start, VL.size()) != VL;
}))
continue;
// Try to build long masked gather loads.
@@ -22140,7 +22138,7 @@ class HorizontalReduction {
// Try to regroup reduced values so that it gets more profitable to try to
// reduce them. Values are grouped by their value ids, instructions - by
// instruction op id and/or alternate op id, plus do extra analysis for
- // loads (grouping them by the distabce between pointers) and cmp
+ // loads (grouping them by the distance between pointers) and cmp
// instructions (grouping them by the predicate).
SmallMapVector<
size_t, SmallMapVector<size_t, SmallMapVector<Value *, unsigned, 2>, 2>,
@@ -22207,10 +22205,9 @@ class HorizontalReduction {
for (auto &PossibleReducedVals : PossibleReducedValsVect) {
auto PossibleRedVals = PossibleReducedVals.second.takeVector();
SmallVector<SmallVector<Value *>> PossibleRedValsVect;
- for (auto It = PossibleRedVals.begin(), E = PossibleRedVals.end();
- It != E; ++It) {
+ for (auto &It : PossibleRedVals) {
PossibleRedValsVect.emplace_back();
- auto RedValsVect = It->second.takeVector();
+ auto RedValsVect = It.second.takeVector();
stable_sort(RedValsVect, llvm::less_second());
for (const std::pair<Value *, unsigned> &Data : RedValsVect)
PossibleRedValsVect.back().append(Data.second, Data.first);
@@ -22370,8 +22367,8 @@ class HorizontalReduction {
SmallVector<Value *> Candidates;
Candidates.reserve(2 * OrigReducedVals.size());
DenseMap<Value *, Value *> TrackedToOrig(2 * OrigReducedVals.size());
- for (unsigned Cnt = 0, Sz = OrigReducedVals.size(); Cnt < Sz; ++Cnt) {
- Value *RdxVal = TrackedVals.at(OrigReducedVals[Cnt]);
+ for (Value *ReducedVal : OrigReducedVals) {
+ Value *RdxVal = TrackedVals.at(ReducedVal);
// Check if the reduction value was not overriden by the extractelement
// instruction because of the vectorization and exclude it, if it is not
// compatible with other values.
@@ -22382,7 +22379,7 @@ class HorizontalReduction {
(S && !Inst))
continue;
Candidates.push_back(RdxVal);
- TrackedToOrig.try_emplace(RdxVal, OrigReducedVals[Cnt]);
+ TrackedToOrig.try_emplace(RdxVal, ReducedVal);
}
bool ShuffledExtracts = false;
// Try to handle shuffled extractelements.
|
|
@llvm/pr-subscribers-llvm-transforms Author: Piotr Fusik (pfusik) ChangesFull diff: https://github.com/llvm/llvm-project/pull/149029.diff 1 Files Affected:
diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 87de28044b2ae..9bc30a4895f7a 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -5540,8 +5540,7 @@ BoUpSLP::findReusedOrderedScalars(const BoUpSLP::TreeEntry &TE,
return std::max(Entries[I].front()->getVectorFactor(),
Entries[I].back()->getVectorFactor());
});
- unsigned NumUndefs =
- count_if(CurrentOrder, [&](unsigned Idx) { return Idx == NumScalars; });
+ unsigned NumUndefs = count(CurrentOrder, NumScalars);
if (ShuffledSubMasks.all() || (NumScalars > 2 && NumUndefs >= NumScalars / 2))
return std::nullopt;
return std::move(CurrentOrder);
@@ -8623,11 +8622,10 @@ void BoUpSLP::tryToVectorizeGatheredLoads(
State == LoadsState::CompressVectorize)
return false;
ConsecutiveNodesSize += VL.size();
- unsigned Start = std::distance(Slice.begin(), It);
- unsigned Sz = Slice.size() - Start;
+ size_t Start = std::distance(Slice.begin(), It);
+ size_t Sz = Slice.size() - Start;
return Sz < VL.size() ||
- Slice.slice(std::distance(Slice.begin(), It),
- VL.size()) != VL;
+ Slice.slice(Start, VL.size()) != VL;
}))
continue;
// Try to build long masked gather loads.
@@ -22140,7 +22138,7 @@ class HorizontalReduction {
// Try to regroup reduced values so that it gets more profitable to try to
// reduce them. Values are grouped by their value ids, instructions - by
// instruction op id and/or alternate op id, plus do extra analysis for
- // loads (grouping them by the distabce between pointers) and cmp
+ // loads (grouping them by the distance between pointers) and cmp
// instructions (grouping them by the predicate).
SmallMapVector<
size_t, SmallMapVector<size_t, SmallMapVector<Value *, unsigned, 2>, 2>,
@@ -22207,10 +22205,9 @@ class HorizontalReduction {
for (auto &PossibleReducedVals : PossibleReducedValsVect) {
auto PossibleRedVals = PossibleReducedVals.second.takeVector();
SmallVector<SmallVector<Value *>> PossibleRedValsVect;
- for (auto It = PossibleRedVals.begin(), E = PossibleRedVals.end();
- It != E; ++It) {
+ for (auto &It : PossibleRedVals) {
PossibleRedValsVect.emplace_back();
- auto RedValsVect = It->second.takeVector();
+ auto RedValsVect = It.second.takeVector();
stable_sort(RedValsVect, llvm::less_second());
for (const std::pair<Value *, unsigned> &Data : RedValsVect)
PossibleRedValsVect.back().append(Data.second, Data.first);
@@ -22370,8 +22367,8 @@ class HorizontalReduction {
SmallVector<Value *> Candidates;
Candidates.reserve(2 * OrigReducedVals.size());
DenseMap<Value *, Value *> TrackedToOrig(2 * OrigReducedVals.size());
- for (unsigned Cnt = 0, Sz = OrigReducedVals.size(); Cnt < Sz; ++Cnt) {
- Value *RdxVal = TrackedVals.at(OrigReducedVals[Cnt]);
+ for (Value *ReducedVal : OrigReducedVals) {
+ Value *RdxVal = TrackedVals.at(ReducedVal);
// Check if the reduction value was not overriden by the extractelement
// instruction because of the vectorization and exclude it, if it is not
// compatible with other values.
@@ -22382,7 +22379,7 @@ class HorizontalReduction {
(S && !Inst))
continue;
Candidates.push_back(RdxVal);
- TrackedToOrig.try_emplace(RdxVal, OrigReducedVals[Cnt]);
+ TrackedToOrig.try_emplace(RdxVal, ReducedVal);
}
bool ShuffledExtracts = false;
// Try to handle shuffled extractelements.
|
| SmallVector<SmallVector<Value *>> PossibleRedValsVect; | ||
| for (auto It = PossibleRedVals.begin(), E = PossibleRedVals.end(); | ||
| It != E; ++It) { | ||
| for (auto &It : PossibleRedVals) { |
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.
It->Slice? Or something else
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.
Done
|
Also, split changes in the different functions into separate patches, if possible |
for in matchAssociativeReduction
No description provided.