Skip to content

Commit d03b68b

Browse files
committed
fixup! [SLP] More OOP to simplify vectorizeStores() (NFC)
1 parent f935439 commit d03b68b

File tree

1 file changed

+18
-13
lines changed

1 file changed

+18
-13
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 18 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -20880,10 +20880,20 @@ class RelatedStoreInsts {
2088020880
return Inserted ? std::nullopt : std::optional<unsigned>(It->second);
2088120881
}
2088220882

20883-
StoreInst &getBaseStore() const { return *AllStores[BaseInstrIdx]; }
2088420883
using DistToInstMap = std::map<int, unsigned>;
2088520884
const DistToInstMap &getStores() const { return Instrs; }
2088620885

20886+
/// If \p SI is related to this group of stores, return the distance of its
20887+
/// pointer operand to the one the group's BaseInstr.
20888+
std::optional<int> getPointerDiff(StoreInst &SI, const DataLayout &DL,
20889+
ScalarEvolution &SE) const {
20890+
StoreInst &BaseStore = *AllStores[BaseInstrIdx];
20891+
return getPointersDiff(
20892+
BaseStore.getValueOperand()->getType(), BaseStore.getPointerOperand(),
20893+
SI.getValueOperand()->getType(), SI.getPointerOperand(), DL, SE,
20894+
/*StrictCheck=*/true);
20895+
}
20896+
2088720897
/// Recompute the pointer distances to be based on \p NewBaseInstIdx.
2088820898
/// Stores whose index is less than \p MinSafeIdx will be dropped.
2088920899
void rebase(unsigned MinSafeIdx, unsigned NewBaseInstIdx,
@@ -21245,16 +21255,11 @@ bool SLPVectorizerPass::vectorizeStores(
2124521255
// dependencies and no need to waste compile time to try to vectorize them.
2124621256
// - Try to vectorize the sequence {1, {1, 0}, {3, 2}}.
2124721257
auto FillStoresSet = [&](unsigned Idx, StoreInst *SI) {
21248-
std::optional<int> Diff;
21249-
auto *RelatedStores =
21250-
find_if(SortedStores, [&](const RelatedStoreInsts &StoreSeq) {
21251-
StoreInst &BaseStore = StoreSeq.getBaseStore();
21252-
Diff = getPointersDiff(BaseStore.getValueOperand()->getType(),
21253-
BaseStore.getPointerOperand(),
21254-
SI->getValueOperand()->getType(),
21255-
SI->getPointerOperand(), *DL, *SE,
21256-
/*StrictCheck=*/true);
21257-
return Diff.has_value();
21258+
std::optional<int> PtrDist;
21259+
auto *RelatedStores = find_if(
21260+
SortedStores, [&PtrDist, SI, this](const RelatedStoreInsts &StoreSeq) {
21261+
PtrDist = StoreSeq.getPointerDiff(*SI, *DL, *SE);
21262+
return PtrDist.has_value();
2125821263
});
2125921264

2126021265
// We did not find a comparable store, start a new group.
@@ -21267,12 +21272,12 @@ bool SLPVectorizerPass::vectorizeStores(
2126721272
// vectorize the existing instructions before adding the current store.
2126821273
// Otherwise, insert this store and keep collecting.
2126921274
if (std::optional<unsigned> PrevInst =
21270-
RelatedStores->insertOrLookup(Idx, *Diff)) {
21275+
RelatedStores->insertOrLookup(Idx, *PtrDist)) {
2127121276
TryToVectorize(RelatedStores->getStores());
2127221277
RelatedStores->clearVectorizedStores(VectorizedStores);
2127321278
RelatedStores->rebase(/*MinSafeIdx=*/*PrevInst + 1,
2127421279
/*NewBaseInstIdx=*/Idx,
21275-
/*DistFromCurBase=*/*Diff);
21280+
/*DistFromCurBase=*/*PtrDist);
2127621281
}
2127721282
};
2127821283
Type *PrevValTy = nullptr;

0 commit comments

Comments
 (0)