[llvm] [LoadStoreVectorizer] Fill gaps in load/store chains to enable vectorization (PR #159388)
Drew Kersnar via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 5 07:11:39 PST 2025
================
@@ -623,6 +658,39 @@ std::vector<Chain> Vectorizer::splitChainByContiguity(Chain &C) {
dumpChain(C);
});
+ // If the chain is not contiguous, we try to fill the gap with "extra"
+ // elements to artificially make it contiguous, to try to enable
+ // vectorization. We only fill gaps if there is potential to end up with a
+ // legal masked load/store given the target, address space, and element type.
+ // At this point, when querying the TTI, optimistically assume max alignment
+ // and max vector size, as splitChainByAlignment will ensure the final vector
+ // shape passes the legalization check.
+ unsigned AS = getLoadStoreAddressSpace(C[0].Inst);
+ Type *ElementType = getLoadStoreType(C[0].Inst)->getScalarType();
+ unsigned MaxVecRegBits = TTI.getLoadStoreVecRegBitWidth(AS);
+ Align OptimisticAlign = Align(MaxVecRegBits / 8);
+ unsigned int MaxVectorNumElems =
+ MaxVecRegBits / DL.getTypeSizeInBits(ElementType);
+ FixedVectorType *OptimisticVectorType =
+ FixedVectorType::get(ElementType, MaxVectorNumElems);
+ bool TryFillGaps =
+ isa<LoadInst>(C[0].Inst)
+ ? TTI.isLegalMaskedLoad(OptimisticVectorType, OptimisticAlign, AS,
+ TTI::MaskKind::ConstantMask)
+ : TTI.isLegalMaskedStore(OptimisticVectorType, OptimisticAlign, AS,
+ TTI::MaskKind::ConstantMask);
+
+ // Derive the alignment of the leader of the chain (which every
+ // OffsetFromLeader is based on) using the current first element of the chain.
+ // We could derive a better alignment by iterating over the entire chain but
+ // this should be sufficient. We use this value to derive the alignment of any
+ // extra elements we create while gap filling.
+ Align LeaderOfChainAlign =
+ commonAlignment(getLoadStoreAlignment(C[0].Inst),
+ C[0].OffsetFromLeader.abs().getLimitedValue());
+
+ unsigned ASPtrBits = DL.getIndexSizeInBits(AS);
+
std::vector<Chain> Ret;
----------------
dakersnar wrote:
I'm not sure, but std::vector is used throughout the file to represent and return split chains, so I'm assuming there was a reason for it.
https://github.com/llvm/llvm-project/pull/159388
More information about the llvm-commits
mailing list