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

Unified Diff: dart/lib/compiler/implementation/ssa/codegen.dart

Issue 9950014: Eliminate branches on constant conditions during codegen. (Closed) Base URL: https://dart.googlecode.com/svn/branches/bleeding_edge
Patch Set: Address review comments Created 8 years, 9 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: dart/lib/compiler/implementation/ssa/codegen.dart
diff --git a/dart/lib/compiler/implementation/ssa/codegen.dart b/dart/lib/compiler/implementation/ssa/codegen.dart
index 91f179dc4a9da9b9577922cbbe83d70de4e0b08f..498f128412b35e53c3394bb16a651d3c149294ec 100644
--- a/dart/lib/compiler/implementation/ssa/codegen.dart
+++ b/dart/lib/compiler/implementation/ssa/codegen.dart
@@ -902,23 +902,36 @@ class SsaCodeGenerator implements HVisitor {
}
visitIf(HIf node) {
+ HInstruction condition = node.inputs[0];
+ int preVisitedBlocks = 0;
List<HBasicBlock> dominated = node.block.dominatedBlocks;
HIfBlockInformation info = node.blockInformation;
- startIf(node);
- assert(!isGenerateAtUseSite(node));
- startThen(node);
- assert(node.thenBlock === dominated[0]);
- visitSubGraph(info.thenGraph);
- int preVisitedBlocks = 1;
- endThen(node);
- if (node.hasElse) {
- startElse(node);
- assert(node.elseBlock === dominated[1]);
- visitSubGraph(info.elseGraph);
- preVisitedBlocks = 2;
- endElse(node);
- }
- endIf(node);
+ if (condition.isConstant()) {
+ HConstant constant = condition;
+ if (constant.constant.isTrue()) {
+ visitSubGraph(info.thenGraph);
+ } else if (node.hasElse) {
+ visitSubGraph(info.elseGraph);
+ }
+ // We ignore the other branch, even if it isn't visited.
+ preVisitedBlocks = node.hasElse ? 2 : 1;
+ } else {
+ startIf(node);
+ assert(!isGenerateAtUseSite(node));
+ startThen(node);
+ assert(node.thenBlock === dominated[0]);
+ visitSubGraph(info.thenGraph);
+ preVisitedBlocks++;
+ endThen(node);
+ if (node.hasElse) {
+ startElse(node);
+ assert(node.elseBlock === dominated[1]);
+ visitSubGraph(info.elseGraph);
+ preVisitedBlocks++;
+ endElse(node);
+ }
+ endIf(node);
+ }
if (info.joinBlock !== null && info.joinBlock.dominator !== node.block) {
// The join block is dominated by a block in one of the branches.
// The subgraph traversal never reached it, so we visit it here
« 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