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 @@ -9606,9 +9606,10 @@ return; } - // A store of a loop varying value to a loop invariant address only - // needs only the last copy of the store. - if (isa(UI) && !getOperand(1)->hasDefiningRecipe()) { + // A store of a loop varying value to a uniform address only needs only the + // last copy of the store. + if (isa(UI) && + vputils::isUniformAfterVectorization(getOperand(1))) { auto Lane = VPLane::getLastLaneForVF(State.VF); State.ILV->scalarizeInstruction(UI, this, VPIteration(State.UF - 1, Lane), IsPredicated, State);