[llvm] 299e5fe - [SLP][NFC]Simplify/unify vectors for scattered/vectorized loads from

Alexey Bataev via llvm-commits llvm-commits at lists.llvm.org
Tue Feb 6 08:21:47 PST 2024


Author: Alexey Bataev
Date: 2024-02-06T08:18:11-08:00
New Revision: 299e5fef9dee3f2d3af8f9162075b8f1cfa34446

URL: https://github.com/llvm/llvm-project/commit/299e5fef9dee3f2d3af8f9162075b8f1cfa34446
DIFF: https://github.com/llvm/llvm-project/commit/299e5fef9dee3f2d3af8f9162075b8f1cfa34446.diff

LOG: [SLP][NFC]Simplify/unify vectors for scattered/vectorized loads from
gathers, NFC.

Added: 
    

Modified: 
    llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Removed: 
    


################################################################################
diff  --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index c35d39f0a9217..1fe39ca1a485b 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -7090,8 +7090,8 @@ class BoUpSLP::ShuffleCostEstimator : public BaseShuffleAnalysis {
         !all_of(Gathers, [&](Value *V) { return R.getTreeEntry(V); }) &&
         !isSplat(Gathers)) {
       SetVector<Value *> VectorizedLoads;
-      SmallVector<LoadInst *> VectorizedStarts;
-      SmallVector<std::pair<unsigned, unsigned>> ScatterVectorized;
+      SmallVector<unsigned> VectorizedStarts;
+      SmallVector<unsigned> ScatterVectorized;
       unsigned StartIdx = 0;
       unsigned VF = VL.size() / 2;
       for (; VF >= MinVF; VF /= 2) {
@@ -7119,9 +7119,9 @@ class BoUpSLP::ShuffleCostEstimator : public BaseShuffleAnalysis {
               // again.
               // TODO: better handling of loads with reorders.
               if (LS == LoadsState::Vectorize && CurrentOrder.empty())
-                VectorizedStarts.push_back(cast<LoadInst>(Slice.front()));
+                VectorizedStarts.push_back(Cnt);
               else
-                ScatterVectorized.emplace_back(Cnt, VF);
+                ScatterVectorized.push_back(Cnt);
               VectorizedLoads.insert(Slice.begin(), Slice.end());
               // If we vectorized initial block, no need to try to vectorize
               // it again.
@@ -7163,17 +7163,18 @@ class BoUpSLP::ShuffleCostEstimator : public BaseShuffleAnalysis {
                                   CostKind, TTI::OperandValueInfo(), LI);
         }
         auto *LoadTy = FixedVectorType::get(VL.front()->getType(), VF);
-        for (LoadInst *LI : VectorizedStarts) {
+        for (unsigned P : VectorizedStarts) {
+          auto *LI = cast<LoadInst>(VL[P]);
           Align Alignment = LI->getAlign();
           GatherCost +=
               TTI.getMemoryOpCost(Instruction::Load, LoadTy, Alignment,
                                   LI->getPointerAddressSpace(), CostKind,
                                   TTI::OperandValueInfo(), LI);
         }
-        for (std::pair<unsigned, unsigned> P : ScatterVectorized) {
-          auto *LI0 = cast<LoadInst>(VL[P.first]);
+        for (unsigned P : ScatterVectorized) {
+          auto *LI0 = cast<LoadInst>(VL[P]);
           Align CommonAlignment =
-              computeCommonAlignment<LoadInst>(VL.slice(P.first + 1, VF - 1));
+              computeCommonAlignment<LoadInst>(VL.slice(P, VF));
           GatherCost += TTI.getGatherScatterOpCost(
               Instruction::Load, LoadTy, LI0->getPointerOperand(),
               /*VariableMask=*/false, CommonAlignment, CostKind, LI0);


        


More information about the llvm-commits mailing list