Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(391)

Unified Diff: pkg/compiler/lib/src/ssa/optimize.dart

Issue 2842863003: dart2js: Move always-taken branch code to dominate join (Closed)
Patch Set: Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: pkg/compiler/lib/src/ssa/optimize.dart
diff --git a/pkg/compiler/lib/src/ssa/optimize.dart b/pkg/compiler/lib/src/ssa/optimize.dart
index 4b5679b33c1a4fe9666c5feaa8d8b5992a7500c2..b15ef7b0c1cc32754d03aa7f9b53ecb988affe54 100644
--- a/pkg/compiler/lib/src/ssa/optimize.dart
+++ b/pkg/compiler/lib/src/ssa/optimize.dart
@@ -1623,6 +1623,7 @@ class SsaDeadCodeEliminator extends HGraphVisitor implements OptimizationPhase {
instruction = previous;
}
block.forEachPhi(simplifyPhi);
+ evacuateTakenBranch(block);
}
void simplifyPhi(HPhi phi) {
@@ -1702,6 +1703,30 @@ class SsaDeadCodeEliminator extends HGraphVisitor implements OptimizationPhase {
return null;
}
+ /// If [block] is an always-taken branch, move the code from the taken branch
+ /// into [block]. This has the effect of making the instructions available for
+ /// further optimizations by moving them to a position that dominates the join
+ /// point of the if-then-else.
+ // TODO(29475): Delete dead blocks instead.
+ void evacuateTakenBranch(HBasicBlock block) {
+ if (!block.isLive) return;
+ HControlFlow branch = block.last;
+ if (branch is HIf) {
+ if (branch.thenBlock.isLive == branch.elseBlock.isLive) return;
+ assert(branch.condition.isConstant());
+ HBasicBlock target =
+ branch.thenBlock.isLive ? branch.thenBlock : branch.elseBlock;
+ HInstruction instruction = target.first;
+ while (!instruction.isControlFlow()) {
+ HInstruction next = instruction.next;
+ if (instruction is HTypeKnown && instruction.isPinned) break;
+ instruction.block.detach(instruction);
+ block.moveAtExit(instruction);
+ instruction = next;
+ }
+ }
+ }
+
void cleanPhis() {
L:
for (HBasicBlock block in _graph.blocks) {
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698