Skip to content

Commit b789116

Browse files
committed
[SLP][NFC] Minor code simplifications
1 parent 8710387 commit b789116

File tree

1 file changed

+10
-13
lines changed

1 file changed

+10
-13
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5540,8 +5540,7 @@ BoUpSLP::findReusedOrderedScalars(const BoUpSLP::TreeEntry &TE,
55405540
return std::max(Entries[I].front()->getVectorFactor(),
55415541
Entries[I].back()->getVectorFactor());
55425542
});
5543-
unsigned NumUndefs =
5544-
count_if(CurrentOrder, [&](unsigned Idx) { return Idx == NumScalars; });
5543+
unsigned NumUndefs = count(CurrentOrder, NumScalars);
55455544
if (ShuffledSubMasks.all() || (NumScalars > 2 && NumUndefs >= NumScalars / 2))
55465545
return std::nullopt;
55475546
return std::move(CurrentOrder);
@@ -8623,11 +8622,10 @@ void BoUpSLP::tryToVectorizeGatheredLoads(
86238622
State == LoadsState::CompressVectorize)
86248623
return false;
86258624
ConsecutiveNodesSize += VL.size();
8626-
unsigned Start = std::distance(Slice.begin(), It);
8627-
unsigned Sz = Slice.size() - Start;
8625+
size_t Start = std::distance(Slice.begin(), It);
8626+
size_t Sz = Slice.size() - Start;
86288627
return Sz < VL.size() ||
8629-
Slice.slice(std::distance(Slice.begin(), It),
8630-
VL.size()) != VL;
8628+
Slice.slice(Start, VL.size()) != VL;
86318629
}))
86328630
continue;
86338631
// Try to build long masked gather loads.
@@ -22140,7 +22138,7 @@ class HorizontalReduction {
2214022138
// Try to regroup reduced values so that it gets more profitable to try to
2214122139
// reduce them. Values are grouped by their value ids, instructions - by
2214222140
// instruction op id and/or alternate op id, plus do extra analysis for
22143-
// loads (grouping them by the distabce between pointers) and cmp
22141+
// loads (grouping them by the distance between pointers) and cmp
2214422142
// instructions (grouping them by the predicate).
2214522143
SmallMapVector<
2214622144
size_t, SmallMapVector<size_t, SmallMapVector<Value *, unsigned, 2>, 2>,
@@ -22207,10 +22205,9 @@ class HorizontalReduction {
2220722205
for (auto &PossibleReducedVals : PossibleReducedValsVect) {
2220822206
auto PossibleRedVals = PossibleReducedVals.second.takeVector();
2220922207
SmallVector<SmallVector<Value *>> PossibleRedValsVect;
22210-
for (auto It = PossibleRedVals.begin(), E = PossibleRedVals.end();
22211-
It != E; ++It) {
22208+
for (auto &It : PossibleRedVals) {
2221222209
PossibleRedValsVect.emplace_back();
22213-
auto RedValsVect = It->second.takeVector();
22210+
auto RedValsVect = It.second.takeVector();
2221422211
stable_sort(RedValsVect, llvm::less_second());
2221522212
for (const std::pair<Value *, unsigned> &Data : RedValsVect)
2221622213
PossibleRedValsVect.back().append(Data.second, Data.first);
@@ -22370,8 +22367,8 @@ class HorizontalReduction {
2237022367
SmallVector<Value *> Candidates;
2237122368
Candidates.reserve(2 * OrigReducedVals.size());
2237222369
DenseMap<Value *, Value *> TrackedToOrig(2 * OrigReducedVals.size());
22373-
for (unsigned Cnt = 0, Sz = OrigReducedVals.size(); Cnt < Sz; ++Cnt) {
22374-
Value *RdxVal = TrackedVals.at(OrigReducedVals[Cnt]);
22370+
for (Value *ReducedVal : OrigReducedVals) {
22371+
Value *RdxVal = TrackedVals.at(ReducedVal);
2237522372
// Check if the reduction value was not overriden by the extractelement
2237622373
// instruction because of the vectorization and exclude it, if it is not
2237722374
// compatible with other values.
@@ -22382,7 +22379,7 @@ class HorizontalReduction {
2238222379
(S && !Inst))
2238322380
continue;
2238422381
Candidates.push_back(RdxVal);
22385-
TrackedToOrig.try_emplace(RdxVal, OrigReducedVals[Cnt]);
22382+
TrackedToOrig.try_emplace(RdxVal, ReducedVal);
2238622383
}
2238722384
bool ShuffledExtracts = false;
2238822385
// Try to handle shuffled extractelements.

0 commit comments

Comments
 (0)