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/common-operator.h" | 5 #include "src/compiler/common-operator.h" |
6 #include "src/compiler/common-operator-reducer.h" | 6 #include "src/compiler/common-operator-reducer.h" |
7 #include "src/compiler/machine-operator.h" | 7 #include "src/compiler/machine-operator.h" |
8 #include "src/compiler/machine-type.h" | 8 #include "src/compiler/machine-type.h" |
9 #include "src/compiler/operator.h" | 9 #include "src/compiler/operator.h" |
| 10 #include "src/compiler/simplified-operator.h" |
10 #include "test/unittests/compiler/graph-reducer-unittest.h" | 11 #include "test/unittests/compiler/graph-reducer-unittest.h" |
11 #include "test/unittests/compiler/graph-unittest.h" | 12 #include "test/unittests/compiler/graph-unittest.h" |
12 #include "test/unittests/compiler/node-test-utils.h" | 13 #include "test/unittests/compiler/node-test-utils.h" |
13 | 14 |
14 using testing::StrictMock; | 15 using testing::StrictMock; |
15 | 16 |
16 namespace v8 { | 17 namespace v8 { |
17 namespace internal { | 18 namespace internal { |
18 namespace compiler { | 19 namespace compiler { |
19 | 20 |
20 class CommonOperatorReducerTest : public GraphTest { | 21 class CommonOperatorReducerTest : public GraphTest { |
21 public: | 22 public: |
22 explicit CommonOperatorReducerTest(int num_parameters = 1) | 23 explicit CommonOperatorReducerTest(int num_parameters = 1) |
23 : GraphTest(num_parameters), machine_(zone()) {} | 24 : GraphTest(num_parameters), machine_(zone()), simplified_(zone()) {} |
24 ~CommonOperatorReducerTest() override {} | 25 ~CommonOperatorReducerTest() override {} |
25 | 26 |
26 protected: | 27 protected: |
27 Reduction Reduce( | 28 Reduction Reduce( |
28 AdvancedReducer::Editor* editor, Node* node, | 29 AdvancedReducer::Editor* editor, Node* node, |
29 MachineOperatorBuilder::Flags flags = MachineOperatorBuilder::kNoFlags) { | 30 MachineOperatorBuilder::Flags flags = MachineOperatorBuilder::kNoFlags) { |
30 MachineOperatorBuilder machine(zone(), kMachPtr, flags); | 31 MachineOperatorBuilder machine(zone(), kMachPtr, flags); |
31 CommonOperatorReducer reducer(editor, graph(), common(), &machine); | 32 CommonOperatorReducer reducer(editor, graph(), common(), &machine); |
32 return reducer.Reduce(node); | 33 return reducer.Reduce(node); |
33 } | 34 } |
34 | 35 |
35 Reduction Reduce(Node* node, MachineOperatorBuilder::Flags flags = | 36 Reduction Reduce(Node* node, MachineOperatorBuilder::Flags flags = |
36 MachineOperatorBuilder::kNoFlags) { | 37 MachineOperatorBuilder::kNoFlags) { |
37 StrictMock<MockAdvancedReducerEditor> editor; | 38 StrictMock<MockAdvancedReducerEditor> editor; |
38 return Reduce(&editor, node, flags); | 39 return Reduce(&editor, node, flags); |
39 } | 40 } |
40 | 41 |
41 MachineOperatorBuilder* machine() { return &machine_; } | 42 MachineOperatorBuilder* machine() { return &machine_; } |
| 43 SimplifiedOperatorBuilder* simplified() { return &simplified_; } |
42 | 44 |
43 private: | 45 private: |
44 MachineOperatorBuilder machine_; | 46 MachineOperatorBuilder machine_; |
| 47 SimplifiedOperatorBuilder simplified_; |
45 }; | 48 }; |
46 | 49 |
47 | 50 |
48 namespace { | 51 namespace { |
49 | 52 |
50 const BranchHint kBranchHints[] = {BranchHint::kNone, BranchHint::kFalse, | 53 const BranchHint kBranchHints[] = {BranchHint::kNone, BranchHint::kFalse, |
51 BranchHint::kTrue}; | 54 BranchHint::kTrue}; |
52 | 55 |
53 | 56 |
54 const MachineType kMachineTypes[] = { | 57 const MachineType kMachineTypes[] = { |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
162 StrictMock<MockAdvancedReducerEditor> editor; | 165 StrictMock<MockAdvancedReducerEditor> editor; |
163 EXPECT_CALL(editor, Replace(if_true, control)); | 166 EXPECT_CALL(editor, Replace(if_true, control)); |
164 EXPECT_CALL(editor, Replace(if_false, IsDead())); | 167 EXPECT_CALL(editor, Replace(if_false, IsDead())); |
165 Reduction const r = Reduce(&editor, branch); | 168 Reduction const r = Reduce(&editor, branch); |
166 ASSERT_TRUE(r.Changed()); | 169 ASSERT_TRUE(r.Changed()); |
167 EXPECT_THAT(r.replacement(), IsDead()); | 170 EXPECT_THAT(r.replacement(), IsDead()); |
168 } | 171 } |
169 } | 172 } |
170 | 173 |
171 | 174 |
| 175 TEST_F(CommonOperatorReducerTest, BranchWithBooleanNot) { |
| 176 Node* const value = Parameter(0); |
| 177 TRACED_FOREACH(BranchHint, hint, kBranchHints) { |
| 178 Node* const control = graph()->start(); |
| 179 Node* const branch = graph()->NewNode( |
| 180 common()->Branch(hint), |
| 181 graph()->NewNode(simplified()->BooleanNot(), value), control); |
| 182 Node* const if_true = graph()->NewNode(common()->IfTrue(), branch); |
| 183 Node* const if_false = graph()->NewNode(common()->IfFalse(), branch); |
| 184 Reduction const r = Reduce(branch); |
| 185 ASSERT_TRUE(r.Changed()); |
| 186 EXPECT_EQ(branch, r.replacement()); |
| 187 EXPECT_THAT(branch, IsBranch(value, control)); |
| 188 EXPECT_THAT(if_false, IsIfTrue(branch)); |
| 189 EXPECT_THAT(if_true, IsIfFalse(branch)); |
| 190 } |
| 191 } |
| 192 |
| 193 |
172 // ----------------------------------------------------------------------------- | 194 // ----------------------------------------------------------------------------- |
173 // Merge | 195 // Merge |
174 | 196 |
175 | 197 |
176 TEST_F(CommonOperatorReducerTest, MergeOfUnusedDiamond0) { | 198 TEST_F(CommonOperatorReducerTest, MergeOfUnusedDiamond0) { |
177 Node* const value = Parameter(0); | 199 Node* const value = Parameter(0); |
178 Node* const control = graph()->start(); | 200 Node* const control = graph()->start(); |
179 Node* const branch = graph()->NewNode(common()->Branch(), value, control); | 201 Node* const branch = graph()->NewNode(common()->Branch(), value, control); |
180 Node* const if_true = graph()->NewNode(common()->IfTrue(), branch); | 202 Node* const if_true = graph()->NewNode(common()->IfTrue(), branch); |
181 Node* const if_false = graph()->NewNode(common()->IfFalse(), branch); | 203 Node* const if_false = graph()->NewNode(common()->IfFalse(), branch); |
(...skipping 372 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
554 Node* select = | 576 Node* select = |
555 graph()->NewNode(common()->Select(kMachFloat64), check, p0, p1); | 577 graph()->NewNode(common()->Select(kMachFloat64), check, p0, p1); |
556 Reduction r = Reduce(select, MachineOperatorBuilder::kFloat64Min); | 578 Reduction r = Reduce(select, MachineOperatorBuilder::kFloat64Min); |
557 ASSERT_TRUE(r.Changed()); | 579 ASSERT_TRUE(r.Changed()); |
558 EXPECT_THAT(r.replacement(), IsFloat64Min(p0, p1)); | 580 EXPECT_THAT(r.replacement(), IsFloat64Min(p0, p1)); |
559 } | 581 } |
560 | 582 |
561 } // namespace compiler | 583 } // namespace compiler |
562 } // namespace internal | 584 } // namespace internal |
563 } // namespace v8 | 585 } // namespace v8 |
OLD | NEW |