[llvm] [SLP] NFC: Remove redundant expression from getBuildVectorCost (PR #222547)

Sander de Smalen via llvm-commits llvm-commits at lists.llvm.org
Thu Sep 10 01:18:23 PDT 2026


https://github.com/sdesmalen-arm created https://github.com/llvm/llvm-project/pull/222547

Gathers is initialized with the contents from VL and then not modified, so `VL.equals(Gathers)` is always true.

Also removed unnecessary `std::iota`, as the constructor for SmallVector can initialize the array with 0 instead.

>From 261e3ec80ee11a1d7cc5e734e0dc93e5f42ae939 Mon Sep 17 00:00:00 2001
From: Sander de Smalen <sander.desmalen at arm.com>
Date: Wed, 9 Sep 2026 15:21:03 +0000
Subject: [PATCH] [SLP] NFC: Remove redundant expression from
 getBuildVectorCost

Gathers is initialized with the contents from VL and then not modified,
so `VL.equals(Gathers)` is always true.

Also removed unnecessary `std::iota`, as the constructor for SmallVector
can initialize the array with 0 instead.
---
 llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp | 12 ++++--------
 1 file changed, 4 insertions(+), 8 deletions(-)

diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 3fd146320c959..c050cb305379c 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -14451,7 +14451,6 @@ class BoUpSLP::ShuffleCostEstimator : public BaseShuffleAnalysis {
       return TTI::TCC_Free;
     auto *VecTy = cast<VectorType>(getWidenedType(ScalarTy, VL.size()));
     InstructionCost GatherCost = 0;
-    SmallVector<Value *> Gathers(VL);
     if (!Root && isSplat(VL)) {
       // Found the broadcasting of the single scalar, calculate the cost as
       // the broadcast.
@@ -14486,11 +14485,9 @@ class BoUpSLP::ShuffleCostEstimator : public BaseShuffleAnalysis {
                                          /*Index=*/0, /*SubTp=*/nullptr,
                                          /*Args=*/*It);
     }
-    return GatherCost +
-           (all_of(Gathers, IsaPred<UndefValue>)
-                ? TTI::TCC_Free
-                : R.getGatherCost(Gathers, !Root && VL.equals(Gathers),
-                                  ScalarTy));
+    return GatherCost + (all_of(VL, IsaPred<UndefValue>)
+                             ? TTI::TCC_Free
+                             : R.getGatherCost(VL, !Root, ScalarTy));
   };
 
   /// Compute the cost of creating a vector containing the extracted values from
@@ -20726,8 +20723,7 @@ InstructionCost BoUpSLP::getGatherCost(ArrayRef<Value *> VL, bool ForPoisonSrc,
       Cost += TTI->getCastInstrCost(Instruction::Trunc, ScalarTy, V->getType(),
                                     TTI::CastContextHint::None, CostKind);
   };
-  SmallVector<int> ConstantShuffleMask(VF, PoisonMaskElem);
-  std::iota(ConstantShuffleMask.begin(), ConstantShuffleMask.end(), 0);
+  SmallVector<int> ConstantShuffleMask(VF, 0);
   for (auto [I, V] : enumerate(VL)) {
     // No need to shuffle duplicates for constants.
     if ((ForPoisonSrc && isConstant(V)) || isa<UndefValue>(V))



More information about the llvm-commits mailing list