diff --git a/llvm/lib/Analysis/LoopAccessAnalysis.cpp b/llvm/lib/Analysis/LoopAccessAnalysis.cpp --- a/llvm/lib/Analysis/LoopAccessAnalysis.cpp +++ b/llvm/lib/Analysis/LoopAccessAnalysis.cpp @@ -2561,6 +2561,11 @@ if (!Ptr) return; + // If the pointer is invariant then there is no stride and it makes no + // sense to add it here. + if (TheLoop->isLoopInvariant(Ptr)) + return; + Value *Stride = getStrideFromPointer(Ptr, PSE->getSE(), TheLoop); if (!Stride) return; diff --git a/llvm/lib/Analysis/VectorUtils.cpp b/llvm/lib/Analysis/VectorUtils.cpp --- a/llvm/lib/Analysis/VectorUtils.cpp +++ b/llvm/lib/Analysis/VectorUtils.cpp @@ -1157,6 +1157,12 @@ Value *Ptr = getLoadStorePointerOperand(&I); if (!Ptr) continue; + + // If the pointer is invariant then there is no stride and it makes no + // sense to add it here. + if (TheLoop->isLoopInvariant(Ptr)) + continue; + Type *ElementTy = getLoadStoreType(&I); // Currently, codegen doesn't support cases where the type size doesn't diff --git a/llvm/test/Transforms/LoopVectorize/vector-no-scevcheck.ll b/llvm/test/Transforms/LoopVectorize/vector-no-scevcheck.ll --- a/llvm/test/Transforms/LoopVectorize/vector-no-scevcheck.ll +++ b/llvm/test/Transforms/LoopVectorize/vector-no-scevcheck.ll @@ -1,4 +1,3 @@ -; FIXME: this will fail unless D146958 is applied. ; RUN: opt -passes=loop-vectorize -force-vector-width=2 -force-vector-interleave=1 -S < %s | FileCheck %s define void @foo(ptr %pout, ptr %pin, i64 %val0, i64 %val1, i64 %val2) {