@@ -20880,10 +20880,20 @@ class RelatedStoreInsts {
20880
20880
return Inserted ? std::nullopt : std::optional<unsigned>(It->second);
20881
20881
}
20882
20882
20883
- StoreInst &getBaseStore() const { return *AllStores[BaseInstrIdx]; }
20884
20883
using DistToInstMap = std::map<int, unsigned>;
20885
20884
const DistToInstMap &getStores() const { return Instrs; }
20886
20885
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
+
20887
20897
/// Recompute the pointer distances to be based on \p NewBaseInstIdx.
20888
20898
/// Stores whose index is less than \p MinSafeIdx will be dropped.
20889
20899
void rebase(unsigned MinSafeIdx, unsigned NewBaseInstIdx,
@@ -21245,16 +21255,11 @@ bool SLPVectorizerPass::vectorizeStores(
21245
21255
// dependencies and no need to waste compile time to try to vectorize them.
21246
21256
// - Try to vectorize the sequence {1, {1, 0}, {3, 2}}.
21247
21257
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();
21258
21263
});
21259
21264
21260
21265
// We did not find a comparable store, start a new group.
@@ -21267,12 +21272,12 @@ bool SLPVectorizerPass::vectorizeStores(
21267
21272
// vectorize the existing instructions before adding the current store.
21268
21273
// Otherwise, insert this store and keep collecting.
21269
21274
if (std::optional<unsigned> PrevInst =
21270
- RelatedStores->insertOrLookup(Idx, *Diff )) {
21275
+ RelatedStores->insertOrLookup(Idx, *PtrDist )) {
21271
21276
TryToVectorize(RelatedStores->getStores());
21272
21277
RelatedStores->clearVectorizedStores(VectorizedStores);
21273
21278
RelatedStores->rebase(/*MinSafeIdx=*/*PrevInst + 1,
21274
21279
/*NewBaseInstIdx=*/Idx,
21275
- /*DistFromCurBase=*/*Diff );
21280
+ /*DistFromCurBase=*/*PtrDist );
21276
21281
}
21277
21282
};
21278
21283
Type *PrevValTy = nullptr;
0 commit comments