From dda2a5d4570e1cccc30f078844e8e9b39b1b4d7a Mon Sep 17 00:00:00 2001 From: Vasileios Porpodas Date: Tue, 9 May 2023 19:07:21 -0700 Subject: [PATCH] [SLP][NFC] Rename a couple of variables and replace an if-else with an std::min - Rename `LimitForRegisterSize` to `MaxVFOnly` to make the meaning of the limit less ambiguous - Rename `OpsWidth` to `ActualVF`, which makes it clear that this is the VF we are using for vectorization. - Replace the if-else code for the initialization of OpsWidth with an std::min. Differential Revision: https://reviews.llvm.org/D150241 --- .../llvm/Transforms/Vectorize/SLPVectorizer.h | 5 +- .../Transforms/Vectorize/SLPVectorizer.cpp | 49 +++++++++---------- 2 files changed, 24 insertions(+), 30 deletions(-) diff --git a/llvm/include/llvm/Transforms/Vectorize/SLPVectorizer.h b/llvm/include/llvm/Transforms/Vectorize/SLPVectorizer.h index fa35ff8d5afb..007dbffd3864 100644 --- a/llvm/include/llvm/Transforms/Vectorize/SLPVectorizer.h +++ b/llvm/include/llvm/Transforms/Vectorize/SLPVectorizer.h @@ -95,11 +95,10 @@ private: bool tryToVectorizePair(Value *A, Value *B, slpvectorizer::BoUpSLP &R); /// Try to vectorize a list of operands. - /// \param LimitForRegisterSize Vectorize only using maximal allowed register - /// size. + /// \param MaxVFOnly Vectorize only using maximal allowed register size. /// \returns true if a value was vectorized. bool tryToVectorizeList(ArrayRef VL, slpvectorizer::BoUpSLP &R, - bool LimitForRegisterSize = false); + bool MaxVFOnly = false); /// Try to vectorize a chain that may start at the operands of \p I. bool tryToVectorize(Instruction *I, slpvectorizer::BoUpSLP &R); diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp index c4b709019cc2..17326700a9d0 100644 --- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp +++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp @@ -12380,7 +12380,7 @@ bool SLPVectorizerPass::tryToVectorizePair(Value *A, Value *B, BoUpSLP &R) { } bool SLPVectorizerPass::tryToVectorizeList(ArrayRef VL, BoUpSLP &R, - bool LimitForRegisterSize) { + bool MaxVFOnly) { if (VL.size() < 2) return false; @@ -12442,21 +12442,17 @@ bool SLPVectorizerPass::tryToVectorizeList(ArrayRef VL, BoUpSLP &R, if (TTI->getNumberOfParts(VecTy) == VF) continue; for (unsigned I = NextInst; I < MaxInst; ++I) { - unsigned OpsWidth = 0; + unsigned ActualVF = std::min(MaxInst - I, VF); - if (I + VF > MaxInst) - OpsWidth = MaxInst - I; - else - OpsWidth = VF; - - if (!isPowerOf2_32(OpsWidth)) + if (!isPowerOf2_32(ActualVF)) continue; - if ((LimitForRegisterSize && OpsWidth < MaxVF) || - (VF > MinVF && OpsWidth <= VF / 2) || (VF == MinVF && OpsWidth < 2)) + if (MaxVFOnly && ActualVF < MaxVF) + break; + if ((VF > MinVF && ActualVF <= VF / 2) || (VF == MinVF && ActualVF < 2)) break; - ArrayRef Ops = VL.slice(I, OpsWidth); + ArrayRef Ops = VL.slice(I, ActualVF); // Check that a previous iteration of this loop did not delete the Value. if (llvm::any_of(Ops, [&R](Value *V) { auto *I = dyn_cast(V); @@ -12464,7 +12460,7 @@ bool SLPVectorizerPass::tryToVectorizeList(ArrayRef VL, BoUpSLP &R, })) continue; - LLVM_DEBUG(dbgs() << "SLP: Analyzing " << OpsWidth << " operations " + LLVM_DEBUG(dbgs() << "SLP: Analyzing " << ActualVF << " operations " << "\n"); R.buildTree(Ops); @@ -12482,7 +12478,7 @@ bool SLPVectorizerPass::tryToVectorizeList(ArrayRef VL, BoUpSLP &R, MinCost = std::min(MinCost, Cost); LLVM_DEBUG(dbgs() << "SLP: Found cost = " << Cost - << " for VF=" << OpsWidth << "\n"); + << " for VF=" << ActualVF << "\n"); if (Cost < -SLPCostThreshold) { LLVM_DEBUG(dbgs() << "SLP: Vectorizing list at cost:" << Cost << ".\n"); R.getORE()->emit(OptimizationRemark(SV_NAME, "VectorizedList", @@ -14277,7 +14273,7 @@ static bool tryToVectorizeSequence( SmallVectorImpl &Incoming, function_ref Comparator, function_ref AreCompatible, function_ref, bool)> TryToVectorizeHelper, - bool LimitForRegisterSize, BoUpSLP &R) { + bool MaxVFOnly, BoUpSLP &R) { bool Changed = false; // Sort by type, parent, operands. stable_sort(Incoming, Comparator); @@ -14305,7 +14301,7 @@ static bool tryToVectorizeSequence( // same/alternate ops only, this may result in some extra final // vectorization. if (NumElts > 1 && - TryToVectorizeHelper(ArrayRef(IncIt, NumElts), LimitForRegisterSize)) { + TryToVectorizeHelper(ArrayRef(IncIt, NumElts), MaxVFOnly)) { // Success start over because instructions might have been changed. Changed = true; } else { @@ -14324,10 +14320,10 @@ static bool tryToVectorizeSequence( // Final attempt to vectorize instructions with the same types. if (Candidates.size() > 1 && (SameTypeIt == E || (*SameTypeIt)->getType() != (*IncIt)->getType())) { - if (TryToVectorizeHelper(Candidates, /*LimitForRegisterSize=*/false)) { + if (TryToVectorizeHelper(Candidates, /*MaxVFOnly=*/false)) { // Success start over because instructions might have been changed. Changed = true; - } else if (LimitForRegisterSize) { + } else if (MaxVFOnly) { // Try to vectorize using small vectors. for (auto *It = Candidates.begin(), *End = Candidates.end(); It != End;) { @@ -14335,9 +14331,8 @@ static bool tryToVectorizeSequence( while (SameTypeIt != End && AreCompatible(*SameTypeIt, *It)) ++SameTypeIt; unsigned NumElts = (SameTypeIt - It); - if (NumElts > 1 && - TryToVectorizeHelper(ArrayRef(It, NumElts), - /*LimitForRegisterSize=*/false)) + if (NumElts > 1 && TryToVectorizeHelper(ArrayRef(It, NumElts), + /*MaxVFOnly=*/false)) Changed = true; It = SameTypeIt; } @@ -14438,7 +14433,7 @@ bool SLPVectorizerPass::vectorizeCmpInsts(ArrayRef CmpInsts, SmallVector Vals(CmpInsts.begin(), CmpInsts.end()); Changed |= tryToVectorizeSequence( Vals, CompareSorter, AreCompatibleCompares, - [this, &R](ArrayRef Candidates, bool LimitForRegisterSize) { + [this, &R](ArrayRef Candidates, bool MaxVFOnly) { // Exclude possible reductions from other blocks. bool ArePossiblyReducedInOtherBlock = any_of(Candidates, [](Value *V) { return any_of(V->users(), [V](User *U) { @@ -14449,9 +14444,9 @@ bool SLPVectorizerPass::vectorizeCmpInsts(ArrayRef CmpInsts, }); if (ArePossiblyReducedInOtherBlock) return false; - return tryToVectorizeList(Candidates, R, LimitForRegisterSize); + return tryToVectorizeList(Candidates, R, MaxVFOnly); }, - /*LimitForRegisterSize=*/true, R); + /*MaxVFOnly=*/true, R); return Changed; } @@ -14635,10 +14630,10 @@ bool SLPVectorizerPass::vectorizeChainsInBlock(BasicBlock *BB, BoUpSLP &R) { HaveVectorizedPhiNodes = tryToVectorizeSequence( Incoming, PHICompare, AreCompatiblePHIs, - [this, &R](ArrayRef Candidates, bool LimitForRegisterSize) { - return tryToVectorizeList(Candidates, R, LimitForRegisterSize); + [this, &R](ArrayRef Candidates, bool MaxVFOnly) { + return tryToVectorizeList(Candidates, R, MaxVFOnly); }, - /*LimitForRegisterSize=*/true, R); + /*MaxVFOnly=*/true, R); Changed |= HaveVectorizedPhiNodes; VisitedInstrs.insert(Incoming.begin(), Incoming.end()); } while (HaveVectorizedPhiNodes); @@ -14931,7 +14926,7 @@ bool SLPVectorizerPass::vectorizeStoreChains(BoUpSLP &R) { [this, &R](ArrayRef Candidates, bool) { return vectorizeStores(Candidates, R); }, - /*LimitForRegisterSize=*/false, R); + /*MaxVFOnly=*/false, R); } return Changed; } -- 2.34.1