Skip to content

Commit b6eae70

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

File tree

1 file changed

+19
-13
lines changed

1 file changed

+19
-13
lines changed

llvm/lib/Transforms/Vectorize/SLPVectorizer.cpp

Lines changed: 19 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,17 +21255,13 @@ 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;
21258+
std::optional<int> PtrDist;
2124921259
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-
});
21260+
find_if(SortedStores,
21261+
[&PtrDist, SI, this](const RelatedStoreInsts &StoreSeq) {
21262+
PtrDist = StoreSeq.getPointerDiff(*SI, *DL, *SE);
21263+
return PtrDist.has_value();
21264+
});
2125921265

2126021266
// We did not find a comparable store, start a new group.
2126121267
if (RelatedStores == SortedStores.end()) {
@@ -21267,12 +21273,12 @@ bool SLPVectorizerPass::vectorizeStores(
2126721273
// vectorize the existing instructions before adding the current store.
2126821274
// Otherwise, insert this store and keep collecting.
2126921275
if (std::optional<unsigned> PrevInst =
21270-
RelatedStores->insertOrLookup(Idx, *Diff)) {
21276+
RelatedStores->insertOrLookup(Idx, *PtrDist)) {
2127121277
TryToVectorize(RelatedStores->getStores());
2127221278
RelatedStores->clearVectorizedStores(VectorizedStores);
2127321279
RelatedStores->rebase(/*MinSafeIdx=*/*PrevInst + 1,
2127421280
/*NewBaseInstIdx=*/Idx,
21275-
/*DistFromCurBase=*/*Diff);
21281+
/*DistFromCurBase=*/*PtrDist);
2127621282
}
2127721283
};
2127821284
Type *PrevValTy = nullptr;

0 commit comments

Comments
 (0)