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 3b60e5b9bd32b2218b1fe33e6af30bccbbae61ad..ce10b1e63593729feb3bdafcf3da00315e52aa81 100644 |
--- a/test/unittests/compiler/common-operator-reducer-unittest.cc |
+++ b/test/unittests/compiler/common-operator-reducer-unittest.cc |
@@ -108,7 +108,88 @@ TEST_F(CommonOperatorReducerTest, RedundantPhi) { |
} |
-TEST_F(CommonOperatorReducerTest, PhiToFloat64MaxOrFloat64Min) { |
+TEST_F(CommonOperatorReducerTest, PhiToFloat32Abs) { |
+ Node* p0 = Parameter(0); |
+ Node* c0 = Float32Constant(0.0); |
+ Node* check = graph()->NewNode(machine()->Float32LessThan(), c0, p0); |
+ Node* branch = graph()->NewNode(common()->Branch(), check, graph()->start()); |
+ Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
+ Node* vtrue = p0; |
+ Node* if_false = graph()->NewNode(common()->IfFalse(), branch); |
+ Node* vfalse = graph()->NewNode(machine()->Float32Sub(), c0, p0); |
+ Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); |
+ Node* phi = |
+ graph()->NewNode(common()->Phi(kMachFloat32, 2), vtrue, vfalse, merge); |
+ Reduction r = Reduce(phi, MachineOperatorBuilder::kFloat32Abs); |
+ ASSERT_TRUE(r.Changed()); |
+ EXPECT_THAT(r.replacement(), IsFloat32Abs(p0)); |
+} |
+ |
+ |
+TEST_F(CommonOperatorReducerTest, PhiToFloat64Abs) { |
+ Node* p0 = Parameter(0); |
+ Node* c0 = Float64Constant(0.0); |
+ Node* check = graph()->NewNode(machine()->Float64LessThan(), c0, p0); |
+ Node* branch = graph()->NewNode(common()->Branch(), check, graph()->start()); |
+ Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
+ Node* vtrue = p0; |
+ Node* if_false = graph()->NewNode(common()->IfFalse(), branch); |
+ Node* vfalse = graph()->NewNode(machine()->Float64Sub(), c0, p0); |
+ Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); |
+ Node* phi = |
+ graph()->NewNode(common()->Phi(kMachFloat64, 2), vtrue, vfalse, merge); |
+ Reduction r = Reduce(phi, MachineOperatorBuilder::kFloat64Abs); |
+ ASSERT_TRUE(r.Changed()); |
+ EXPECT_THAT(r.replacement(), IsFloat64Abs(p0)); |
+} |
+ |
+ |
+TEST_F(CommonOperatorReducerTest, PhiToFloat32Max) { |
+ Node* p0 = Parameter(0); |
+ Node* p1 = Parameter(1); |
+ Node* check = graph()->NewNode(machine()->Float32LessThan(), 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); |
+ Node* phi = graph()->NewNode(common()->Phi(kMachFloat32, 2), p1, p0, merge); |
+ Reduction r = Reduce(phi, MachineOperatorBuilder::kFloat32Max); |
+ ASSERT_TRUE(r.Changed()); |
+ EXPECT_THAT(r.replacement(), IsFloat32Max(p1, p0)); |
+} |
+ |
+ |
+TEST_F(CommonOperatorReducerTest, PhiToFloat64Max) { |
+ 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); |
+ Node* phi = graph()->NewNode(common()->Phi(kMachFloat64, 2), p1, p0, merge); |
+ Reduction r = Reduce(phi, MachineOperatorBuilder::kFloat64Max); |
+ ASSERT_TRUE(r.Changed()); |
+ EXPECT_THAT(r.replacement(), IsFloat64Max(p1, p0)); |
+} |
+ |
+ |
+TEST_F(CommonOperatorReducerTest, PhiToFloat32Min) { |
+ Node* p0 = Parameter(0); |
+ Node* p1 = Parameter(1); |
+ Node* check = graph()->NewNode(machine()->Float32LessThan(), 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); |
+ Node* phi = graph()->NewNode(common()->Phi(kMachFloat32, 2), p0, p1, merge); |
+ Reduction r = Reduce(phi, MachineOperatorBuilder::kFloat32Min); |
+ ASSERT_TRUE(r.Changed()); |
+ EXPECT_THAT(r.replacement(), IsFloat32Min(p0, p1)); |
+} |
+ |
+ |
+TEST_F(CommonOperatorReducerTest, PhiToFloat64Min) { |
Node* p0 = Parameter(0); |
Node* p1 = Parameter(1); |
Node* check = graph()->NewNode(machine()->Float64LessThan(), p0, p1); |
@@ -116,16 +197,10 @@ TEST_F(CommonOperatorReducerTest, PhiToFloat64MaxOrFloat64Min) { |
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)); |
+ Node* phi = graph()->NewNode(common()->Phi(kMachFloat64, 2), p0, p1, merge); |
+ Reduction r = Reduce(phi, MachineOperatorBuilder::kFloat64Min); |
+ ASSERT_TRUE(r.Changed()); |
+ EXPECT_THAT(r.replacement(), IsFloat64Min(p0, p1)); |
} |
@@ -146,20 +221,77 @@ TEST_F(CommonOperatorReducerTest, RedundantSelect) { |
} |
-TEST_F(CommonOperatorReducerTest, SelectToFloat64MaxOrFloat64Min) { |
+TEST_F(CommonOperatorReducerTest, SelectToFloat32Abs) { |
+ Node* p0 = Parameter(0); |
+ Node* c0 = Float32Constant(0.0); |
+ Node* check = graph()->NewNode(machine()->Float32LessThan(), c0, p0); |
+ Node* select = |
+ graph()->NewNode(common()->Select(kMachFloat32), check, p0, |
+ graph()->NewNode(machine()->Float32Sub(), c0, p0)); |
+ Reduction r = Reduce(select, MachineOperatorBuilder::kFloat32Abs); |
+ ASSERT_TRUE(r.Changed()); |
+ EXPECT_THAT(r.replacement(), IsFloat32Abs(p0)); |
+} |
+ |
+ |
+TEST_F(CommonOperatorReducerTest, SelectToFloat64Abs) { |
+ Node* p0 = Parameter(0); |
+ Node* c0 = Float64Constant(0.0); |
+ Node* check = graph()->NewNode(machine()->Float64LessThan(), c0, p0); |
+ Node* select = |
+ graph()->NewNode(common()->Select(kMachFloat64), check, p0, |
+ graph()->NewNode(machine()->Float64Sub(), c0, p0)); |
+ Reduction r = Reduce(select, MachineOperatorBuilder::kFloat64Abs); |
+ ASSERT_TRUE(r.Changed()); |
+ EXPECT_THAT(r.replacement(), IsFloat64Abs(p0)); |
+} |
+ |
+ |
+TEST_F(CommonOperatorReducerTest, SelectToFloat32Max) { |
+ Node* p0 = Parameter(0); |
+ Node* p1 = Parameter(1); |
+ Node* check = graph()->NewNode(machine()->Float32LessThan(), p0, p1); |
+ Node* select = |
+ graph()->NewNode(common()->Select(kMachFloat32), check, p1, p0); |
+ Reduction r = Reduce(select, MachineOperatorBuilder::kFloat32Max); |
+ ASSERT_TRUE(r.Changed()); |
+ EXPECT_THAT(r.replacement(), IsFloat32Max(p1, p0)); |
+} |
+ |
+ |
+TEST_F(CommonOperatorReducerTest, SelectToFloat64Max) { |
+ Node* p0 = Parameter(0); |
+ Node* p1 = Parameter(1); |
+ Node* check = graph()->NewNode(machine()->Float64LessThan(), p0, p1); |
+ Node* select = |
+ graph()->NewNode(common()->Select(kMachFloat64), check, p1, p0); |
+ Reduction r = Reduce(select, MachineOperatorBuilder::kFloat64Max); |
+ ASSERT_TRUE(r.Changed()); |
+ EXPECT_THAT(r.replacement(), IsFloat64Max(p1, p0)); |
+} |
+ |
+ |
+TEST_F(CommonOperatorReducerTest, SelectToFloat32Min) { |
+ Node* p0 = Parameter(0); |
+ Node* p1 = Parameter(1); |
+ Node* check = graph()->NewNode(machine()->Float32LessThan(), p0, p1); |
+ Node* select = |
+ graph()->NewNode(common()->Select(kMachFloat32), check, p0, p1); |
+ Reduction r = Reduce(select, MachineOperatorBuilder::kFloat32Min); |
+ ASSERT_TRUE(r.Changed()); |
+ EXPECT_THAT(r.replacement(), IsFloat32Min(p0, p1)); |
+} |
+ |
+ |
+TEST_F(CommonOperatorReducerTest, SelectToFloat64Min) { |
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)); |
+ Node* select = |
+ graph()->NewNode(common()->Select(kMachFloat64), check, p0, p1); |
+ Reduction r = Reduce(select, MachineOperatorBuilder::kFloat64Min); |
+ ASSERT_TRUE(r.Changed()); |
+ EXPECT_THAT(r.replacement(), IsFloat64Min(p0, p1)); |
} |
} // namespace compiler |