@@ -793,7 +793,8 @@ class AccessAnalysis {
793
793
794
794
} // end anonymous namespace
795
795
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.
797
798
static std::optional<int64_t >
798
799
getStrideFromAddRec (const SCEVAddRecExpr *AR, const Loop *Lp, Type *AccessTy,
799
800
Value *Ptr, PredicatedScalarEvolution &PSE) {
@@ -835,16 +836,24 @@ getStrideFromAddRec(const SCEVAddRecExpr *AR, const Loop *Lp, Type *AccessTy,
835
836
return Stride;
836
837
}
837
838
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);
840
841
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.
842
844
static bool isNoWrap (PredicatedScalarEvolution &PSE, const SCEVAddRecExpr *AR,
843
845
Value *Ptr, Type *AccessTy, const Loop *L, bool Assume,
844
846
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
+
845
854
// The address calculation must not wrap. Otherwise, a dependence could be
846
855
// inverted.
847
- if (isNoWrapAddRec (Ptr, AR , PSE, L))
856
+ if (isNoWrapGEP (Ptr, PSE, L))
848
857
return true ;
849
858
850
859
// An nusw getelementptr that is an AddRec cannot wrap. If it would wrap,
@@ -1445,18 +1454,9 @@ void AccessAnalysis::processMemAccesses() {
1445
1454
}
1446
1455
}
1447
1456
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) {
1460
1460
// Scalar evolution does not propagate the non-wrapping flags to values that
1461
1461
// are derived from a non-wrapping induction variable because non-wrapping
1462
1462
// could be flow-sensitive.
0 commit comments