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 @@ -1236,24 +1236,23 @@ if (!requiresScalarEpilogue()) return; - // Avoid releasing a Group twice. - SmallPtrSet *, 4> DelSet; - for (auto &I : InterleaveGroupMap) { - InterleaveGroup *Group = I.second; - if (Group->requiresScalarEpilogue()) - DelSet.insert(Group); - } - assert(!DelSet.empty() && "At least one group must be invalidated, as a " - "scalar epilogue was required"); - for (auto *Ptr : DelSet) { + bool ReleasedGroup = false; + // Release groups requiring scalar epilogues. Note that this also removes them + // from InterleaveGroups. + for (auto *Group : make_early_inc_range(InterleaveGroups)) { + if (!Group->requiresScalarEpilogue()) + continue; LLVM_DEBUG( dbgs() << "LV: Invalidate candidate interleaved group due to gaps that " "require a scalar epilogue (not allowed under optsize) and cannot " "be masked (not enabled). \n"); - releaseGroup(Ptr); + releaseGroup(Group); + ReleasedGroup = true; } - + assert(ReleasedGroup && "At least one group must be invalidated, as a " + "scalar epilogue was required"); + (void)ReleasedGroup; RequiresScalarEpilogue = false; }