[llvm] [SLPVectorizer] Move size checks (NFC) (PR #159361)

Mikhail Gudim via llvm-commits llvm-commits at lists.llvm.org
Mon Sep 22 08:42:01 PDT 2025


https://github.com/mgudim updated https://github.com/llvm/llvm-project/pull/159361

>From da74788acd691c76705f07cc438abceaa7b76fb6 Mon Sep 17 00:00:00 2001
From: Mikhail Gudim <mgudim at ventanamicro.com>
Date: Wed, 17 Sep 2025 06:43:01 -0700
Subject: [PATCH 1/2] [SLPVectorizer] Move size checks (NFC)

Move size checks inside `isStridedLoad`. In the future we plan to
possibly change the size and type of strided load there.
---
 .../Transforms/Vectorize/SLPVectorizer.cpp    | 30 +++++++++----------
 1 file changed, 15 insertions(+), 15 deletions(-)

diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 6ac9018df641e..5f5f266284856 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -2237,8 +2237,7 @@ class BoUpSLP {
   bool isStridedLoad(ArrayRef<Value *> VL, ArrayRef<Value *> PointerOps,
                      ArrayRef<unsigned> Order, const TargetTransformInfo &TTI,
                      const DataLayout &DL, ScalarEvolution &SE,
-                     const bool IsAnyPointerUsedOutGraph, const int64_t Diff,
-                     StridedPtrInfo &SPtrInfo) const;
+                     const int64_t Diff, StridedPtrInfo &SPtrInfo) const;
 
   /// Checks if the given array of loads can be represented as a vectorized,
   /// scatter or just simple gather.
@@ -6822,10 +6821,22 @@ bool BoUpSLP::isStridedLoad(ArrayRef<Value *> VL, ArrayRef<Value *> PointerOps,
                             ArrayRef<unsigned> Order,
                             const TargetTransformInfo &TTI,
                             const DataLayout &DL, ScalarEvolution &SE,
-                            const bool IsAnyPointerUsedOutGraph,
                             const int64_t Diff,
                             StridedPtrInfo &SPtrInfo) const {
   const size_t Sz = VL.size();
+  // Simple check if not a strided access - clear order.
+  bool IsPossibleStrided = Diff % (Sz - 1) == 0;
+  if (!IsPossibleStrided)
+    return false;
+
+  // Try to generate strided load node.
+  auto IsAnyPointerUsedOutGraph =
+      IsPossibleStrided && any_of(PointerOps, [&](Value *V) {
+        return isa<Instruction>(V) && any_of(V->users(), [&](User *U) {
+                 return !isVectorized(U) && !MustGather.contains(U);
+               });
+      });
+
   const uint64_t AbsoluteDiff = std::abs(Diff);
   Type *ScalarTy = VL.front()->getType();
   auto *VecTy = getWidenedType(ScalarTy, Sz);
@@ -6956,18 +6967,7 @@ BoUpSLP::LoadsState BoUpSLP::canVectorizeLoads(
                                    cast<Instruction>(V), UserIgnoreList);
                              }))
       return LoadsState::CompressVectorize;
-    // Simple check if not a strided access - clear order.
-    bool IsPossibleStrided = *Diff % (Sz - 1) == 0;
-    // Try to generate strided load node.
-    auto IsAnyPointerUsedOutGraph =
-        IsPossibleStrided && any_of(PointerOps, [&](Value *V) {
-          return isa<Instruction>(V) && any_of(V->users(), [&](User *U) {
-                   return !isVectorized(U) && !MustGather.contains(U);
-                 });
-        });
-    if (IsPossibleStrided &&
-        isStridedLoad(VL, PointerOps, Order, *TTI, *DL, *SE,
-                      IsAnyPointerUsedOutGraph, *Diff, SPtrInfo))
+    if (isStridedLoad(VL, PointerOps, Order, *TTI, *DL, *SE, *Diff, SPtrInfo))
       return LoadsState::StridedVectorize;
   }
   if (!TTI->isLegalMaskedGather(VecTy, CommonAlignment) ||

>From 157145082df7813ca5361a29a313b590272b5b07 Mon Sep 17 00:00:00 2001
From: Mikhail Gudim <mgudim at ventanamicro.com>
Date: Mon, 22 Sep 2025 08:34:35 -0700
Subject: [PATCH 2/2] got rid of "IsPossibleStrided" and a comment.

---
 llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)

diff --git a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
index 5f5f266284856..702eca2f2149a 100644
--- a/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
+++ b/llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp
@@ -6824,14 +6824,12 @@ bool BoUpSLP::isStridedLoad(ArrayRef<Value *> VL, ArrayRef<Value *> PointerOps,
                             const int64_t Diff,
                             StridedPtrInfo &SPtrInfo) const {
   const size_t Sz = VL.size();
-  // Simple check if not a strided access - clear order.
-  bool IsPossibleStrided = Diff % (Sz - 1) == 0;
-  if (!IsPossibleStrided)
+  if (Diff % (Sz - 1) != 0)
     return false;
 
   // Try to generate strided load node.
   auto IsAnyPointerUsedOutGraph =
-      IsPossibleStrided && any_of(PointerOps, [&](Value *V) {
+      Iany_of(PointerOps, [&](Value *V) {
         return isa<Instruction>(V) && any_of(V->users(), [&](User *U) {
                  return !isVectorized(U) && !MustGather.contains(U);
                });



More information about the llvm-commits mailing list