Skip to content

Commit 064092f

Browse files
committed
!fixup address comments, thanks
1 parent f29a2e4 commit 064092f

File tree

5 files changed

+29
-32
lines changed

5 files changed

+29
-32
lines changed

llvm/include/llvm/Analysis/LoopAccessAnalysis.h

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,14 @@ class MemoryDepChecker {
290290
return PointerBounds;
291291
}
292292

293-
AssumptionCache *getAC() const { return AC; }
294-
DominatorTree *getDT() const { return DT; }
293+
DominatorTree *getDT() const {
294+
assert(AC && "requested DT, but it is not available");
295+
return DT;
296+
}
297+
AssumptionCache *getAC() const {
298+
assert(AC && "requested AC, but it is not available");
299+
return AC;
300+
}
295301

296302
private:
297303
/// A wrapper around ScalarEvolution, used to add runtime SCEV checks, and
@@ -927,7 +933,7 @@ LLVM_ABI std::pair<const SCEV *, const SCEV *> getStartAndEndForAccess(
927933
const SCEV *MaxBTC, ScalarEvolution *SE,
928934
DenseMap<std::pair<const SCEV *, Type *>,
929935
std::pair<const SCEV *, const SCEV *>> *PointerBounds,
930-
AssumptionCache *AC, DominatorTree *DT);
936+
DominatorTree *DT, AssumptionCache *AC);
931937

932938
class LoopAccessInfoManager {
933939
/// The cache.
@@ -944,8 +950,9 @@ class LoopAccessInfoManager {
944950

945951
public:
946952
LoopAccessInfoManager(ScalarEvolution &SE, AAResults &AA, DominatorTree &DT,
947-
LoopInfo &LI, TargetTransformInfo *TTI,
948-
const TargetLibraryInfo *TLI, AssumptionCache *AC)
953+
LoopInfo &LI, TargetTransformInfo *TTI = nullptr,
954+
const TargetLibraryInfo *TLI = nullptr,
955+
AssumptionCache *AC = nullptr)
949956
: SE(SE), AA(AA), DT(DT), LI(LI), TTI(TTI), TLI(TLI), AC(AC) {}
950957

951958
LLVM_ABI const LoopAccessInfo &getInfo(Loop &L, bool AllowPartial = false);

llvm/lib/Analysis/Loads.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ bool llvm::isDereferenceableAndAlignedInLoop(
326326
return false;
327327

328328
const auto &[AccessStart, AccessEnd] = getStartAndEndForAccess(
329-
L, PtrScev, LI->getType(), BECount, MaxBECount, &SE, nullptr, AC, &DT);
329+
L, PtrScev, LI->getType(), BECount, MaxBECount, &SE, nullptr, &DT, AC);
330330
if (isa<SCEVCouldNotCompute>(AccessStart) ||
331331
isa<SCEVCouldNotCompute>(AccessEnd))
332332
return false;

llvm/lib/Analysis/LoopAccessAnalysis.cpp

Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ static bool
214214
evaluatePtrAddRecAtMaxBTCWillNotWrap(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_) &&

llvm/lib/Transforms/Scalar/LoopFlatten.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1009,8 +1009,7 @@ PreservedAnalyses LoopFlattenPass::run(LoopNest &LN, LoopAnalysisManager &LAM,
10091009
// in simplified form, and also needs LCSSA. Running
10101010
// this pass will simplify all loops that contain inner loops,
10111011
// regardless of whether anything ends up being flattened.
1012-
LoopAccessInfoManager LAIM(AR.SE, AR.AA, AR.DT, AR.LI, &AR.TTI, nullptr,
1013-
nullptr);
1012+
LoopAccessInfoManager LAIM(AR.SE, AR.AA, AR.DT, AR.LI, &AR.TTI);
10141013
for (Loop *InnerLoop : LN.getLoops()) {
10151014
auto *OuterLoop = InnerLoop->getParentLoop();
10161015
if (!OuterLoop)

llvm/lib/Transforms/Scalar/LoopVersioningLICM.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,7 @@ PreservedAnalyses LoopVersioningLICMPass::run(Loop &L, LoopAnalysisManager &AM,
551551
const Function *F = L.getHeader()->getParent();
552552
OptimizationRemarkEmitter ORE(F);
553553

554-
LoopAccessInfoManager LAIs(*SE, *AA, *DT, LAR.LI, nullptr, nullptr, nullptr);
554+
LoopAccessInfoManager LAIs(*SE, *AA, *DT, LAR.LI);
555555
if (!LoopVersioningLICM(AA, SE, &ORE, LAIs, LAR.LI, &L).run(DT))
556556
return PreservedAnalyses::all();
557557
return getLoopPassPreservedAnalyses();

0 commit comments

Comments
 (0)