diff --git a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp --- a/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp +++ b/llvm/lib/Transforms/Vectorize/VPlanTransforms.cpp @@ -431,9 +431,11 @@ IV->getStartValue(), Step, TruncI ? TruncI->getType() : nullptr); HeaderVPBB->insert(Steps, HeaderVPBB->getFirstNonPhi()); - // If there are no vector users of IV, simply update all users to use Step + // If there are no vector users of IV, simply update all users to use Steps // instead. - if (!IV->needsVectorIV()) { + if (all_of(IV->users(), [IV](VPUser *U) { + return cast(U)->usesScalars(IV); + })) { IV->replaceAllUsesWith(Steps); continue; }