[llvm] Re-land [Transform][LoadStoreVectorizer] allow redundant in Chain (PR #168135)
Drew Kersnar via llvm-commits
llvm-commits at lists.llvm.org
Wed Nov 19 08:59:53 PST 2025
================
@@ -626,22 +626,25 @@ std::vector<Chain> Vectorizer::splitChainByContiguity(Chain &C) {
std::vector<Chain> Ret;
Ret.push_back({C.front()});
- unsigned ElemBytes = DL.getTypeStoreSize(getChainElemTy(C));
+ unsigned ChainElemTyBits = DL.getTypeSizeInBits(getChainElemTy(C));
APInt PrevReadEnd = C[0].OffsetFromLeader +
DL.getTypeStoreSize(getLoadStoreType(&*C[0].Inst));
for (auto It = std::next(C.begin()), End = C.end(); It != End; ++It) {
- // `prev` accesses offsets [PrevDistFromBase, PrevReadEnd).
auto &CurChain = Ret.back();
unsigned SzBytes = DL.getTypeStoreSize(getLoadStoreType(&*It->Inst));
// Add this instruction to the end of the current chain, or start a new one.
- assert(SzBytes % ElemBytes == 0);
+ assert(
+ 8 * SzBytes % ChainElemTyBits == 0 &&
+ "Every chain-element size must be a multiple of the element size after "
+ "vectorization.");
APInt ReadEnd = It->OffsetFromLeader + SzBytes;
// Allow redundancy: partial or full overlap counts as contiguous.
bool AreContiguous = false;
if (It->OffsetFromLeader.sle(PrevReadEnd)) {
+ // Check overlap is a multiple of the element size after vectorization.
uint64_t Overlap = (PrevReadEnd - It->OffsetFromLeader).getZExtValue();
- if (Overlap % ElemBytes == 0)
+ if (8 * Overlap % ChainElemTyBits == 0)
----------------
dakersnar wrote:
Let's think through this to see if we can find an example. Would an input IR that has a load i32 with an offset of, say, 5 be legal on some hypothetical target that does not require an ABI alignment of 4 for i32s?
load i32 ptr
load i32 ptr + 4
load i32 ptr + 5
load i32 ptr + 8
In this example, the 3rd load would have overlap with the 2nd load, making all four loads technically contiguous with your redundant load change. However, we would have no way of indexing the third load from the resulting vector, since we can only index at the granularity of the element type size, so proceeding with this chain would be illegal.
Is this a negative test you could add, and can you confirm that without the if condition something goes wrong?
https://github.com/llvm/llvm-project/pull/168135
More information about the llvm-commits
mailing list