[llvm] [SLP] Initial support for masked stores (PR #204893)
Alexey Bataev via llvm-commits
llvm-commits at lists.llvm.org
Fri Jun 26 14:46:12 PDT 2026
================
@@ -28495,6 +28641,55 @@ bool SLPVectorizerPass::vectorizeStores(
ExtendContexts(StoreSeq.getStores());
ActuallyVectorizeContexts();
+
+ // When some stores are still not vectorized, try to lower them together as a
+ // single masked store (expand + masked.store).
+ if (!AllowMaskedStores)
+ return Changed;
+
+ SmallVector<Value *> Remaining;
+ for (StoreInst *SI : Stores)
+ if (!R.isDeleted(SI) && !VectorizedStores.contains(SI))
+ Remaining.push_back(SI);
+ if (Remaining.size() < 2)
+ return Changed;
+
+ Type *ValTy = getValueType(Remaining.front());
+ if (any_of(Remaining, [&](Value *V) {
+ return cast<StoreInst>(V)->getValueOperand()->getType() != ValTy;
+ }))
+ return Changed;
+
+ SmallVector<Value *> PointerOps;
+ PointerOps.reserve(Remaining.size());
+ for (Value *V : Remaining)
+ PointerOps.push_back(cast<StoreInst>(V)->getPointerOperand());
+ SmallVector<unsigned> Order;
+ if (!sortPtrAccesses(PointerOps, ValTy, *DL, *SE, Order))
+ return Changed;
+
+ SmallVector<Value *> Sorted(Remaining.size());
+ for (unsigned I : seq<unsigned>(Remaining.size()))
+ Sorted[I] = Remaining[Order.empty() ? I : Order[I]];
+
+ // No need to re-check for consecutive (stride-1) pairs here: the caller
+ // already disables masked stores for the whole base-object group when any
+ // consecutive pair exists, so this subset cannot contain one.
+ if (!Visited
+ .insert({Sorted.front(),
+ cast<StoreInst>(Sorted.front())->getValueOperand(),
+ Sorted.back(),
+ cast<StoreInst>(Sorted.back())->getValueOperand(),
+ Sorted.size()})
+ .second)
+ return Changed;
+
+ unsigned Size = 0;
+ if (vectorizeStoreChain(Sorted, R, /*Idx=*/0, /*MinVF=*/2, Size)
----------------
alexey-bataev wrote:
Again, do not know the actual VF here
https://github.com/llvm/llvm-project/pull/204893
More information about the llvm-commits
mailing list