@@ -214,7 +214,7 @@ static bool
214214evaluatePtrAddRecAtMaxBTCWillNotWrap (const SCEVAddRecExpr *AR,
215215 const SCEV *MaxBTC, const SCEV *EltSize,
216216 ScalarEvolution &SE, const DataLayout &DL,
217- AssumptionCache *AC, DominatorTree *DT ) {
217+ DominatorTree *DT, AssumptionCache *AC ) {
218218 auto *PointerBase = SE.getPointerBase (AR->getStart ());
219219 auto *StartPtr = dyn_cast<SCEVUnknown>(PointerBase);
220220 if (!StartPtr)
@@ -233,23 +233,14 @@ evaluatePtrAddRecAtMaxBTCWillNotWrap(const SCEVAddRecExpr *AR,
233233 const SCEV *DerefBytesSCEV = SE.getConstant (WiderTy, DerefBytes);
234234
235235 // Check if we have a suitable dereferencable assumption we can use.
236- RetainedKnowledge DerefRK;
237- if (!StartPtrV->canBeFreed () &&
238- getKnowledgeForValue (
239- StartPtrV, {Attribute::Dereferenceable}, *AC,
240- [&](RetainedKnowledge RK, Instruction *Assume, auto ) {
241- if (!isValidAssumeForContext (
242- Assume, L->getLoopPredecessor ()->getTerminator (), DT))
243- return false ;
244- if (RK.AttrKind == Attribute::Dereferenceable) {
245- DerefRK = std::max (DerefRK, RK);
246- return true ;
247- }
248- return false ;
249- }) &&
250- DerefRK.ArgValue ) {
251- DerefBytesSCEV = SE.getUMaxExpr (DerefBytesSCEV,
252- SE.getConstant (WiderTy, DerefRK.ArgValue ));
236+ if (!StartPtrV->canBeFreed ()) {
237+ RetainedKnowledge DerefRK = getKnowledgeValidInContext (
238+ StartPtrV, {Attribute::Dereferenceable}, *AC,
239+ L->getLoopPredecessor ()->getTerminator (), DT);
240+ if (DerefRK) {
241+ DerefBytesSCEV = SE.getUMaxExpr (
242+ DerefBytesSCEV, SE.getConstant (WiderTy, DerefRK.ArgValue ));
243+ }
253244 }
254245
255246 bool IsKnownNonNegative = SE.isKnownNonNegative (Step);
@@ -298,7 +289,7 @@ std::pair<const SCEV *, const SCEV *> llvm::getStartAndEndForAccess(
298289 const SCEV *MaxBTC, ScalarEvolution *SE,
299290 DenseMap<std::pair<const SCEV *, Type *>,
300291 std::pair<const SCEV *, const SCEV *>> *PointerBounds,
301- AssumptionCache *AC, DominatorTree *DT ) {
292+ DominatorTree *DT, AssumptionCache *AC ) {
302293 std::pair<const SCEV *, const SCEV *> *PtrBoundsPair;
303294 if (PointerBounds) {
304295 auto [Iter, Ins] = PointerBounds->insert (
@@ -334,7 +325,7 @@ std::pair<const SCEV *, const SCEV *> llvm::getStartAndEndForAccess(
334325 // separately checks that accesses cannot not wrap, so unsigned max
335326 // represents an upper bound.
336327 if (evaluatePtrAddRecAtMaxBTCWillNotWrap (AR, MaxBTC, EltSizeSCEV, *SE, DL,
337- AC, DT )) {
328+ DT, AC )) {
338329 ScEnd = AR->evaluateAtIteration (MaxBTC, *SE);
339330 } else {
340331 ScEnd = SE->getAddExpr (
@@ -383,7 +374,7 @@ void RuntimePointerChecking::insert(Loop *Lp, Value *Ptr, const SCEV *PtrExpr,
383374 const SCEV *BTC = PSE.getBackedgeTakenCount ();
384375 const auto &[ScStart, ScEnd] = getStartAndEndForAccess (
385376 Lp, PtrExpr, AccessTy, BTC, SymbolicMaxBTC, PSE.getSE (),
386- &DC.getPointerBounds (), DC.getAC (), DC.getDT ());
377+ &DC.getPointerBounds (), DC.getDT (), DC.getAC ());
387378 assert (!isa<SCEVCouldNotCompute>(ScStart) &&
388379 !isa<SCEVCouldNotCompute>(ScEnd) &&
389380 " must be able to compute both start and end expressions" );
@@ -2036,10 +2027,10 @@ MemoryDepChecker::getDependenceDistanceStrideAndSize(
20362027 const SCEV *SymbolicMaxBTC = PSE.getSymbolicMaxBackedgeTakenCount ();
20372028 const auto &[SrcStart_, SrcEnd_] =
20382029 getStartAndEndForAccess (InnermostLoop, Src, ATy, BTC, SymbolicMaxBTC,
2039- PSE.getSE (), &PointerBounds, AC, DT );
2030+ PSE.getSE (), &PointerBounds, DT, AC );
20402031 const auto &[SinkStart_, SinkEnd_] =
20412032 getStartAndEndForAccess (InnermostLoop, Sink, BTy, BTC, SymbolicMaxBTC,
2042- PSE.getSE (), &PointerBounds, AC, DT );
2033+ PSE.getSE (), &PointerBounds, DT, AC );
20432034 if (!isa<SCEVCouldNotCompute>(SrcStart_) &&
20442035 !isa<SCEVCouldNotCompute>(SrcEnd_) &&
20452036 !isa<SCEVCouldNotCompute>(SinkStart_) &&
0 commit comments