From 986f2ac48f369bc025a3f1830e2d5bba235be0fd Mon Sep 17 00:00:00 2001 From: Alex MacLean Date: Fri, 10 Jan 2025 09:18:28 -0800 Subject: [PATCH] [SLPVectorizer] minor tweaks around lambdas for compatibility with older compilers (#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. --- .../Transforms/Vectorize/SLPVectorizer.cpp | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index cdfec332af37ab..29b81114ef7051 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -6908,7 +6908,7 @@ void BoUpSLP::tryToVectorizeGatheredLoads( return L1.second > L2.second; }; - auto IsMaskedGatherSupported = [&](ArrayRef Loads) { + auto IsMaskedGatherSupported = [&, TTI = TTI](ArrayRef Loads) { ArrayRef Values(reinterpret_cast(Loads.begin()), Loads.size()); Align Alignment = computeCommonAlignment(Values); @@ -7075,9 +7075,10 @@ void BoUpSLP::tryToVectorizeGatheredLoads( } SmallVector> LocalLoadsDists(LoadsDists); SmallVector OriginalLoads(LocalLoadsDists.size()); - transform( - LoadsDists, OriginalLoads.begin(), - [](const std::pair &L) { return L.first; }); + transform(LoadsDists, OriginalLoads.begin(), + [](const std::pair &L) -> LoadInst * { + return L.first; + }); stable_sort(LocalLoadsDists, LoadSorter); SmallVector Loads; unsigned MaxConsecutiveDistance = 0; @@ -7304,7 +7305,8 @@ void BoUpSLP::tryToVectorizeGatheredLoads( if (!Ref.empty() && !NonVectorized.empty() && std::accumulate( Ref.begin(), Ref.end(), 0u, - [](unsigned S, ArrayRef> LoadsDists) { + [](unsigned S, + ArrayRef> LoadsDists) -> unsigned { return S + LoadsDists.size(); }) != NonVectorized.size() && IsMaskedGatherSupported(NonVectorized)) { @@ -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 &NewMask) { + auto &&IsIdenticalOrLessDefined = [TTI = TTI](Instruction *I1, + Instruction *I2, + SmallVectorImpl &NewMask) { if (I1->getType() != I2->getType()) return false; auto *SI1 = dyn_cast(I1); @@ -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(