diff --git a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp --- a/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp +++ b/llvm/lib/Transforms/Vectorize/LoopVectorize.cpp @@ -4671,9 +4671,17 @@ if (Cmp && TheLoop->contains(Cmp) && Cmp->hasOneUse()) addToWorklistIfAllowed(Cmp); + auto PrevVF = VF.divideCoefficientBy(2); // Return true if all lanes perform the same memory operation, and we can // thus chose to execute only one. auto isUniformMemOpUse = [&](Instruction *I) { + // If the value was already known to not be uniform for the previous + // (smaller VF), it cannot be uniform for the larger VF. + if (PrevVF.isVector()) { + auto Iter = Uniforms.find(PrevVF); + if (Iter != Uniforms.end() && !Iter->second.contains(I)) + return false; + } if (!Legal->isUniformMemOp(*I)) return false; if (isa(I))