[llvm] [SLP][NFC] Minor code simplifications (PR #149029)
Piotr Fusik via llvm-commits
llvm-commits at lists.llvm.org
Wed Jul 16 00:18:25 PDT 2025
https://github.com/pfusik created https://github.com/llvm/llvm-project/pull/149029
None
>From b789116e8b72dcd1b9bcb0968cd61cff0eb94768 Mon Sep 17 00:00:00 2001
From: Piotr Fusik <p.fusik at samsung.com>
Date: Wed, 16 Jul 2025 09:17:30 +0200
Subject: [PATCH] [SLP][NFC] Minor code simplifications
---
.../Transforms/Vectorize/SLPVectorizer.cpp | 23 ++++++++-----------
1 file changed, 10 insertions(+), 13 deletions(-)
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.
More information about the llvm-commits
mailing list