Skip to content

Commit 6d86a8a

Browse files
authored
LAA: scope responsibility of isNoWrapAddRec (NFC) (#127479)
Free isNoWrapAddRec from the AddRec check, and rename it to isNoWrapGEP.
1 parent 6a30076 commit 6d86a8a

File tree

1 file changed

+17
-17
lines changed

1 file changed

+17
-17
lines changed

llvm/lib/Analysis/LoopAccessAnalysis.cpp

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,8 @@ 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,
799800
Value *Ptr, PredicatedScalarEvolution &PSE) {
@@ -835,16 +836,24 @@ 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+
851+
if (PSE.hasNoOverflow(Ptr, SCEVWrapPredicate::IncrementNUSW))
852+
return true;
853+
845854
// The address calculation must not wrap. Otherwise, a dependence could be
846855
// inverted.
847-
if (isNoWrapAddRec(Ptr, AR, PSE, L))
856+
if (isNoWrapGEP(Ptr, PSE, L))
848857
return true;
849858

850859
// An nusw getelementptr that is an AddRec cannot wrap. If it would wrap,
@@ -1445,18 +1454,9 @@ void AccessAnalysis::processMemAccesses() {
14451454
}
14461455
}
14471456

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-
1457-
if (PSE.hasNoOverflow(Ptr, SCEVWrapPredicate::IncrementNUSW))
1458-
return true;
1459-
1457+
/// Check whether \p Ptr is non-wrapping GEP.
1458+
static bool isNoWrapGEP(Value *Ptr, PredicatedScalarEvolution &PSE,
1459+
const Loop *L) {
14601460
// Scalar evolution does not propagate the non-wrapping flags to values that
14611461
// are derived from a non-wrapping induction variable because non-wrapping
14621462
// could be flow-sensitive.

0 commit comments

Comments
 (0)