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

Unified Diff: test/cctest/compiler/test-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.cc ('k') | test/mjsunit/regress/regress-451958.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: test/cctest/compiler/test-control-reducer.cc
diff --git a/test/cctest/compiler/test-control-reducer.cc b/test/cctest/compiler/test-control-reducer.cc
index 13e60bc13cd80aca4957db4c198bb12e61c8a3d7..c4a1190281929da27d7ac91df50974db42ebfaec 100644
--- a/test/cctest/compiler/test-control-reducer.cc
+++ b/test/cctest/compiler/test-control-reducer.cc
@@ -17,6 +17,8 @@ using namespace v8::internal::compiler;
static const size_t kNumLeafs = 4;
+enum Decision { kFalse, kUnknown, kTrue };
+
// TODO(titzer): convert this whole file into unit tests.
static int CheckInputs(Node* node, Node* i0 = NULL, Node* i1 = NULL,
@@ -175,10 +177,25 @@ class ControlReducerTester : HandleAndZoneScope {
CheckInputs(end, expect);
}
- void ReduceBranch(Node* expect, Node* branch) {
- Node* result =
- ControlReducer::ReduceBranchForTesting(&jsgraph, &common, branch);
- CHECK_EQ(expect, result);
+ void ReduceBranch(Decision expected, Node* branch) {
+ Node* control = branch->InputAt(1);
+ for (Node* use : branch->uses()) {
+ if (use->opcode() == IrOpcode::kIfTrue) {
+ Node* result =
+ ControlReducer::ReduceIfNodeForTesting(&jsgraph, &common, use);
+ if (expected == kTrue) CHECK_EQ(control, result);
+ if (expected == kFalse) CHECK_EQ(IrOpcode::kDead, result->opcode());
+ if (expected == kUnknown) CHECK_EQ(use, result);
+ } else if (use->opcode() == IrOpcode::kIfFalse) {
+ Node* result =
+ ControlReducer::ReduceIfNodeForTesting(&jsgraph, &common, use);
+ if (expected == kFalse) CHECK_EQ(control, result);
+ if (expected == kTrue) CHECK_EQ(IrOpcode::kDead, result->opcode());
+ if (expected == kUnknown) CHECK_EQ(use, result);
+ } else {
+ UNREACHABLE();
+ }
+ }
}
Node* Return(Node* val, Node* effect, Node* control) {
@@ -1028,7 +1045,7 @@ struct While {
TEST(CBranchReduce_none1) {
ControlReducerTester R;
Diamond d(R, R.p0);
- R.ReduceBranch(d.branch, d.branch);
+ R.ReduceBranch(kUnknown, d.branch);
}
@@ -1037,7 +1054,7 @@ TEST(CBranchReduce_none2) {
Diamond d1(R, R.p0);
Diamond d2(R, R.p0);
d2.chain(d1);
- R.ReduceBranch(d2.branch, d2.branch);
+ R.ReduceBranch(kUnknown, d2.branch);
}
@@ -1050,13 +1067,7 @@ TEST(CBranchReduce_true) {
for (size_t i = 0; i < arraysize(true_values); i++) {
Diamond d(R, true_values[i]);
- Node* true_use = R.graph.NewNode(R.common.Merge(1), d.if_true);
- Node* false_use = R.graph.NewNode(R.common.Merge(1), d.if_false);
- R.ReduceBranch(R.start, d.branch);
- CHECK_EQ(R.start, true_use->InputAt(0));
- CHECK_EQ(IrOpcode::kDead, false_use->InputAt(0)->opcode());
- CHECK(d.if_true->IsDead()); // replaced
- CHECK(d.if_false->IsDead()); // replaced
+ R.ReduceBranch(kTrue, d.branch);
}
}
@@ -1068,13 +1079,7 @@ TEST(CBranchReduce_false) {
for (size_t i = 0; i < arraysize(false_values); i++) {
Diamond d(R, false_values[i]);
- Node* true_use = R.graph.NewNode(R.common.Merge(1), d.if_true);
- Node* false_use = R.graph.NewNode(R.common.Merge(1), d.if_false);
- R.ReduceBranch(R.start, d.branch);
- CHECK_EQ(R.start, false_use->InputAt(0));
- CHECK_EQ(IrOpcode::kDead, true_use->InputAt(0)->opcode());
- CHECK(d.if_true->IsDead()); // replaced
- CHECK(d.if_false->IsDead()); // replaced
+ R.ReduceBranch(kFalse, d.branch);
}
}
@@ -1356,10 +1361,10 @@ TEST(CNonTermLoop_big2) {
Branch b1(R, R.p0);
Node* rt = R.graph.NewNode(R.common.Return(), R.one, R.start, b1.if_true);
- Branch b2(R, R.zero, b1.if_false);
+ Node* loop = R.graph.NewNode(R.common.Loop(2), b1.if_false, R.start);
+ Branch b2(R, R.zero, loop);
+ loop->ReplaceInput(1, b2.if_false);
Node* rf = R.graph.NewNode(R.common.Return(), R.zero, R.start, b2.if_true);
- Node* loop = R.SetSelfReferences(
- R.graph.NewNode(R.common.Loop(2), b2.if_false, R.self));
Node* merge = R.graph.NewNode(R.common.Merge(2), rt, rf);
R.end->ReplaceInput(0, merge);
« no previous file with comments | « src/compiler/control-reducer.cc ('k') | test/mjsunit/regress/regress-451958.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698