Skip to content

Commit f59af3b

Browse files
committed
LAA: drop unnecessary args, clarifying APIs
Drop unnecessary arguments in the APIs of getStrideFromAddRec and isNoWrapAddRec, to clarify their usage. Additionally, free isNoWrapAddRec from the AddRec check, and rename it to isNoWrapGEP.
1 parent a177be5 commit f59af3b

File tree

1 file changed

+20
-21
lines changed

1 file changed

+20
-21
lines changed

llvm/lib/Analysis/LoopAccessAnalysis.cpp

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -793,14 +793,15 @@ class AccessAnalysis {
793793

794794
} // end anonymous namespace
795795

796-
/// Try to compute the stride for \p AR. Used by getPtrStride.
796+
/// Try to compute a constant stride for \p AR. Used by getPtrStride and
797+
/// isNoWrap.
797798
static std::optional<int64_t>
798799
getStrideFromAddRec(const SCEVAddRecExpr *AR, const Loop *Lp, Type *AccessTy,
799-
Value *Ptr, PredicatedScalarEvolution &PSE) {
800+
PredicatedScalarEvolution &PSE) {
800801
// The access function must stride over the innermost loop.
801802
if (Lp != AR->getLoop()) {
802803
LLVM_DEBUG(dbgs() << "LAA: Bad stride - Not striding over innermost loop "
803-
<< *Ptr << " SCEV: " << *AR << "\n");
804+
<< "SCEV: " << *AR << "\n");
804805
return std::nullopt;
805806
}
806807

@@ -810,8 +811,8 @@ getStrideFromAddRec(const SCEVAddRecExpr *AR, const Loop *Lp, Type *AccessTy,
810811
// Calculate the pointer stride and check if it is constant.
811812
const SCEVConstant *C = dyn_cast<SCEVConstant>(Step);
812813
if (!C) {
813-
LLVM_DEBUG(dbgs() << "LAA: Bad stride - Not a constant strided " << *Ptr
814-
<< " SCEV: " << *AR << "\n");
814+
LLVM_DEBUG(dbgs() << "LAA: Bad stride - Not a constant strided "
815+
<< "SCEV: " << *AR << "\n");
815816
return std::nullopt;
816817
}
817818

@@ -835,16 +836,21 @@ getStrideFromAddRec(const SCEVAddRecExpr *AR, const Loop *Lp, Type *AccessTy,
835836
return Stride;
836837
}
837838

838-
static bool isNoWrapAddRec(Value *Ptr, const SCEVAddRecExpr *AR,
839-
PredicatedScalarEvolution &PSE, const Loop *L);
839+
static bool isNoWrapGEP(Value *Ptr, PredicatedScalarEvolution &PSE,
840+
const Loop *L);
840841

841-
/// Check whether a pointer address cannot wrap.
842+
/// Check whether \p AR is a non-wrapping AddRec, or if \p Ptr is a non-wrapping
843+
/// GEP.
842844
static bool isNoWrap(PredicatedScalarEvolution &PSE, const SCEVAddRecExpr *AR,
843845
Value *Ptr, Type *AccessTy, const Loop *L, bool Assume,
844846
std::optional<int64_t> Stride = std::nullopt) {
847+
// FIXME: This should probably only return true for NUW.
848+
if (AR->getNoWrapFlags(SCEV::NoWrapMask))
849+
return true;
850+
845851
// The address calculation must not wrap. Otherwise, a dependence could be
846852
// inverted.
847-
if (isNoWrapAddRec(Ptr, AR, PSE, L))
853+
if (isNoWrapGEP(Ptr, PSE, L))
848854
return true;
849855

850856
// An nusw getelementptr that is an AddRec cannot wrap. If it would wrap,
@@ -857,7 +863,7 @@ static bool isNoWrap(PredicatedScalarEvolution &PSE, const SCEVAddRecExpr *AR,
857863
return true;
858864

859865
if (!Stride)
860-
Stride = getStrideFromAddRec(AR, L, AccessTy, Ptr, PSE);
866+
Stride = getStrideFromAddRec(AR, L, AccessTy, PSE);
861867
if (Stride) {
862868
// If the null pointer is undefined, then a access sequence which would
863869
// otherwise access it can be assumed not to unsigned wrap. Note that this
@@ -1445,15 +1451,9 @@ void AccessAnalysis::processMemAccesses() {
14451451
}
14461452
}
14471453

1448-
/// Return true if an AddRec pointer \p Ptr is unsigned non-wrapping,
1449-
/// i.e. monotonically increasing/decreasing.
1450-
static bool isNoWrapAddRec(Value *Ptr, const SCEVAddRecExpr *AR,
1451-
PredicatedScalarEvolution &PSE, const Loop *L) {
1452-
1453-
// FIXME: This should probably only return true for NUW.
1454-
if (AR->getNoWrapFlags(SCEV::NoWrapMask))
1455-
return true;
1456-
1454+
/// Check whether \p Ptr is non-wrapping GEP.
1455+
static bool isNoWrapGEP(Value *Ptr, PredicatedScalarEvolution &PSE,
1456+
const Loop *L) {
14571457
if (PSE.hasNoOverflow(Ptr, SCEVWrapPredicate::IncrementNUSW))
14581458
return true;
14591459

@@ -1524,8 +1524,7 @@ llvm::getPtrStride(PredicatedScalarEvolution &PSE, Type *AccessTy, Value *Ptr,
15241524
return std::nullopt;
15251525
}
15261526

1527-
std::optional<int64_t> Stride =
1528-
getStrideFromAddRec(AR, Lp, AccessTy, Ptr, PSE);
1527+
std::optional<int64_t> Stride = getStrideFromAddRec(AR, Lp, AccessTy, PSE);
15291528
if (!ShouldCheckWrap || !Stride)
15301529
return Stride;
15311530

0 commit comments

Comments
 (0)