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

Unified Diff: src/compiler/control-reducer.cc

Issue 880533002: [turbofan] Simplify reduction if IfTrue and IfFalse and fix bugs. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 years, 11 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 | « src/compiler/control-reducer.h ('k') | test/cctest/compiler/test-control-reducer.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/compiler/control-reducer.cc
diff --git a/src/compiler/control-reducer.cc b/src/compiler/control-reducer.cc
index 0c260623763fb8fb9ab53a0f642e4b8e4c159e9d..7f4bf317496270ce723f3adf46bd3b5a7e5d02e6 100644
--- a/src/compiler/control-reducer.cc
+++ b/src/compiler/control-reducer.cc
@@ -357,8 +357,10 @@ class ControlReducerImpl {
// Reduce branches, phis, and merges.
switch (node->opcode()) {
- case IrOpcode::kBranch:
- return ReduceBranch(node);
+ case IrOpcode::kIfTrue:
+ return ReduceIfTrue(node);
+ case IrOpcode::kIfFalse:
+ return ReduceIfFalse(node);
case IrOpcode::kLoop:
case IrOpcode::kMerge:
return ReduceMerge(node);
@@ -480,30 +482,31 @@ class ControlReducerImpl {
}
// Reduce branches if they have constant inputs.
- Node* ReduceBranch(Node* node) {
- Decision result = DecideCondition(node->InputAt(0));
- if (result == kUnknown) return node;
-
- TRACE(("BranchReduce: #%d:%s = %s\n", node->id(), node->op()->mnemonic(),
- (result == kTrue) ? "true" : "false"));
-
- // Replace IfTrue and IfFalse projections from this branch.
- Node* control = NodeProperties::GetControlInput(node);
- for (Edge edge : node->use_edges()) {
- Node* use = edge.from();
- if (use->opcode() == IrOpcode::kIfTrue) {
- TRACE((" IfTrue: #%d:%s\n", use->id(), use->op()->mnemonic()));
- edge.UpdateTo(NULL);
- ReplaceNode(use, (result == kTrue) ? control : dead());
- control = NodeProperties::GetControlInput(node); // Could change!
- } else if (use->opcode() == IrOpcode::kIfFalse) {
- TRACE((" IfFalse: #%d:%s\n", use->id(), use->op()->mnemonic()));
- edge.UpdateTo(NULL);
- ReplaceNode(use, (result == kTrue) ? dead() : control);
- control = NodeProperties::GetControlInput(node); // Could change!
- }
+ Node* ReduceIfTrue(Node* node) {
+ Node* branch = node->InputAt(0);
+ DCHECK_EQ(IrOpcode::kBranch, branch->opcode());
+ Decision result = DecideCondition(branch->InputAt(0));
+ if (result == kTrue) {
+ // fold a true branch by replacing IfTrue with the branch control.
+ TRACE(("BranchReduce: #%d:%s => #%d:%s\n", branch->id(),
+ branch->op()->mnemonic(), node->id(), node->op()->mnemonic()));
+ return branch->InputAt(1);
+ }
+ return result == kUnknown ? node : dead();
+ }
+
+ // Reduce branches if they have constant inputs.
+ Node* ReduceIfFalse(Node* node) {
+ Node* branch = node->InputAt(0);
+ DCHECK_EQ(IrOpcode::kBranch, branch->opcode());
+ Decision result = DecideCondition(branch->InputAt(0));
+ if (result == kFalse) {
+ // fold a false branch by replacing IfFalse with the branch control.
+ TRACE(("BranchReduce: #%d:%s => #%d:%s\n", branch->id(),
+ branch->op()->mnemonic(), node->id(), node->op()->mnemonic()));
+ return branch->InputAt(1);
}
- return control;
+ return result == kUnknown ? node : dead();
}
// Remove inputs to {node} corresponding to the dead inputs to {merge}
@@ -578,12 +581,19 @@ Node* ControlReducer::ReduceMergeForTesting(JSGraph* jsgraph,
}
-Node* ControlReducer::ReduceBranchForTesting(JSGraph* jsgraph,
+Node* ControlReducer::ReduceIfNodeForTesting(JSGraph* jsgraph,
CommonOperatorBuilder* common,
Node* node) {
Zone zone;
ControlReducerImpl impl(&zone, jsgraph, common);
- return impl.ReduceBranch(node);
+ switch (node->opcode()) {
+ case IrOpcode::kIfTrue:
+ return impl.ReduceIfTrue(node);
+ case IrOpcode::kIfFalse:
+ return impl.ReduceIfFalse(node);
+ default:
+ return node;
+ }
}
}
}
« no previous file with comments | « src/compiler/control-reducer.h ('k') | test/cctest/compiler/test-control-reducer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698