Skip to content

Commit 73ca248

Browse files
author
Mikhail Gudim
committed
added / improved comments,
added `const`s
1 parent b86eb3a commit 73ca248

File tree

1 file changed

+30
-12
lines changed

1 file changed

+30
-12
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 30 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2243,27 +2243,45 @@ class BoUpSLP {
22432243
bool isLoadCombineCandidate(ArrayRef<Value *> Stores) const;
22442244
bool isStridedLoad(ArrayRef<Value *> PointerOps, Type *ScalarTy,
22452245
Align Alignment, int64_t Diff, size_t Sz) const;
2246-
/// Given a set of pointers, check if they can be rearranged as follows (%s is
2247-
/// a constant):
2246+
2247+
/// Return true if an array of scalar loads can be replaced with a strided
2248+
/// load (with constant stride).
2249+
///
2250+
/// It is possible that the load gets "widened". Suppose that originally each load loads `k` bytes and `PointerOps` can be arranged as follows (`%s` is constant):
22482251
/// %b + 0 * %s + 0
22492252
/// %b + 0 * %s + 1
22502253
/// %b + 0 * %s + 2
22512254
/// ...
2252-
/// %b + 0 * %s + w
2255+
/// %b + 0 * %s + (w - 1)
22532256
///
22542257
/// %b + 1 * %s + 0
22552258
/// %b + 1 * %s + 1
22562259
/// %b + 1 * %s + 2
22572260
/// ...
2258-
/// %b + 1 * %s + w
2261+
/// %b + 1 * %s + (w - 1)
2262+
/// ...
2263+
///
2264+
/// %b + (n - 1) * %s + 0
2265+
/// %b + (n - 1) * %s + 1
2266+
/// %b + (n - 1) * %s + 2
22592267
/// ...
2268+
/// %b + (n - 1) * %s + (w - 1)
22602269
///
2261-
/// If the pointers can be rearanged in the above pattern, it means that the
2262-
/// memory can be accessed with a strided loads of width `w` and stride `%s`.
2263-
bool analyzeConstantStrideCandidate(ArrayRef<Value *> PointerOps,
2264-
Type *ElemTy, Align CommonAlignment,
2265-
SmallVectorImpl<unsigned> &SortedIndices,
2266-
int64_t Diff, Value *Ptr0, Value *PtrN,
2270+
/// In this case we will generate a strided load of type `<n x (k * w)>`.
2271+
///
2272+
/// \param PointerOps list of pointer arguments of loads.
2273+
/// \param ElemTy original scalar type of loads.
2274+
/// \param Alignment alignment of the first load.
2275+
/// \param SortedIndices is the order of PointerOps as returned by `sortPtrAccesses`
2276+
/// \param Diff Pointer difference between the lowest and the highes pointer in `PointerOps` as returned by `getPointersDiff`.
2277+
/// \param Ptr0 first pointer in `PointersOps`.
2278+
/// \param PtrN last pointer in `PointersOps`.
2279+
/// \param SPtrInfo If the function return `true`, it also sets all the fields
2280+
/// of `SPtrInfo` necessary to generate the strided load later.
2281+
bool analyzeConstantStrideCandidate(const ArrayRef<Value *> PointerOps,
2282+
Type *ElemTy, Align Alignment,
2283+
const SmallVectorImpl<unsigned> &SortedIndices,
2284+
const int64_t Diff, Value *Ptr0, Value *PtrN,
22672285
StridedPtrInfo &SPtrInfo) const;
22682286

22692287
/// Return true if an array of scalar loads can be replaced with a strided
@@ -6896,8 +6914,8 @@ bool BoUpSLP::isStridedLoad(ArrayRef<Value *> PointerOps, Type *ScalarTy,
68966914
}
68976915

68986916
bool BoUpSLP::analyzeConstantStrideCandidate(
6899-
ArrayRef<Value *> PointerOps, Type *ElemTy, Align CommonAlignment,
6900-
SmallVectorImpl<unsigned> &SortedIndices, int64_t Diff, Value *Ptr0,
6917+
const ArrayRef<Value *> PointerOps, Type *ElemTy, Align CommonAlignment,
6918+
const SmallVectorImpl<unsigned> &SortedIndices, const int64_t Diff, Value *Ptr0,
69016919
Value *PtrN, StridedPtrInfo &SPtrInfo) const {
69026920
const unsigned Sz = PointerOps.size();
69036921
SmallVector<int64_t> SortedOffsetsFromBase;

0 commit comments

Comments
 (0)