Skip to content

Commit

Permalink
[SLPVectorizer] minor tweaks around lambdas for compatibility with ol…
Browse files Browse the repository at this point in the history
…der compilers (llvm#122348)

Older version of msvc do not have great lambda support and are not able
to handle uses of class data or lambdas with implicit return types in
some cases. These minor changes improve the sources compatibility with
older msvc and don't hurt readability either.
  • Loading branch information
AlexMaclean authored Jan 10, 2025
1 parent 59ced72 commit 986f2ac
Showing 1 changed file with 11 additions and 8 deletions.
19 changes: 11 additions & 8 deletions llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -6908,7 +6908,7 @@ void BoUpSLP::tryToVectorizeGatheredLoads(
return L1.second > L2.second;
};

auto IsMaskedGatherSupported = [&](ArrayRef<LoadInst *> Loads) {
auto IsMaskedGatherSupported = [&, TTI = TTI](ArrayRef<LoadInst *> Loads) {
ArrayRef<Value *> Values(reinterpret_cast<Value *const *>(Loads.begin()),
Loads.size());
Align Alignment = computeCommonAlignment<LoadInst>(Values);
Expand Down Expand Up @@ -7075,9 +7075,10 @@ void BoUpSLP::tryToVectorizeGatheredLoads(
}
SmallVector<std::pair<LoadInst *, int>> LocalLoadsDists(LoadsDists);
SmallVector<LoadInst *> OriginalLoads(LocalLoadsDists.size());
transform(
LoadsDists, OriginalLoads.begin(),
[](const std::pair<LoadInst *, int> &L) { return L.first; });
transform(LoadsDists, OriginalLoads.begin(),
[](const std::pair<LoadInst *, int> &L) -> LoadInst * {
return L.first;
});
stable_sort(LocalLoadsDists, LoadSorter);
SmallVector<LoadInst *> Loads;
unsigned MaxConsecutiveDistance = 0;
Expand Down Expand Up @@ -7304,7 +7305,8 @@ void BoUpSLP::tryToVectorizeGatheredLoads(
if (!Ref.empty() && !NonVectorized.empty() &&
std::accumulate(
Ref.begin(), Ref.end(), 0u,
[](unsigned S, ArrayRef<std::pair<LoadInst *, int>> LoadsDists) {
[](unsigned S,
ArrayRef<std::pair<LoadInst *, int>> LoadsDists) -> unsigned {
return S + LoadsDists.size();
}) != NonVectorized.size() &&
IsMaskedGatherSupported(NonVectorized)) {
Expand Down Expand Up @@ -16979,8 +16981,9 @@ void BoUpSLP::optimizeGatherSequence() {
// and its mask indeces are the same as in the first one or undefs. E.g.
// shuffle %0, poison, <0, 0, 0, undef> is less defined than shuffle %0,
// poison, <0, 0, 0, 0>.
auto &&IsIdenticalOrLessDefined = [this](Instruction *I1, Instruction *I2,
SmallVectorImpl<int> &NewMask) {
auto &&IsIdenticalOrLessDefined = [TTI = TTI](Instruction *I1,
Instruction *I2,
SmallVectorImpl<int> &NewMask) {
if (I1->getType() != I2->getType())
return false;
auto *SI1 = dyn_cast<ShuffleVectorInst>(I1);
Expand Down Expand Up @@ -17774,7 +17777,7 @@ bool BoUpSLP::collectValuesToDemote(
BitWidth = std::max(BitWidth, BitWidth1);
return BitWidth > 0 && OrigBitWidth >= (BitWidth * 2);
};
auto FinalAnalysis = [&]() {
auto FinalAnalysis = [&, TTI = TTI]() {
if (!IsProfitableToDemote)
return false;
bool Res = all_of(
Expand Down

0 comments on commit 986f2ac

Please sign in to comment.