Skip to content

Commit a579ced

Browse files
committed
LAA: address review
1 parent f59af3b commit a579ced

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

llvm/lib/Analysis/LoopAccessAnalysis.cpp

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -797,11 +797,11 @@ class AccessAnalysis {
797797
/// isNoWrap.
798798
static std::optional<int64_t>
799799
getStrideFromAddRec(const SCEVAddRecExpr *AR, const Loop *Lp, Type *AccessTy,
800-
PredicatedScalarEvolution &PSE) {
800+
Value *Ptr, PredicatedScalarEvolution &PSE) {
801801
// The access function must stride over the innermost loop.
802802
if (Lp != AR->getLoop()) {
803803
LLVM_DEBUG(dbgs() << "LAA: Bad stride - Not striding over innermost loop "
804-
<< "SCEV: " << *AR << "\n");
804+
<< *Ptr << " SCEV: " << *AR << "\n");
805805
return std::nullopt;
806806
}
807807

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

@@ -848,6 +848,9 @@ static bool isNoWrap(PredicatedScalarEvolution &PSE, const SCEVAddRecExpr *AR,
848848
if (AR->getNoWrapFlags(SCEV::NoWrapMask))
849849
return true;
850850

851+
if (PSE.hasNoOverflow(Ptr, SCEVWrapPredicate::IncrementNUSW))
852+
return true;
853+
851854
// The address calculation must not wrap. Otherwise, a dependence could be
852855
// inverted.
853856
if (isNoWrapGEP(Ptr, PSE, L))
@@ -863,7 +866,7 @@ static bool isNoWrap(PredicatedScalarEvolution &PSE, const SCEVAddRecExpr *AR,
863866
return true;
864867

865868
if (!Stride)
866-
Stride = getStrideFromAddRec(AR, L, AccessTy, PSE);
869+
Stride = getStrideFromAddRec(AR, L, AccessTy, Ptr, PSE);
867870
if (Stride) {
868871
// If the null pointer is undefined, then a access sequence which would
869872
// otherwise access it can be assumed not to unsigned wrap. Note that this
@@ -1454,9 +1457,6 @@ void AccessAnalysis::processMemAccesses() {
14541457
/// Check whether \p Ptr is non-wrapping GEP.
14551458
static bool isNoWrapGEP(Value *Ptr, PredicatedScalarEvolution &PSE,
14561459
const Loop *L) {
1457-
if (PSE.hasNoOverflow(Ptr, SCEVWrapPredicate::IncrementNUSW))
1458-
return true;
1459-
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.
@@ -1524,7 +1524,8 @@ llvm::getPtrStride(PredicatedScalarEvolution &PSE, Type *AccessTy, Value *Ptr,
15241524
return std::nullopt;
15251525
}
15261526

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

0 commit comments

Comments
 (0)