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

Unified Diff: test/unittests/compiler/control-reducer-unittest.cc

Issue 1061303002: [turbofan] Match selects in control reducer (configurable). (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 5 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 | « src/compiler/pipeline.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 76f25580bd2cbd5a7cdde2d000e50d3b35ac0fe5..02ff8ffd7c2b5c0e615402e1d440fe6f72c33807 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/diamond.h"
#include "src/compiler/graph-visualizer.h"
#include "src/compiler/js-graph.h"
#include "src/compiler/js-operator.h"
@@ -34,13 +35,14 @@ class ControlReducerTest : public TypedGraphTest {
JSOperatorBuilder javascript_;
JSGraph jsgraph_;
- void ReduceGraph() {
+ void ReduceGraph(int max_phis_for_select = 0) {
if (FLAG_trace_turbo_graph) {
OFStream os(stdout);
os << "-- Graph before control reduction" << std::endl;
os << AsRPO(*graph());
}
- ControlReducer::ReduceGraph(zone(), jsgraph(), common());
+ ControlReducer::ReduceGraph(zone(), jsgraph(), common(),
+ max_phis_for_select);
if (FLAG_trace_turbo_graph) {
OFStream os(stdout);
os << "-- Graph after control reduction" << std::endl;
@@ -279,6 +281,75 @@ TEST_F(ControlReducerTest, RangeAsInputToBranch_true2) {
}
+TEST_F(ControlReducerTest, SelectPhi) {
+ Node* p0 = Parameter(0);
+ const MachineType kType = kMachInt32;
+ Diamond d(graph(), common(), p0);
+ Node* phi =
+ d.Phi(kType, jsgraph()->Int32Constant(1), jsgraph()->Int32Constant(2));
+
+ Node* ret =
+ graph()->NewNode(common()->Return(), phi, graph()->start(), d.merge);
+ graph()->end()->ReplaceInput(0, ret);
+
+ ReduceGraph(1);
+
+ // Phi should be replaced with a select.
+ EXPECT_THAT(graph()->end(),
+ IsEnd(IsReturn(
+ IsSelect(kType, p0, IsInt32Constant(1), IsInt32Constant(2)),
+ graph()->start(), graph()->start())));
+}
+
+
+TEST_F(ControlReducerTest, SelectPhis_fail) {
+ Node* p0 = Parameter(0);
+ const MachineType kType = kMachInt32;
+ Diamond d(graph(), common(), p0);
+ Node* phi =
+ d.Phi(kType, jsgraph()->Int32Constant(1), jsgraph()->Int32Constant(2));
+ Node* phi2 =
+ d.Phi(kType, jsgraph()->Int32Constant(11), jsgraph()->Int32Constant(22));
+ USE(phi2);
+ Node* ret =
+ graph()->NewNode(common()->Return(), phi, graph()->start(), d.merge);
+ graph()->end()->ReplaceInput(0, ret);
+
+ ReduceGraph(1);
+
+ // Diamond should not be replaced with a select (too many phis).
+ EXPECT_THAT(ret, IsReturn(phi, graph()->start(), d.merge));
+ EXPECT_THAT(graph()->end(), IsEnd(ret));
+}
+
+
+TEST_F(ControlReducerTest, SelectTwoPhis) {
+ Node* p0 = Parameter(0);
+ const MachineType kType = kMachInt32;
+ Diamond d(graph(), common(), p0);
+ Node* phi1 =
+ d.Phi(kType, jsgraph()->Int32Constant(1), jsgraph()->Int32Constant(2));
+ Node* phi2 =
+ d.Phi(kType, jsgraph()->Int32Constant(2), jsgraph()->Int32Constant(3));
+ MachineOperatorBuilder machine(zone());
+ Node* add = graph()->NewNode(machine.Int32Add(), phi1, phi2);
+ Node* ret =
+ graph()->NewNode(common()->Return(), add, graph()->start(), d.merge);
+ graph()->end()->ReplaceInput(0, ret);
+
+ ReduceGraph(2);
+
+ // Phis should be replaced with two selects.
+ EXPECT_THAT(
+ ret,
+ IsReturn(IsInt32Add(
+ IsSelect(kType, p0, IsInt32Constant(1), IsInt32Constant(2)),
+ IsSelect(kType, p0, IsInt32Constant(2), IsInt32Constant(3))),
+ graph()->start(), graph()->start()));
+ EXPECT_THAT(graph()->end(), IsEnd(ret));
+}
+
+
} // namespace compiler
} // namespace internal
} // namespace v8
« no previous file with comments | « src/compiler/pipeline.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698