Index: test/unittests/compiler/common-operator-reducer-unittest.cc |
diff --git a/test/unittests/compiler/common-operator-reducer-unittest.cc b/test/unittests/compiler/common-operator-reducer-unittest.cc |
index 1f6044b97cc5c4b8cf318404b49b0e1a582d7cb0..3b60e5b9bd32b2218b1fe33e6af30bccbbae61ad 100644 |
--- a/test/unittests/compiler/common-operator-reducer-unittest.cc |
+++ b/test/unittests/compiler/common-operator-reducer-unittest.cc |
@@ -4,9 +4,13 @@ |
#include "src/compiler/common-operator.h" |
#include "src/compiler/common-operator-reducer.h" |
+#include "src/compiler/js-graph.h" |
+#include "src/compiler/js-operator.h" |
+#include "src/compiler/machine-operator.h" |
#include "src/compiler/machine-type.h" |
#include "src/compiler/operator.h" |
#include "test/unittests/compiler/graph-unittest.h" |
+#include "test/unittests/compiler/node-test-utils.h" |
namespace v8 { |
namespace internal { |
@@ -15,14 +19,23 @@ namespace compiler { |
class CommonOperatorReducerTest : public GraphTest { |
public: |
explicit CommonOperatorReducerTest(int num_parameters = 1) |
- : GraphTest(num_parameters) {} |
+ : GraphTest(num_parameters), machine_(zone()) {} |
~CommonOperatorReducerTest() OVERRIDE {} |
protected: |
- Reduction Reduce(Node* node) { |
- CommonOperatorReducer reducer; |
+ Reduction Reduce(Node* node, MachineOperatorBuilder::Flags flags = |
+ MachineOperatorBuilder::kNoFlags) { |
+ JSOperatorBuilder javascript(zone()); |
+ MachineOperatorBuilder machine(zone(), kMachPtr, flags); |
+ JSGraph jsgraph(isolate(), graph(), common(), &javascript, &machine); |
+ CommonOperatorReducer reducer(&jsgraph); |
return reducer.Reduce(node); |
} |
+ |
+ MachineOperatorBuilder* machine() { return &machine_; } |
+ |
+ private: |
+ MachineOperatorBuilder machine_; |
}; |
@@ -78,9 +91,14 @@ TEST_F(CommonOperatorReducerTest, RedundantPhi) { |
int const value_input_count = input_count - 1; |
TRACED_FOREACH(MachineType, type, kMachineTypes) { |
for (int i = 0; i < value_input_count; ++i) { |
+ inputs[i] = graph()->start(); |
+ } |
+ Node* merge = graph()->NewNode(common()->Merge(value_input_count), |
+ value_input_count, inputs); |
+ for (int i = 0; i < value_input_count; ++i) { |
inputs[i] = input; |
} |
- inputs[value_input_count] = graph()->start(); |
+ inputs[value_input_count] = merge; |
Reduction r = Reduce(graph()->NewNode( |
common()->Phi(type, value_input_count), input_count, inputs)); |
ASSERT_TRUE(r.Changed()); |
@@ -90,6 +108,27 @@ TEST_F(CommonOperatorReducerTest, RedundantPhi) { |
} |
+TEST_F(CommonOperatorReducerTest, PhiToFloat64MaxOrFloat64Min) { |
+ Node* p0 = Parameter(0); |
+ Node* p1 = Parameter(1); |
+ Node* check = graph()->NewNode(machine()->Float64LessThan(), p0, p1); |
+ Node* branch = graph()->NewNode(common()->Branch(), check, graph()->start()); |
+ Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
+ Node* if_false = graph()->NewNode(common()->IfFalse(), branch); |
+ Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); |
+ Reduction r1 = |
+ Reduce(graph()->NewNode(common()->Phi(kMachFloat64, 2), p1, p0, merge), |
+ MachineOperatorBuilder::kFloat64Max); |
+ ASSERT_TRUE(r1.Changed()); |
+ EXPECT_THAT(r1.replacement(), IsFloat64Max(p1, p0)); |
+ Reduction r2 = |
+ Reduce(graph()->NewNode(common()->Phi(kMachFloat64, 2), p0, p1, merge), |
+ MachineOperatorBuilder::kFloat64Min); |
+ ASSERT_TRUE(r2.Changed()); |
+ EXPECT_THAT(r2.replacement(), IsFloat64Min(p0, p1)); |
+} |
+ |
+ |
// ----------------------------------------------------------------------------- |
// Select |
@@ -106,6 +145,23 @@ TEST_F(CommonOperatorReducerTest, RedundantSelect) { |
} |
} |
+ |
+TEST_F(CommonOperatorReducerTest, SelectToFloat64MaxOrFloat64Min) { |
+ Node* p0 = Parameter(0); |
+ Node* p1 = Parameter(1); |
+ Node* check = graph()->NewNode(machine()->Float64LessThan(), p0, p1); |
+ Reduction r1 = |
+ Reduce(graph()->NewNode(common()->Select(kMachFloat64), check, p1, p0), |
+ MachineOperatorBuilder::kFloat64Max); |
+ ASSERT_TRUE(r1.Changed()); |
+ EXPECT_THAT(r1.replacement(), IsFloat64Max(p1, p0)); |
+ Reduction r2 = |
+ Reduce(graph()->NewNode(common()->Select(kMachFloat64), check, p0, p1), |
+ MachineOperatorBuilder::kFloat64Min); |
+ ASSERT_TRUE(r2.Changed()); |
+ EXPECT_THAT(r2.replacement(), IsFloat64Min(p0, p1)); |
+} |
+ |
} // namespace compiler |
} // namespace internal |
} // namespace v8 |