llvmorg-github-actions[bot] wrote:

<!--LLVM PR SUMMARY COMMENT-->

@llvm/pr-subscribers-llvm-transforms

Author: Anshil Gandhi (gandhi56)

<details>
<summary>Changes</summary>

Both `vectorizeStores()` and `vectorizeLoads()` (via `createVectorLoad()`) 
checked that the bundle is consecutive right before calling `canVectorize()`. 
Fold that check into `canVectorize()` so that every caller gets it.

No functional change.

Stacked on #<!-- -->236635.

🤖 Generated with [Claude Code](https://claude.com/claude-code)


---
Full diff: https://github.com/llvm/llvm-project/pull/236636.diff


2 Files Affected:

- (modified) 
llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/Passes/LoadStoreVec.h 
(+2-2) 
- (modified) 
llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/LoadStoreVec.cpp (+8-9) 


``````````diff
diff --git 
a/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/Passes/LoadStoreVec.h
 
b/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/Passes/LoadStoreVec.h
index ae29644e4b2c7d..7ce3acc837dbaa 100644
--- 
a/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/Passes/LoadStoreVec.h
+++ 
b/llvm/include/llvm/Transforms/Vectorize/SandboxVectorizer/Passes/LoadStoreVec.h
@@ -55,8 +55,8 @@ class LLVM_ABI LoadStoreVec final : public RegionPass {
   /// reverts it otherwise. \returns true if the transaction was accepted.
   bool acceptOrRevert();
 
-  /// Checks legality of vectorization and \returns the vector type on success,
-  /// nullopt otherwise.
+  /// Checks that \p Bndl accesses consecutive memory and is legal to
+  /// vectorize. \returns the vector type on success, nullopt otherwise.
   std::optional<Type *> canVectorize(BndlRef<Instruction *> Bndl);
 
   /// Builds a single vector load out of \p Loads. \returns the new load,
diff --git 
a/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/LoadStoreVec.cpp 
b/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/LoadStoreVec.cpp
index db520128d5c130..c66acab5b1ada2 100644
--- a/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/LoadStoreVec.cpp
+++ b/llvm/lib/Transforms/Vectorize/SandboxVectorizer/Passes/LoadStoreVec.cpp
@@ -30,6 +30,14 @@ namespace sandboxir {
 std::optional<Type *> LoadStoreVec::canVectorize(BndlRef<Instruction *> Bndl) {
   LLVM_DEBUG(dbgs() << DEBUG_PREFIX << "canVectorize() Bundle:\n";
              VecUtils::dump(Bndl));
+  if (isa<StoreInst>(Bndl[0])) {
+    if (!VecUtils::areConsecutive<StoreInst, Instruction>(
+            Bndl, A->getScalarEvolution(), *DL))
+      return std::nullopt;
+  } else if (!VecUtils::areConsecutive<LoadInst, Instruction>(
+                 Bndl, A->getScalarEvolution(), *DL)) {
+    return std::nullopt;
+  }
   const auto &LegalityRes = Legality->canVectorizeLSV(Bndl);
   LLVM_DEBUG(dbgs() << DEBUG_PREFIX << "Legality: " << LegalityRes << "\n");
 
@@ -64,9 +72,6 @@ bool LoadStoreVec::acceptOrRevert() {
 }
 
 LoadInst *LoadStoreVec::createVectorLoad(BndlRef<Instruction *> Loads) {
-  if (!VecUtils::areConsecutive<LoadInst, Instruction>(
-          Loads, A->getScalarEvolution(), *DL))
-    return nullptr;
   if (!canVectorize(Loads))
     return nullptr;
 
@@ -211,9 +216,6 @@ Constant 
*LoadStoreVec::createConstantVector(BndlRef<Constant *> Constants) {
 }
 
 bool LoadStoreVec::vectorizeStores(BndlRef<Instruction *> Stores, Region &Rgn) 
{
-  if (!VecUtils::areConsecutive<StoreInst, Instruction>(
-          Stores, A->getScalarEvolution(), *DL))
-    return false;
   if (!canVectorize(Stores))
     return false;
   SmallVector<Value *, 4> Operands;
@@ -285,9 +287,6 @@ bool LoadStoreVec::vectorizeStores(BndlRef<Instruction *> 
Stores, Region &Rgn) {
 
 LoadInst *LoadStoreVec::vectorizeLoads(BndlRef<Instruction *> Loads,
                                        Region &Rgn) {
-  if (!VecUtils::areConsecutive<LoadInst, Instruction>(
-          Loads, A->getScalarEvolution(), *DL))
-    return nullptr;
   auto VecTy = canVectorize(Loads);
   if (!VecTy)
     return nullptr;

``````````

</details>


https://github.com/llvm/llvm-project/pull/236636
_______________________________________________
llvm-branch-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits

Reply via email to