Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 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 |
| 3 | // found in the LICENSE file. |
| 4 | |
| 5 | #include "src/compiler/select-lowering.h" |
| 6 | #include "test/unittests/compiler/graph-unittest.h" |
| 7 | #include "test/unittests/compiler/node-test-utils.h" |
| 8 | #include "testing/gmock-support.h" |
| 9 | |
| 10 | using testing::AllOf; |
| 11 | using testing::Capture; |
| 12 | using testing::CaptureEq; |
| 13 | using testing::Not; |
| 14 | |
| 15 | namespace v8 { |
| 16 | namespace internal { |
| 17 | namespace compiler { |
| 18 | |
| 19 | class SelectLoweringTest : public GraphTest { |
| 20 | public: |
| 21 | SelectLoweringTest() : GraphTest(5), lowering_(graph(), common()) {} |
| 22 | |
| 23 | protected: |
| 24 | Reduction Reduce(Node* node) { return lowering_.Reduce(node); } |
| 25 | |
| 26 | private: |
| 27 | SelectLowering lowering_; |
| 28 | }; |
| 29 | |
| 30 | |
| 31 | TEST_F(SelectLoweringTest, SelectWithSameConditions) { |
| 32 | Node* const p0 = Parameter(0); |
| 33 | Node* const p1 = Parameter(1); |
| 34 | Node* const p2 = Parameter(2); |
| 35 | Node* const p3 = Parameter(3); |
| 36 | Node* const p4 = Parameter(4); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 37 | Node* const s0 = graph()->NewNode( |
| 38 | common()->Select(MachineRepresentation::kWord32), p0, p1, p2); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 39 | |
| 40 | Capture<Node*> branch; |
| 41 | Capture<Node*> merge; |
| 42 | { |
| 43 | Reduction const r = Reduce(s0); |
| 44 | ASSERT_TRUE(r.Changed()); |
| 45 | EXPECT_THAT( |
| 46 | r.replacement(), |
| 47 | IsPhi( |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 48 | MachineRepresentation::kWord32, p1, p2, |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 49 | AllOf(CaptureEq(&merge), |
| 50 | IsMerge(IsIfTrue(CaptureEq(&branch)), |
| 51 | IsIfFalse(AllOf(CaptureEq(&branch), |
| 52 | IsBranch(p0, graph()->start()))))))); |
| 53 | } |
| 54 | { |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 55 | Reduction const r = Reduce(graph()->NewNode( |
| 56 | common()->Select(MachineRepresentation::kWord32), p0, p3, p4)); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 57 | ASSERT_TRUE(r.Changed()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 58 | EXPECT_THAT(r.replacement(), IsPhi(MachineRepresentation::kWord32, p3, p4, |
| 59 | CaptureEq(&merge))); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 60 | } |
| 61 | { |
| 62 | // We must not reuse the diamond if it is reachable from either else/then |
| 63 | // values of the Select, because the resulting graph can not be scheduled. |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 64 | Reduction const r = Reduce(graph()->NewNode( |
| 65 | common()->Select(MachineRepresentation::kWord32), p0, s0, p0)); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 66 | ASSERT_TRUE(r.Changed()); |
Ben Murdoch | 4a90d5f | 2016-03-22 12:00:34 +0000 | [diff] [blame] | 67 | EXPECT_THAT(r.replacement(), IsPhi(MachineRepresentation::kWord32, s0, p0, |
| 68 | Not(CaptureEq(&merge)))); |
Emily Bernier | d0a1eb7 | 2015-03-24 16:35:39 -0400 | [diff] [blame] | 69 | } |
| 70 | } |
| 71 | |
| 72 | } // namespace compiler |
| 73 | } // namespace internal |
| 74 | } // namespace v8 |