From 8c42bd9ea4d837a43514da4f452c58e00c2e187f Mon Sep 17 00:00:00 2001 From: Allan Sandfeld Jensen Date: Wed, 27 Feb 2019 15:43:14 +0100 Subject: [PATCH] Avoid theoretical quadratic runtime on removing redundant moves Change-Id: I3b9a85e53333349b30f3acb6219e7e47861ca042 Reviewed-on: https://chromium-review.googlesource.com/c/v8/v8/+/1491596 Reviewed-by: Clemens Hammacher Reviewed-by: Ben Titzer Commit-Queue: Clemens Hammacher Cr-Commit-Position: refs/heads/master@{#60424} --- src/compiler/backend/gap-resolver.cc | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/compiler/backend/gap-resolver.cc b/src/compiler/backend/gap-resolver.cc index 1758ca2c5a..e11a8b6434 100644 --- a/src/compiler/backend/gap-resolver.cc +++ b/src/compiler/backend/gap-resolver.cc @@ -93,20 +93,23 @@ void GapResolver::Resolve(ParallelMove* moves) { // detect simple non-overlapping moves, and collect FP move representations if // aliasing is non-simple. int fp_reps = 0; - for (auto it = moves->begin(); it != moves->end();) { - MoveOperands* move = *it; + size_t nmoves = moves->size(); + for (size_t i = 0; i < nmoves;) { + MoveOperands* move = (*moves)[i]; if (move->IsRedundant()) { - it = moves->erase(it); + nmoves--; + if (i < nmoves) (*moves)[i] = (*moves)[nmoves]; continue; } + i++; source_kinds.Add(GetKind(move->source())); destination_kinds.Add(GetKind(move->destination())); if (!kSimpleFPAliasing && move->destination().IsFPRegister()) { fp_reps |= RepresentationBit( LocationOperand::cast(move->destination()).representation()); } - ++it; } + if (nmoves != moves->size()) moves->resize(nmoves); if ((source_kinds & destination_kinds).empty() || moves->size() < 2) { // Fast path for non-conflicting parallel moves.