diff --git a/js/src/ion/UnreachableCodeElimination.cpp b/js/src/ion/UnreachableCodeElimination.cpp index 6738a6364e4..75367fd313c 100644 --- a/js/src/ion/UnreachableCodeElimination.cpp +++ b/js/src/ion/UnreachableCodeElimination.cpp @@ -7,6 +7,7 @@ #include "UnreachableCodeElimination.h" #include "IonAnalysis.h" +#include "AliasAnalysis.h" using namespace js; using namespace ion; @@ -70,6 +71,13 @@ UnreachableCodeElimination::removeUnmarkedBlocksAndCleanup() if (redundantPhis_ && !EliminatePhis(mir_, graph_, ConservativeObservability)) return false; + // Pass 4: Rerun alias analysis + if (rerunAliasAnalysis_) { + AliasAnalysis analysis(mir_, graph_); + if (!analysis.analyze()) + return false; + } + return true; } @@ -128,8 +136,13 @@ UnreachableCodeElimination::prunePointlessBranchesAndMarkReachableBlocks() } void -UnreachableCodeElimination::removeUsesFromUnmarkedBlocks(MDefinition *instr) +UnreachableCodeElimination::checkDependencyAndRemoveUsesFromUnmarkedBlocks(MDefinition *instr) { + // When the instruction depends on removed block, + // alias analysis needs to get rerun to have the right dependency. + if (instr->dependency() && !instr->dependency()->block()->isMarked()) + rerunAliasAnalysis_ = true; + for (MUseIterator iter(instr->usesBegin()); iter != instr->usesEnd(); ) { if (!iter->consumer()->block()->isMarked()) iter = instr->removeUse(iter); @@ -161,9 +174,9 @@ UnreachableCodeElimination::removeUnmarkedBlocksAndClearDominators() if (block->isMarked()) { block->setId(--id); for (MPhiIterator iter(block->phisBegin()); iter != block->phisEnd(); iter++) - removeUsesFromUnmarkedBlocks(*iter); + checkDependencyAndRemoveUsesFromUnmarkedBlocks(*iter); for (MInstructionIterator iter(block->begin()); iter != block->end(); iter++) - removeUsesFromUnmarkedBlocks(*iter); + checkDependencyAndRemoveUsesFromUnmarkedBlocks(*iter); } else { if (block->numPredecessors() > 1) { // If this block had phis, then any reachable diff --git a/js/src/ion/UnreachableCodeElimination.h b/js/src/ion/UnreachableCodeElimination.h index 4e7e7e007a6..99a61eed7b7 100644 --- a/js/src/ion/UnreachableCodeElimination.h +++ b/js/src/ion/UnreachableCodeElimination.h @@ -22,9 +22,10 @@ class UnreachableCodeElimination MIRGraph &graph_; uint32_t marked_; bool redundantPhis_; + bool rerunAliasAnalysis_; bool prunePointlessBranchesAndMarkReachableBlocks(); - void removeUsesFromUnmarkedBlocks(MDefinition *instr); + void checkDependencyAndRemoveUsesFromUnmarkedBlocks(MDefinition *instr); bool removeUnmarkedBlocksAndClearDominators(); bool removeUnmarkedBlocksAndCleanup(); @@ -33,7 +34,8 @@ class UnreachableCodeElimination : mir_(mir), graph_(graph), marked_(0), - redundantPhis_(false) + redundantPhis_(false), + rerunAliasAnalysis_(false) {} // Walks the graph and discovers what is reachable. Removes everything else.