[llvm] [SLPVectorizer] Widen constant strided loads. (PR #162324)
Alexey Bataev via llvm-commits
llvm-commits at lists.llvm.org
Sat Nov 1 11:03:24 PDT 2025
================
@@ -6942,32 +6941,99 @@ bool BoUpSLP::analyzeConstantStrideCandidate(
const SmallVectorImpl<unsigned> &SortedIndices, const int64_t Diff,
Value *Ptr0, Value *PtrN, StridedPtrInfo &SPtrInfo) const {
const size_t Sz = PointerOps.size();
- if (!isStridedLoad(PointerOps, ScalarTy, Alignment, Diff, Sz))
+ SmallVector<int64_t> SortedOffsetsFromBase(Sz);
+ // Go through `PointerOps` in sorted order and record offsets from `Ptr0`.
+ for (unsigned I : seq<unsigned>(Sz)) {
+ Value *Ptr =
+ SortedIndices.empty() ? PointerOps[I] : PointerOps[SortedIndices[I]];
+ SortedOffsetsFromBase[I] =
+ *getPointersDiff(ScalarTy, Ptr0, ScalarTy, Ptr, *DL, *SE);
+ }
+
+ // The code below checks that `SortedOffsetsFromBase` looks as follows:
+ // ```
+ // [
+ // (e_{0, 0}, e_{0, 1}, ..., e_{0, GroupSize - 1}), // first group
+ // (e_{1, 0}, e_{1, 1}, ..., e_{1, GroupSize - 1}), // secon group
+ // ...
+ // (e_{NumGroups - 1, 0}, e_{NumGroups - 1, 1}, ..., e_{NumGroups - 1,
+ // GroupSize - 1}), // last group
+ // ]
+ // ```
+ // The distance between consecutive elements within each group should all be
+ // the same `StrideWithinGroup`. The distance between the first elements of
+ // consecutive groups should all be the same `StrideBetweenGroups`.
+
+ int64_t StrideWithinGroup =
+ SortedOffsetsFromBase[1] - SortedOffsetsFromBase[0];
+ // Determine size of the first group. Later we will check that all other
+ // groups have the same size.
+ auto isEndOfGroupIndex = [=, &SortedOffsetsFromBase](unsigned Idx) {
+ return SortedOffsetsFromBase[Idx] - SortedOffsetsFromBase[Idx - 1] !=
+ StrideWithinGroup;
+ };
+ unsigned GroupSize = *llvm::find_if(seq<unsigned>(1, Sz), isEndOfGroupIndex);
----------------
alexey-bataev wrote:
Are you sure it always finds the required element?
https://github.com/llvm/llvm-project/pull/162324
More information about the llvm-commits
mailing list