@@ -180,11 +180,15 @@ class MemoryDepChecker {
180180 const SmallVectorImpl<Instruction *> &Instrs) const ;
181181 };
182182
183- MemoryDepChecker (PredicatedScalarEvolution &PSE, const Loop *L,
183+ MemoryDepChecker (PredicatedScalarEvolution &PSE, AssumptionCache *AC,
184+ DominatorTree *DT, const Loop *L,
184185 const DenseMap<Value *, const SCEV *> &SymbolicStrides,
185- unsigned MaxTargetVectorWidthInBits)
186- : PSE(PSE), InnermostLoop(L), SymbolicStrides(SymbolicStrides),
187- MaxTargetVectorWidthInBits (MaxTargetVectorWidthInBits) {}
186+ unsigned MaxTargetVectorWidthInBits,
187+ std::optional<ScalarEvolution::LoopGuards> &LoopGuards)
188+ : PSE(PSE), AC(AC), DT(DT), InnermostLoop(L),
189+ SymbolicStrides (SymbolicStrides),
190+ MaxTargetVectorWidthInBits(MaxTargetVectorWidthInBits),
191+ LoopGuards(LoopGuards) {}
188192
189193 // / Register the location (instructions are given increasing numbers)
190194 // / of a write access.
@@ -236,8 +240,8 @@ class MemoryDepChecker {
236240
237241 // / In same cases when the dependency check fails we can still
238242 // / vectorize the loop with a dynamic array access check.
239- bool shouldRetryWithRuntimeCheck () const {
240- return FoundNonConstantDistanceDependence &&
243+ bool shouldRetryWithRuntimeChecks () const {
244+ return ShouldRetryWithRuntimeChecks &&
241245 Status == VectorizationSafetyStatus::PossiblySafeWithRtChecks;
242246 }
243247
@@ -288,6 +292,15 @@ class MemoryDepChecker {
288292 return PointerBounds;
289293 }
290294
295+ DominatorTree *getDT () const {
296+ assert (DT && " requested DT, but it is not available" );
297+ return DT;
298+ }
299+ AssumptionCache *getAC () const {
300+ assert (AC && " requested AC, but it is not available" );
301+ return AC;
302+ }
303+
291304private:
292305 // / A wrapper around ScalarEvolution, used to add runtime SCEV checks, and
293306 // / applies dynamic knowledge to simplify SCEV expressions and convert them
@@ -296,6 +309,10 @@ class MemoryDepChecker {
296309 // / example we might assume a unit stride for a pointer in order to prove
297310 // / that a memory access is strided and doesn't wrap.
298311 PredicatedScalarEvolution &PSE;
312+
313+ AssumptionCache *AC;
314+ DominatorTree *DT;
315+
299316 const Loop *InnermostLoop;
300317
301318 // / Reference to map of pointer values to
@@ -327,9 +344,9 @@ class MemoryDepChecker {
327344 uint64_t MaxStoreLoadForwardSafeDistanceInBits =
328345 std::numeric_limits<uint64_t >::max();
329346
330- // / If we see a non-constant dependence distance we can still try to
331- // / vectorize this loop with runtime checks .
332- bool FoundNonConstantDistanceDependence = false ;
347+ // / Whether we should try to vectorize the loop with runtime checks, if the
348+ // / dependencies are not safe .
349+ bool ShouldRetryWithRuntimeChecks = false ;
333350
334351 // / Result of the dependence checks, indicating whether the checked
335352 // / dependences are safe for vectorization, require RT checks or are known to
@@ -358,7 +375,7 @@ class MemoryDepChecker {
358375 PointerBounds;
359376
360377 // / Cache for the loop guards of InnermostLoop.
361- std::optional<ScalarEvolution::LoopGuards> LoopGuards;
378+ std::optional<ScalarEvolution::LoopGuards> & LoopGuards;
362379
363380 // / Check whether there is a plausible dependence between the two
364381 // / accesses.
@@ -516,8 +533,9 @@ class RuntimePointerChecking {
516533 AliasSetId(AliasSetId), Expr(Expr), NeedsFreeze(NeedsFreeze) {}
517534 };
518535
519- RuntimePointerChecking (MemoryDepChecker &DC, ScalarEvolution *SE)
520- : DC(DC), SE(SE) {}
536+ RuntimePointerChecking (MemoryDepChecker &DC, ScalarEvolution *SE,
537+ std::optional<ScalarEvolution::LoopGuards> &LoopGuards)
538+ : DC(DC), SE(SE), LoopGuards(LoopGuards) {}
521539
522540 // / Reset the state of the pointer runtime information.
523541 void reset () {
@@ -631,6 +649,9 @@ class RuntimePointerChecking {
631649 // / Holds a pointer to the ScalarEvolution analysis.
632650 ScalarEvolution *SE;
633651
652+ // / Cache for the loop guards of the loop.
653+ std::optional<ScalarEvolution::LoopGuards> &LoopGuards;
654+
634655 // / Set of run-time checks required to establish independence of
635656 // / otherwise may-aliasing pointers in the loop.
636657 SmallVector<RuntimePointerCheck, 4 > Checks;
@@ -670,7 +691,7 @@ class LoopAccessInfo {
670691 LLVM_ABI LoopAccessInfo (Loop *L, ScalarEvolution *SE,
671692 const TargetTransformInfo *TTI,
672693 const TargetLibraryInfo *TLI, AAResults *AA,
673- DominatorTree *DT, LoopInfo *LI,
694+ DominatorTree *DT, LoopInfo *LI, AssumptionCache *AC,
674695 bool AllowPartial = false );
675696
676697 // / Return true we can analyze the memory accesses in the loop and there are
@@ -806,6 +827,9 @@ class LoopAccessInfo {
806827
807828 Loop *TheLoop;
808829
830+ // / Cache for the loop guards of TheLoop.
831+ std::optional<ScalarEvolution::LoopGuards> LoopGuards;
832+
809833 // / Determines whether we should generate partial runtime checks when not all
810834 // / memory accesses could be analyzed.
811835 bool AllowPartial;
@@ -922,7 +946,9 @@ LLVM_ABI std::pair<const SCEV *, const SCEV *> getStartAndEndForAccess(
922946 const Loop *Lp, const SCEV *PtrExpr, Type *AccessTy, const SCEV *BTC,
923947 const SCEV *MaxBTC, ScalarEvolution *SE,
924948 DenseMap<std::pair<const SCEV *, Type *>,
925- std::pair<const SCEV *, const SCEV *>> *PointerBounds);
949+ std::pair<const SCEV *, const SCEV *>> *PointerBounds,
950+ DominatorTree *DT, AssumptionCache *AC,
951+ std::optional<ScalarEvolution::LoopGuards> &LoopGuards);
926952
927953class LoopAccessInfoManager {
928954 // / The cache.
@@ -935,12 +961,13 @@ class LoopAccessInfoManager {
935961 LoopInfo &LI;
936962 TargetTransformInfo *TTI;
937963 const TargetLibraryInfo *TLI = nullptr ;
964+ AssumptionCache *AC;
938965
939966public:
940967 LoopAccessInfoManager (ScalarEvolution &SE, AAResults &AA, DominatorTree &DT,
941968 LoopInfo &LI, TargetTransformInfo *TTI,
942- const TargetLibraryInfo *TLI)
943- : SE(SE), AA(AA), DT(DT), LI(LI), TTI(TTI), TLI(TLI) {}
969+ const TargetLibraryInfo *TLI, AssumptionCache *AC )
970+ : SE(SE), AA(AA), DT(DT), LI(LI), TTI(TTI), TLI(TLI), AC(AC) {}
944971
945972 LLVM_ABI const LoopAccessInfo &getInfo (Loop &L, bool AllowPartial = false );
946973
0 commit comments