https://github.com/gandhi56 updated https://github.com/llvm/llvm-project/pull/236636
>From 48cea401eea47fc84885e6386c2caa0264d9648d Mon Sep 17 00:00:00 2001 From: Anshil Gandhi <[email protected]> Date: Wed, 28 Oct 2026 23:18:52 -0400 Subject: [PATCH] [SandboxVec][LoadStoreVec] Move contiguity check into canVectorize() (NFC) 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. Co-Authored-By: Claude Opus 5.5 <[email protected]> --- .../SandboxVectorizer/Passes/LoadStoreVec.h | 4 ++-- .../SandboxVectorizer/Passes/LoadStoreVec.cpp | 17 ++++++++--------- 2 files changed, 10 insertions(+), 11 deletions(-) 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; _______________________________________________ llvm-branch-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-branch-commits
