@@ -203,11 +203,18 @@ RuntimeCheckingPtrGroup::RuntimeCheckingPtrGroup(
203203// /
204204// / There is no conflict when the intervals are disjoint:
205205// / NoConflict = (P2.Start >= P1.End) || (P1.Start >= P2.End)
206- static std::pair<const SCEV *, const SCEV *>
207- getStartAndEndForAccess (const Loop *Lp, const SCEV *PtrExpr, Type *AccessTy,
208- PredicatedScalarEvolution &PSE) {
206+ static std::pair<const SCEV *, const SCEV *> getStartAndEndForAccess (
207+ const Loop *Lp, const SCEV *PtrExpr, Type *AccessTy,
208+ PredicatedScalarEvolution &PSE,
209+ DenseMap<const SCEV *, std::pair<const SCEV *, const SCEV *>>
210+ &PointerBounds) {
209211 ScalarEvolution *SE = PSE.getSE ();
210212
213+ auto [Iter, Ins] = PointerBounds.insert (
214+ {PtrExpr, {SE->getCouldNotCompute (), SE->getCouldNotCompute ()}});
215+ if (!Ins)
216+ return Iter->second ;
217+
211218 const SCEV *ScStart;
212219 const SCEV *ScEnd;
213220
@@ -244,7 +251,8 @@ getStartAndEndForAccess(const Loop *Lp, const SCEV *PtrExpr, Type *AccessTy,
244251 const SCEV *EltSizeSCEV = SE->getStoreSizeOfExpr (IdxTy, AccessTy);
245252 ScEnd = SE->getAddExpr (ScEnd, EltSizeSCEV);
246253
247- return {ScStart, ScEnd};
254+ Iter->second = {ScStart, ScEnd};
255+ return Iter->second ;
248256}
249257
250258// / Calculate Start and End points of memory access using
@@ -254,8 +262,8 @@ void RuntimePointerChecking::insert(Loop *Lp, Value *Ptr, const SCEV *PtrExpr,
254262 unsigned DepSetId, unsigned ASId,
255263 PredicatedScalarEvolution &PSE,
256264 bool NeedsFreeze) {
257- const auto &[ScStart, ScEnd] =
258- getStartAndEndForAccess ( Lp, PtrExpr, AccessTy, PSE);
265+ const auto &[ScStart, ScEnd] = getStartAndEndForAccess (
266+ Lp, PtrExpr, AccessTy, PSE, DC. getPointerBounds () );
259267 assert (!isa<SCEVCouldNotCompute>(ScStart) &&
260268 !isa<SCEVCouldNotCompute>(ScEnd) &&
261269 " must be able to compute both start and end expressions" );
@@ -1964,10 +1972,9 @@ MemoryDepChecker::getDependenceDistanceStrideAndSize(
19641972 if (SE.isLoopInvariant (Src, InnermostLoop) ||
19651973 SE.isLoopInvariant (Sink, InnermostLoop)) {
19661974 const auto &[SrcStart, SrcEnd] =
1967- getStartAndEndForAccess (InnermostLoop, Src, ATy, PSE);
1975+ getStartAndEndForAccess (InnermostLoop, Src, ATy, PSE, PointerBounds );
19681976 const auto &[SinkStart, SinkEnd] =
1969- getStartAndEndForAccess (InnermostLoop, Sink, BTy, PSE);
1970-
1977+ getStartAndEndForAccess (InnermostLoop, Sink, BTy, PSE, PointerBounds);
19711978 if (!isa<SCEVCouldNotCompute>(SrcStart) &&
19721979 !isa<SCEVCouldNotCompute>(SrcEnd) &&
19731980 !isa<SCEVCouldNotCompute>(SinkStart) &&
0 commit comments