@@ -798,8 +798,13 @@ getStrideFromAddRec(const SCEVAddRecExpr *AR, const Loop *Lp, Type *AccessTy,
798
798
Value *Ptr , PredicatedScalarEvolution &PSE) {
799
799
// The access function must stride over the innermost loop.
800
800
if (Lp != AR->getLoop ()) {
801
- LLVM_DEBUG (dbgs () << " LAA: Bad stride - Not striding over innermost loop "
802
- << *Ptr << " SCEV: " << *AR << " \n " );
801
+ LLVM_DEBUG ({
802
+ dbgs () << " LAA: Bad stride - Not striding over innermost loop " ;
803
+ if (Ptr )
804
+ dbgs () << *Ptr << " " ;
805
+
806
+ dbgs () << " SCEV: " << *AR << " \n " ;
807
+ });
803
808
return std::nullopt;
804
809
}
805
810
@@ -809,8 +814,12 @@ getStrideFromAddRec(const SCEVAddRecExpr *AR, const Loop *Lp, Type *AccessTy,
809
814
// Calculate the pointer stride and check if it is constant.
810
815
const SCEVConstant *C = dyn_cast<SCEVConstant>(Step);
811
816
if (!C) {
812
- LLVM_DEBUG (dbgs () << " LAA: Bad stride - Not a constant strided " << *Ptr
813
- << " SCEV: " << *AR << " \n " );
817
+ LLVM_DEBUG ({
818
+ dbgs () << " LAA: Bad stride - Not a constant strided " ;
819
+ if (Ptr )
820
+ dbgs () << *Ptr << " " ;
821
+ dbgs () << " SCEV: " << *AR << " \n " ;
822
+ });
814
823
return std::nullopt;
815
824
}
816
825
@@ -837,29 +846,29 @@ getStrideFromAddRec(const SCEVAddRecExpr *AR, const Loop *Lp, Type *AccessTy,
837
846
static bool isNoWrapGEP (Value *Ptr , PredicatedScalarEvolution &PSE,
838
847
const Loop *L);
839
848
840
- // / Check whether \p AR is a non-wrapping AddRec, or if \p Ptr is a non-wrapping
841
- // / GEP .
849
+ // / Check whether \p AR is a non-wrapping AddRec. If \p Ptr is not nullptr, use
850
+ // / informating from the IR pointer value to determine no-wrap .
842
851
static bool isNoWrap (PredicatedScalarEvolution &PSE, const SCEVAddRecExpr *AR,
843
852
Value *Ptr , Type *AccessTy, const Loop *L, bool Assume,
844
853
std::optional<int64_t > Stride = std::nullopt) {
845
854
// FIXME: This should probably only return true for NUW.
846
855
if (AR->getNoWrapFlags (SCEV::NoWrapMask))
847
856
return true ;
848
857
849
- if (PSE.hasNoOverflow (Ptr , SCEVWrapPredicate::IncrementNUSW))
858
+ if (Ptr && PSE.hasNoOverflow (Ptr , SCEVWrapPredicate::IncrementNUSW))
850
859
return true ;
851
860
852
861
// The address calculation must not wrap. Otherwise, a dependence could be
853
862
// inverted.
854
- if (isNoWrapGEP (Ptr , PSE, L))
863
+ if (Ptr && isNoWrapGEP (Ptr , PSE, L))
855
864
return true ;
856
865
857
866
// An nusw getelementptr that is an AddRec cannot wrap. If it would wrap,
858
867
// the distance between the previously accessed location and the wrapped
859
868
// location will be larger than half the pointer index type space. In that
860
869
// case, the GEP would be poison and any memory access dependent on it would
861
870
// be immediate UB when executed.
862
- if (auto *GEP = dyn_cast <GetElementPtrInst>(Ptr );
871
+ if (auto *GEP = dyn_cast_if_present <GetElementPtrInst>(Ptr );
863
872
GEP && GEP->hasNoUnsignedSignedWrap ())
864
873
return true ;
865
874
@@ -875,7 +884,7 @@ static bool isNoWrap(PredicatedScalarEvolution &PSE, const SCEVAddRecExpr *AR,
875
884
return true ;
876
885
}
877
886
878
- if (Assume) {
887
+ if (Ptr && Assume) {
879
888
PSE.setNoOverflow (Ptr , SCEVWrapPredicate::IncrementNUSW);
880
889
LLVM_DEBUG (dbgs () << " LAA: Pointer may wrap:\n "
881
890
<< " LAA: Pointer: " << *Ptr << " \n "
@@ -1117,6 +1126,7 @@ bool AccessAnalysis::createCheckForAccess(RuntimePointerChecking &RtCheck,
1117
1126
1118
1127
SmallVector<PointerIntPair<const SCEV *, 1 , bool >> TranslatedPtrs =
1119
1128
findForkedPointer (PSE, StridesMap, Ptr , TheLoop);
1129
+ assert (!TranslatedPtrs.empty () && " must have some translated pointers" );
1120
1130
1121
1131
// / Check whether all pointers can participate in a runtime bounds check. They
1122
1132
// / must either be invariant or AddRecs. If ShouldCheckWrap is true, they also
@@ -1142,13 +1152,10 @@ bool AccessAnalysis::createCheckForAccess(RuntimePointerChecking &RtCheck,
1142
1152
1143
1153
// When we run after a failing dependency check we have to make sure
1144
1154
// we don't have wrapping pointers.
1145
- if (ShouldCheckWrap) {
1146
- // Skip wrap checking when translating pointers.
1147
- if (TranslatedPtrs.size () > 1 )
1148
- return false ;
1149
-
1150
- if (!isNoWrap (PSE, AR, Ptr , AccessTy, TheLoop, Assume))
1151
- return false ;
1155
+ if (ShouldCheckWrap &&
1156
+ !isNoWrap (PSE, AR, TranslatedPtrs.size () == 1 ? Ptr : nullptr , AccessTy,
1157
+ TheLoop, Assume)) {
1158
+ return false ;
1152
1159
}
1153
1160
}
1154
1161
0 commit comments