Index: lib/Analysis/LoopAccessAnalysis.cpp =================================================================== --- lib/Analysis/LoopAccessAnalysis.cpp +++ lib/Analysis/LoopAccessAnalysis.cpp @@ -1463,11 +1463,19 @@ LLVM_DEBUG(dbgs() << "LAA: Distance for " << *InstMap[AIdx] << " to " << *InstMap[BIdx] << ": " << *Dist << "\n"); + const SCEVConstant *C = dyn_cast(Dist); // Need accesses with constant stride. We don't want to vectorize // "A[B[i]] += ..." and similar code or pointer arithmetic that could wrap in // the address space. if (!StrideAPtr || !StrideBPtr || StrideAPtr != StrideBPtr){ LLVM_DEBUG(dbgs() << "Pointer access with non-constant stride\n"); + // Given StrideAPtr and StrideBPtr exists, we know the pointer arithmetic + // does not wrap. Even if they are not the same stride, if the distance + // between source and sink is constant wrt the loop, then let us try with + // runtime checks. + if (StrideAPtr && StrideBPtr && + (C || PSE.getSE()->isLoopInvariant(Dist, InnermostLoop))) + ShouldRetryWithRuntimeCheck = true; return Dependence::Unknown; } @@ -1476,7 +1484,6 @@ auto &DL = InnermostLoop->getHeader()->getModule()->getDataLayout(); uint64_t TypeByteSize = DL.getTypeAllocSize(ATy); uint64_t Stride = std::abs(StrideAPtr); - const SCEVConstant *C = dyn_cast(Dist); if (!C) { if (TypeByteSize == DL.getTypeAllocSize(BTy) && isSafeDependenceDistance(DL, *(PSE.getSE()),