| OLD | NEW |
| 1 // Copyright 2014 the V8 project authors. All rights reserved. | 1 // Copyright 2014 the V8 project authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "src/compiler/select-lowering.h" | 5 #include "src/compiler/select-lowering.h" |
| 6 #include "test/unittests/compiler/graph-unittest.h" | 6 #include "test/unittests/compiler/graph-unittest.h" |
| 7 #include "test/unittests/compiler/node-test-utils.h" | 7 #include "test/unittests/compiler/node-test-utils.h" |
| 8 #include "testing/gmock-support.h" | 8 #include "testing/gmock-support.h" |
| 9 | 9 |
| 10 using testing::AllOf; | 10 using testing::AllOf; |
| 11 using testing::Capture; | 11 using testing::Capture; |
| 12 using testing::CaptureEq; | 12 using testing::CaptureEq; |
| 13 using testing::Not; |
| 13 | 14 |
| 14 namespace v8 { | 15 namespace v8 { |
| 15 namespace internal { | 16 namespace internal { |
| 16 namespace compiler { | 17 namespace compiler { |
| 17 | 18 |
| 18 class SelectLoweringTest : public GraphTest { | 19 class SelectLoweringTest : public GraphTest { |
| 19 public: | 20 public: |
| 20 SelectLoweringTest() : GraphTest(5), lowering_(graph(), common()) {} | 21 SelectLoweringTest() : GraphTest(5), lowering_(graph(), common()) {} |
| 21 | 22 |
| 22 protected: | 23 protected: |
| 23 Reduction Reduce(Node* node) { return lowering_.Reduce(node); } | 24 Reduction Reduce(Node* node) { return lowering_.Reduce(node); } |
| 24 | 25 |
| 25 private: | 26 private: |
| 26 SelectLowering lowering_; | 27 SelectLowering lowering_; |
| 27 }; | 28 }; |
| 28 | 29 |
| 29 | 30 |
| 30 TEST_F(SelectLoweringTest, SelectWithSameConditions) { | 31 TEST_F(SelectLoweringTest, SelectWithSameConditions) { |
| 31 Node* const p0 = Parameter(0); | 32 Node* const p0 = Parameter(0); |
| 32 Node* const p1 = Parameter(1); | 33 Node* const p1 = Parameter(1); |
| 33 Node* const p2 = Parameter(2); | 34 Node* const p2 = Parameter(2); |
| 34 Node* const p3 = Parameter(3); | 35 Node* const p3 = Parameter(3); |
| 35 Node* const p4 = Parameter(4); | 36 Node* const p4 = Parameter(4); |
| 37 Node* const s0 = graph()->NewNode(common()->Select(kMachInt32), p0, p1, p2); |
| 36 | 38 |
| 37 Capture<Node*> branch; | 39 Capture<Node*> branch; |
| 38 Capture<Node*> merge; | 40 Capture<Node*> merge; |
| 39 { | 41 { |
| 40 Reduction const r = | 42 Reduction const r = Reduce(s0); |
| 41 Reduce(graph()->NewNode(common()->Select(kMachInt32), p0, p1, p2)); | |
| 42 ASSERT_TRUE(r.Changed()); | 43 ASSERT_TRUE(r.Changed()); |
| 43 EXPECT_THAT( | 44 EXPECT_THAT( |
| 44 r.replacement(), | 45 r.replacement(), |
| 45 IsPhi( | 46 IsPhi( |
| 46 kMachInt32, p1, p2, | 47 kMachInt32, p1, p2, |
| 47 AllOf(CaptureEq(&merge), | 48 AllOf(CaptureEq(&merge), |
| 48 IsMerge(IsIfTrue(CaptureEq(&branch)), | 49 IsMerge(IsIfTrue(CaptureEq(&branch)), |
| 49 IsIfFalse(AllOf(CaptureEq(&branch), | 50 IsIfFalse(AllOf(CaptureEq(&branch), |
| 50 IsBranch(p0, graph()->start()))))))); | 51 IsBranch(p0, graph()->start()))))))); |
| 51 } | 52 } |
| 52 { | 53 { |
| 53 Reduction const r = | 54 Reduction const r = |
| 54 Reduce(graph()->NewNode(common()->Select(kMachInt32), p0, p3, p4)); | 55 Reduce(graph()->NewNode(common()->Select(kMachInt32), p0, p3, p4)); |
| 55 ASSERT_TRUE(r.Changed()); | 56 ASSERT_TRUE(r.Changed()); |
| 56 EXPECT_THAT(r.replacement(), IsPhi(kMachInt32, p3, p4, CaptureEq(&merge))); | 57 EXPECT_THAT(r.replacement(), IsPhi(kMachInt32, p3, p4, CaptureEq(&merge))); |
| 57 } | 58 } |
| 59 { |
| 60 // We must not reuse the diamond if it is reachable from either else/then |
| 61 // values of the Select, because the resulting graph can not be scheduled. |
| 62 Reduction const r = |
| 63 Reduce(graph()->NewNode(common()->Select(kMachInt32), p0, s0, p0)); |
| 64 ASSERT_TRUE(r.Changed()); |
| 65 EXPECT_THAT(r.replacement(), |
| 66 IsPhi(kMachInt32, s0, p0, Not(CaptureEq(&merge)))); |
| 67 } |
| 58 } | 68 } |
| 59 | 69 |
| 60 } // namespace compiler | 70 } // namespace compiler |
| 61 } // namespace internal | 71 } // namespace internal |
| 62 } // namespace v8 | 72 } // namespace v8 |
| OLD | NEW |