[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 09:15:00 PST 2025
================
@@ -623,6 +663,25 @@ 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 a potentially legal masked
+ // load/store for the target. If later on, we don't end up with a chain that
+ // could be vectorized into a legal masked load/store, the chains with extra
+ // elements will be filtered out in splitChainByAlignment.
+ bool TryFillGaps = shouldAttemptMaskedLoadStore(C);
+
+ unsigned ASPtrBits =
+ DL.getIndexSizeInBits(getLoadStoreAddressSpace(C[0].Inst));
+
+ // Compute the alignment of the leader of the chain (which every stored offset
+ // is based on) using the current first element of the chain. This is
+ // conservative, we may be able to derive better alignment by iterating over
+ // the chain and finding the leader.
+ Align LeaderOfChainAlign =
----------------
dakersnar wrote:
> The alignment of the leader is independent of the alignment of C[0] =>my claim is, we're only using it, combined with the offset of C[0] from the leader to make a conservative approximation of the leader's alignment.
You're 100% correct in this claim, but I was just trying to avoid changing the Chain data structure for such a narrow edge case. To be specific, this alignment deriving is _only_ useful in the rare event where an extra element ends up as the leader of a chain. Changing the data structure from a SmallVector to a struct that contains a SmallVector + a leader alignment seems like it is not worth the complication to the overall file.
> commonAlign(best possible alignment in the chain, offset of gap load/store from the best aligned load/store)
This might work better, but the code will be a bit more complex. Let me try to implement it and then get your opinion.
https://github.com/llvm/llvm-project/pull/159388
More information about the llvm-commits
mailing list