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; | |
14 | 13 |
15 namespace v8 { | 14 namespace v8 { |
16 namespace internal { | 15 namespace internal { |
17 namespace compiler { | 16 namespace compiler { |
18 | 17 |
19 class SelectLoweringTest : public GraphTest { | 18 class SelectLoweringTest : public GraphTest { |
20 public: | 19 public: |
21 SelectLoweringTest() : GraphTest(5), lowering_(graph(), common()) {} | 20 SelectLoweringTest() : GraphTest(5), lowering_(graph(), common()) {} |
22 | 21 |
23 protected: | 22 protected: |
24 Reduction Reduce(Node* node) { return lowering_.Reduce(node); } | 23 Reduction Reduce(Node* node) { return lowering_.Reduce(node); } |
25 | 24 |
26 private: | 25 private: |
27 SelectLowering lowering_; | 26 SelectLowering lowering_; |
28 }; | 27 }; |
29 | 28 |
30 | 29 |
31 TEST_F(SelectLoweringTest, SelectWithSameConditions) { | 30 TEST_F(SelectLoweringTest, SelectWithSameConditions) { |
32 Node* const p0 = Parameter(0); | 31 Node* const p0 = Parameter(0); |
33 Node* const p1 = Parameter(1); | 32 Node* const p1 = Parameter(1); |
34 Node* const p2 = Parameter(2); | 33 Node* const p2 = Parameter(2); |
35 Node* const p3 = Parameter(3); | 34 Node* const p3 = Parameter(3); |
36 Node* const p4 = Parameter(4); | 35 Node* const p4 = Parameter(4); |
37 Node* const s0 = graph()->NewNode(common()->Select(kMachInt32), p0, p1, p2); | |
38 | 36 |
39 Capture<Node*> branch; | 37 Capture<Node*> branch; |
40 Capture<Node*> merge; | 38 Capture<Node*> merge; |
41 { | 39 { |
42 Reduction const r = Reduce(s0); | 40 Reduction const r = |
| 41 Reduce(graph()->NewNode(common()->Select(kMachInt32), p0, p1, p2)); |
43 ASSERT_TRUE(r.Changed()); | 42 ASSERT_TRUE(r.Changed()); |
44 EXPECT_THAT( | 43 EXPECT_THAT( |
45 r.replacement(), | 44 r.replacement(), |
46 IsPhi( | 45 IsPhi( |
47 kMachInt32, p1, p2, | 46 kMachInt32, p1, p2, |
48 AllOf(CaptureEq(&merge), | 47 AllOf(CaptureEq(&merge), |
49 IsMerge(IsIfTrue(CaptureEq(&branch)), | 48 IsMerge(IsIfTrue(CaptureEq(&branch)), |
50 IsIfFalse(AllOf(CaptureEq(&branch), | 49 IsIfFalse(AllOf(CaptureEq(&branch), |
51 IsBranch(p0, graph()->start()))))))); | 50 IsBranch(p0, graph()->start()))))))); |
52 } | 51 } |
53 { | 52 { |
54 Reduction const r = | 53 Reduction const r = |
55 Reduce(graph()->NewNode(common()->Select(kMachInt32), p0, p3, p4)); | 54 Reduce(graph()->NewNode(common()->Select(kMachInt32), p0, p3, p4)); |
56 ASSERT_TRUE(r.Changed()); | 55 ASSERT_TRUE(r.Changed()); |
57 EXPECT_THAT(r.replacement(), IsPhi(kMachInt32, p3, p4, CaptureEq(&merge))); | 56 EXPECT_THAT(r.replacement(), IsPhi(kMachInt32, p3, p4, CaptureEq(&merge))); |
58 } | 57 } |
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 } | |
68 } | 58 } |
69 | 59 |
70 } // namespace compiler | 60 } // namespace compiler |
71 } // namespace internal | 61 } // namespace internal |
72 } // namespace v8 | 62 } // namespace v8 |
OLD | NEW |