Chromium Code Reviews| Index: test/unittests/compiler/control-reducer-unittest.cc |
| diff --git a/test/unittests/compiler/control-reducer-unittest.cc b/test/unittests/compiler/control-reducer-unittest.cc |
| index 5e9b0ef4b1b532c0b1f6a5c29de39de4f96be270..e9d607edd1b8c81d9794f9c3fd4112048e71488b 100644 |
| --- a/test/unittests/compiler/control-reducer-unittest.cc |
| +++ b/test/unittests/compiler/control-reducer-unittest.cc |
| @@ -3,6 +3,7 @@ |
| // found in the LICENSE file. |
| #include "src/compiler/control-reducer.h" |
| +#include "src/compiler/graph-visualizer.h" |
| #include "src/compiler/js-graph.h" |
| #include "src/compiler/js-operator.h" |
| #include "src/compiler/machine-operator.h" |
| @@ -21,13 +22,33 @@ namespace internal { |
| namespace compiler { |
| class ControlReducerTest : public GraphTest { |
| + public: |
| + ControlReducerTest() |
| + : GraphTest(), |
|
Michael Starzinger
2015/04/02 11:59:34
nit: The default constructor should be implicitly
titzer
2015/04/02 12:35:48
I've taken your suggestion of extending TypeGraphT
|
| + machine_(zone()), |
| + javascript_(zone()), |
| + jsgraph_(isolate(), graph(), common(), &javascript_, &machine_) {} |
| + |
| protected: |
| + MachineOperatorBuilder machine_; |
| + JSOperatorBuilder javascript_; |
| + JSGraph jsgraph_; |
| + |
| void ReduceGraph() { |
| - JSOperatorBuilder javascript(zone()); |
| - MachineOperatorBuilder machine(zone()); |
| - JSGraph jsgraph(isolate(), graph(), common(), &javascript, &machine); |
| - ControlReducer::ReduceGraph(zone(), &jsgraph, common()); |
| + if (FLAG_trace_turbo_graph) { |
| + OFStream os(stdout); |
| + os << "-- Graph before control reduction" << std::endl; |
| + os << AsRPO(*graph()); |
| + } |
| + ControlReducer::ReduceGraph(zone(), jsgraph(), common()); |
| + if (FLAG_trace_turbo_graph) { |
| + OFStream os(stdout); |
| + os << "-- Graph after control reduction" << std::endl; |
| + os << AsRPO(*graph()); |
| + } |
| } |
| + |
| + JSGraph* jsgraph() { return &jsgraph_; } |
| }; |
| @@ -119,6 +140,123 @@ TEST_F(ControlReducerTest, NonTerminatingLoopWithDeadEnd) { |
| IsIfTrue(CaptureEq(&branch)))))))))); |
| } |
| + |
| +TEST_F(ControlReducerTest, PhiAsInputToBranch_true) { |
| + Node* p0 = graph()->NewNode(common()->Parameter(0), graph()->start()); |
| + Node* branch1 = graph()->NewNode(common()->Branch(), p0, graph()->start()); |
| + Node* if_true1 = graph()->NewNode(common()->IfTrue(), branch1); |
| + Node* if_false1 = graph()->NewNode(common()->IfFalse(), branch1); |
| + Node* merge1 = graph()->NewNode(common()->Merge(2), if_true1, if_false1); |
| + Node* phi1 = graph()->NewNode(common()->Phi(kMachInt32, 2), |
| + jsgraph()->Int32Constant(1), |
| + jsgraph()->Int32Constant(2), merge1); |
| + |
| + Node* branch2 = graph()->NewNode(common()->Branch(), phi1, merge1); |
| + Node* if_true2 = graph()->NewNode(common()->IfTrue(), branch2); |
| + Node* if_false2 = graph()->NewNode(common()->IfFalse(), branch2); |
| + Node* merge2 = graph()->NewNode(common()->Merge(2), if_true2, if_false2); |
| + Node* result = graph()->NewNode(common()->Phi(kMachInt32, 2), |
| + jsgraph()->Int32Constant(11), |
| + jsgraph()->Int32Constant(22), merge2); |
| + |
| + Node* ret = |
| + graph()->NewNode(common()->Return(), result, graph()->start(), merge2); |
| + graph()->end()->ReplaceInput(0, ret); |
| + |
| + ReduceGraph(); |
| + |
| + // First diamond is not reduced. |
| + EXPECT_THAT(merge1, IsMerge(IsIfTrue(branch1), IsIfFalse(branch1))); |
| + |
| + // Second diamond should be folded away. |
| + EXPECT_THAT(graph()->end(), |
| + IsEnd(IsReturn(IsInt32Constant(11), graph()->start(), merge1))); |
| +} |
| + |
| + |
| +TEST_F(ControlReducerTest, PhiAsInputToBranch_false) { |
| + Node* p0 = graph()->NewNode(common()->Parameter(0), graph()->start()); |
| + Node* branch1 = graph()->NewNode(common()->Branch(), p0, graph()->start()); |
| + Node* if_true1 = graph()->NewNode(common()->IfTrue(), branch1); |
| + Node* if_false1 = graph()->NewNode(common()->IfFalse(), branch1); |
| + Node* merge1 = graph()->NewNode(common()->Merge(2), if_true1, if_false1); |
| + Node* phi1 = graph()->NewNode(common()->Phi(kMachInt32, 2), |
| + jsgraph()->Int32Constant(0), |
| + jsgraph()->BooleanConstant(false), merge1); |
| + |
| + Node* branch2 = graph()->NewNode(common()->Branch(), phi1, merge1); |
| + Node* if_true2 = graph()->NewNode(common()->IfTrue(), branch2); |
| + Node* if_false2 = graph()->NewNode(common()->IfFalse(), branch2); |
| + Node* merge2 = graph()->NewNode(common()->Merge(2), if_true2, if_false2); |
| + Node* result = graph()->NewNode(common()->Phi(kMachInt32, 2), |
| + jsgraph()->Int32Constant(11), |
| + jsgraph()->Int32Constant(22), merge2); |
| + |
| + Node* ret = |
| + graph()->NewNode(common()->Return(), result, graph()->start(), merge2); |
| + graph()->end()->ReplaceInput(0, ret); |
| + |
| + ReduceGraph(); |
| + |
| + // First diamond is not reduced. |
| + EXPECT_THAT(merge1, IsMerge(IsIfTrue(branch1), IsIfFalse(branch1))); |
| + |
| + // Second diamond should be folded away. |
| + EXPECT_THAT(graph()->end(), |
| + IsEnd(IsReturn(IsInt32Constant(22), graph()->start(), merge1))); |
| +} |
| + |
| + |
| +TEST_F(ControlReducerTest, RangeAsInputToBranch_true1) { |
| + Node* p0 = graph()->NewNode(common()->Parameter(0), graph()->start()); |
|
Michael Starzinger
2015/04/02 11:59:34
nit: If ControlReducerTest would inherit form Type
titzer
2015/04/02 12:35:48
Done.
|
| + NodeProperties::SetBounds(p0, Bounds(Type::Range(1, 2, zone()))); |
| + |
| + Node* branch1 = graph()->NewNode(common()->Branch(), p0, graph()->start()); |
| + Node* if_true1 = graph()->NewNode(common()->IfTrue(), branch1); |
| + Node* if_false1 = graph()->NewNode(common()->IfFalse(), branch1); |
| + Node* merge1 = graph()->NewNode(common()->Merge(1), if_true1, if_false1); |
| + Node* result = graph()->NewNode(common()->Phi(kMachInt32, 2), |
| + jsgraph()->Int32Constant(11), |
| + jsgraph()->Int32Constant(44), merge1); |
| + |
| + Node* ret = |
| + graph()->NewNode(common()->Return(), result, graph()->start(), merge1); |
| + graph()->end()->ReplaceInput(0, ret); |
| + |
| + ReduceGraph(); |
| + |
| + // Diamond should be folded away. |
| + EXPECT_THAT( |
| + graph()->end(), |
| + IsEnd(IsReturn(IsInt32Constant(11), graph()->start(), graph()->start()))); |
| +} |
| + |
| + |
| +TEST_F(ControlReducerTest, RangeAsInputToBranch_true2) { |
| + Node* p0 = graph()->NewNode(common()->Parameter(0), graph()->start()); |
|
Michael Starzinger
2015/04/02 11:59:34
nit: Likewise.
titzer
2015/04/02 12:35:48
Done.
|
| + NodeProperties::SetBounds(p0, Bounds(Type::Range(-2, -1, zone()))); |
| + |
| + Node* branch1 = graph()->NewNode(common()->Branch(), p0, graph()->start()); |
| + Node* if_true1 = graph()->NewNode(common()->IfTrue(), branch1); |
| + Node* if_false1 = graph()->NewNode(common()->IfFalse(), branch1); |
| + Node* merge1 = graph()->NewNode(common()->Merge(1), if_true1, if_false1); |
| + Node* result = graph()->NewNode(common()->Phi(kMachInt32, 2), |
| + jsgraph()->Int32Constant(11), |
| + jsgraph()->Int32Constant(44), merge1); |
| + |
| + Node* ret = |
| + graph()->NewNode(common()->Return(), result, graph()->start(), merge1); |
| + graph()->end()->ReplaceInput(0, ret); |
| + |
| + ReduceGraph(); |
| + |
| + // Diamond should be folded away. |
| + EXPECT_THAT( |
| + graph()->end(), |
| + IsEnd(IsReturn(IsInt32Constant(11), graph()->start(), graph()->start()))); |
| +} |
| + |
| + |
| } // namespace compiler |
| } // namespace internal |
| } // namespace v8 |