diff --git a/llvm/lib/Analysis/Loads.cpp b/llvm/lib/Analysis/Loads.cpp --- a/llvm/lib/Analysis/Loads.cpp +++ b/llvm/lib/Analysis/Loads.cpp @@ -286,15 +286,22 @@ auto* Step = dyn_cast(AddRec->getStepRecurrence(SE)); if (!Step) return false; - // TODO: generalize to access patterns which have gaps - if (Step->getAPInt() != EltSize) - return false; auto TC = SE.getSmallConstantMaxTripCount(L); if (!TC) return false; - const APInt AccessSize = TC * EltSize; + // For now, just ignore overlapping accesses. + // TODO: We should be taking max(Step,EltSize) for computing AccessSize + // below. + if (EltSize.sgt(Step->getAPInt())) + return false; + // Compute the total access size for access patterns with unit stride and + // patterns with gaps. For patterns with unit stride, Step and EltSize are the + // same. + // For patterns with gaps (i.e. non unit stride), we are + // accessing EltSize bytes at every Step. + const APInt AccessSize = TC * Step->getAPInt(); auto *StartS = dyn_cast(AddRec->getStart()); if (!StartS)