Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(420)

Side by Side Diff: test/unittests/compiler/common-operator-reducer-unittest.cc

Issue 1193833002: [turbofan] Proper dead code elimination as regular reducer. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Renamed DeadControl to Dead. Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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/js-operator.h"
8 #include "src/compiler/machine-operator.h" 7 #include "src/compiler/machine-operator.h"
9 #include "src/compiler/machine-type.h" 8 #include "src/compiler/machine-type.h"
10 #include "src/compiler/operator.h" 9 #include "src/compiler/operator.h"
11 #include "test/unittests/compiler/graph-reducer-unittest.h" 10 #include "test/unittests/compiler/graph-reducer-unittest.h"
12 #include "test/unittests/compiler/graph-unittest.h" 11 #include "test/unittests/compiler/graph-unittest.h"
13 #include "test/unittests/compiler/node-test-utils.h" 12 #include "test/unittests/compiler/node-test-utils.h"
14 13
15 using testing::StrictMock; 14 using testing::StrictMock;
16 15
17 namespace v8 { 16 namespace v8 {
18 namespace internal { 17 namespace internal {
19 namespace compiler { 18 namespace compiler {
20 19
21 class CommonOperatorReducerTest : public GraphTest { 20 class CommonOperatorReducerTest : public GraphTest {
22 public: 21 public:
23 explicit CommonOperatorReducerTest(int num_parameters = 1) 22 explicit CommonOperatorReducerTest(int num_parameters = 1)
24 : GraphTest(num_parameters), machine_(zone()) {} 23 : GraphTest(num_parameters), machine_(zone()) {}
25 ~CommonOperatorReducerTest() override {} 24 ~CommonOperatorReducerTest() override {}
26 25
27 protected: 26 protected:
28 Reduction Reduce( 27 Reduction Reduce(
29 AdvancedReducer::Editor* editor, Node* node, 28 AdvancedReducer::Editor* editor, Node* node,
30 MachineOperatorBuilder::Flags flags = MachineOperatorBuilder::kNoFlags) { 29 MachineOperatorBuilder::Flags flags = MachineOperatorBuilder::kNoFlags) {
31 JSOperatorBuilder javascript(zone());
32 MachineOperatorBuilder machine(zone(), kMachPtr, flags); 30 MachineOperatorBuilder machine(zone(), kMachPtr, flags);
33 CommonOperatorReducer reducer(editor, graph(), common(), &machine); 31 CommonOperatorReducer reducer(editor, graph(), common(), &machine);
34 return reducer.Reduce(node); 32 return reducer.Reduce(node);
35 } 33 }
36 34
37 Reduction Reduce(Node* node, MachineOperatorBuilder::Flags flags = 35 Reduction Reduce(Node* node, MachineOperatorBuilder::Flags flags =
38 MachineOperatorBuilder::kNoFlags) { 36 MachineOperatorBuilder::kNoFlags) {
39 StrictMock<MockAdvancedReducerEditor> editor; 37 StrictMock<MockAdvancedReducerEditor> editor;
40 return Reduce(&editor, node, flags); 38 return Reduce(&editor, node, flags);
41 } 39 }
(...skipping 17 matching lines...) Expand all
59 kMachPtr, kMachAnyTagged, kRepBit, kRepWord8, kRepWord16, 57 kMachPtr, kMachAnyTagged, kRepBit, kRepWord8, kRepWord16,
60 kRepWord32, kRepWord64, kRepFloat32, kRepFloat64, kRepTagged}; 58 kRepWord32, kRepWord64, kRepFloat32, kRepFloat64, kRepTagged};
61 59
62 60
63 const Operator kOp0(0, Operator::kNoProperties, "Op0", 0, 0, 0, 1, 1, 0); 61 const Operator kOp0(0, Operator::kNoProperties, "Op0", 0, 0, 0, 1, 1, 0);
64 62
65 } // namespace 63 } // namespace
66 64
67 65
68 // ----------------------------------------------------------------------------- 66 // -----------------------------------------------------------------------------
67 // Branch
68
69
70 TEST_F(CommonOperatorReducerTest, BranchWithInt32ZeroConstant) {
71 TRACED_FOREACH(BranchHint, hint, kBranchHints) {
72 Node* const control = graph()->start();
73 Node* const branch =
74 graph()->NewNode(common()->Branch(hint), Int32Constant(0), control);
75 Node* const if_true = graph()->NewNode(common()->IfTrue(), branch);
76 Node* const if_false = graph()->NewNode(common()->IfFalse(), branch);
77 StrictMock<MockAdvancedReducerEditor> editor;
78 EXPECT_CALL(editor, Replace(if_true, IsDead()));
79 EXPECT_CALL(editor, Replace(if_false, control));
80 Reduction const r = Reduce(&editor, branch);
81 ASSERT_TRUE(r.Changed());
82 EXPECT_THAT(r.replacement(), IsDead());
83 }
84 }
85
86
87 TEST_F(CommonOperatorReducerTest, BranchWithInt32OneConstant) {
88 TRACED_FOREACH(BranchHint, hint, kBranchHints) {
89 Node* const control = graph()->start();
90 Node* const branch =
91 graph()->NewNode(common()->Branch(hint), Int32Constant(1), control);
92 Node* const if_true = graph()->NewNode(common()->IfTrue(), branch);
93 Node* const if_false = graph()->NewNode(common()->IfFalse(), branch);
94 StrictMock<MockAdvancedReducerEditor> editor;
95 EXPECT_CALL(editor, Replace(if_true, control));
96 EXPECT_CALL(editor, Replace(if_false, IsDead()));
97 Reduction const r = Reduce(&editor, branch);
98 ASSERT_TRUE(r.Changed());
99 EXPECT_THAT(r.replacement(), IsDead());
100 }
101 }
102
103
104 TEST_F(CommonOperatorReducerTest, BranchWithInt64ZeroConstant) {
105 TRACED_FOREACH(BranchHint, hint, kBranchHints) {
106 Node* const control = graph()->start();
107 Node* const branch =
108 graph()->NewNode(common()->Branch(hint), Int64Constant(0), control);
109 Node* const if_true = graph()->NewNode(common()->IfTrue(), branch);
110 Node* const if_false = graph()->NewNode(common()->IfFalse(), branch);
111 StrictMock<MockAdvancedReducerEditor> editor;
112 EXPECT_CALL(editor, Replace(if_true, IsDead()));
113 EXPECT_CALL(editor, Replace(if_false, control));
114 Reduction const r = Reduce(&editor, branch);
115 ASSERT_TRUE(r.Changed());
116 EXPECT_THAT(r.replacement(), IsDead());
117 }
118 }
119
120
121 TEST_F(CommonOperatorReducerTest, BranchWithInt64OneConstant) {
122 TRACED_FOREACH(BranchHint, hint, kBranchHints) {
123 Node* const control = graph()->start();
124 Node* const branch =
125 graph()->NewNode(common()->Branch(hint), Int64Constant(1), control);
126 Node* const if_true = graph()->NewNode(common()->IfTrue(), branch);
127 Node* const if_false = graph()->NewNode(common()->IfFalse(), branch);
128 StrictMock<MockAdvancedReducerEditor> editor;
129 EXPECT_CALL(editor, Replace(if_true, control));
130 EXPECT_CALL(editor, Replace(if_false, IsDead()));
131 Reduction const r = Reduce(&editor, branch);
132 ASSERT_TRUE(r.Changed());
133 EXPECT_THAT(r.replacement(), IsDead());
134 }
135 }
136
137
138 TEST_F(CommonOperatorReducerTest, BranchWithFalseConstant) {
139 TRACED_FOREACH(BranchHint, hint, kBranchHints) {
140 Node* const control = graph()->start();
141 Node* const branch =
142 graph()->NewNode(common()->Branch(hint), FalseConstant(), control);
143 Node* const if_true = graph()->NewNode(common()->IfTrue(), branch);
144 Node* const if_false = graph()->NewNode(common()->IfFalse(), branch);
145 StrictMock<MockAdvancedReducerEditor> editor;
146 EXPECT_CALL(editor, Replace(if_true, IsDead()));
147 EXPECT_CALL(editor, Replace(if_false, control));
148 Reduction const r = Reduce(&editor, branch);
149 ASSERT_TRUE(r.Changed());
150 EXPECT_THAT(r.replacement(), IsDead());
151 }
152 }
153
154
155 TEST_F(CommonOperatorReducerTest, BranchWithTrueConstant) {
156 TRACED_FOREACH(BranchHint, hint, kBranchHints) {
157 Node* const control = graph()->start();
158 Node* const branch =
159 graph()->NewNode(common()->Branch(hint), TrueConstant(), control);
160 Node* const if_true = graph()->NewNode(common()->IfTrue(), branch);
161 Node* const if_false = graph()->NewNode(common()->IfFalse(), branch);
162 StrictMock<MockAdvancedReducerEditor> editor;
163 EXPECT_CALL(editor, Replace(if_true, control));
164 EXPECT_CALL(editor, Replace(if_false, IsDead()));
165 Reduction const r = Reduce(&editor, branch);
166 ASSERT_TRUE(r.Changed());
167 EXPECT_THAT(r.replacement(), IsDead());
168 }
169 }
170
171
172 // -----------------------------------------------------------------------------
173 // Merge
174
175
176 TEST_F(CommonOperatorReducerTest, MergeOfUnusedDiamond0) {
177 Node* const value = Parameter(0);
178 Node* const control = graph()->start();
179 Node* const branch = graph()->NewNode(common()->Branch(), value, control);
180 Node* const if_true = graph()->NewNode(common()->IfTrue(), branch);
181 Node* const if_false = graph()->NewNode(common()->IfFalse(), branch);
182 Reduction const r =
183 Reduce(graph()->NewNode(common()->Merge(2), if_true, if_false));
184 ASSERT_TRUE(r.Changed());
185 EXPECT_EQ(control, r.replacement());
186 EXPECT_THAT(branch, IsDead());
187 }
188
189
190 TEST_F(CommonOperatorReducerTest, MergeOfUnusedDiamond1) {
191 Node* const value = Parameter(0);
192 Node* const control = graph()->start();
193 Node* const branch = graph()->NewNode(common()->Branch(), value, control);
194 Node* const if_true = graph()->NewNode(common()->IfTrue(), branch);
195 Node* const if_false = graph()->NewNode(common()->IfFalse(), branch);
196 Reduction const r =
197 Reduce(graph()->NewNode(common()->Merge(2), if_false, if_true));
198 ASSERT_TRUE(r.Changed());
199 EXPECT_EQ(control, r.replacement());
200 EXPECT_THAT(branch, IsDead());
201 }
202
203
204 // -----------------------------------------------------------------------------
69 // EffectPhi 205 // EffectPhi
70 206
71 207
72 TEST_F(CommonOperatorReducerTest, EffectPhiWithMerge) { 208 TEST_F(CommonOperatorReducerTest, EffectPhiWithMerge) {
73 const int kMaxInputs = 64; 209 const int kMaxInputs = 64;
74 Node* inputs[kMaxInputs]; 210 Node* inputs[kMaxInputs];
75 Node* const input = graph()->NewNode(&kOp0); 211 Node* const input = graph()->NewNode(&kOp0);
76 TRACED_FORRANGE(int, input_count, 2, kMaxInputs - 1) { 212 TRACED_FORRANGE(int, input_count, 2, kMaxInputs - 1) {
77 int const value_input_count = input_count - 1; 213 int const value_input_count = input_count - 1;
78 for (int i = 0; i < value_input_count; ++i) { 214 for (int i = 0; i < value_input_count; ++i) {
(...skipping 197 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 TRACED_FOREACH(MachineType, type, kMachineTypes) { 412 TRACED_FOREACH(MachineType, type, kMachineTypes) {
277 Reduction r = Reduce( 413 Reduction r = Reduce(
278 graph()->NewNode(common()->Select(type, hint), input, input, input)); 414 graph()->NewNode(common()->Select(type, hint), input, input, input));
279 ASSERT_TRUE(r.Changed()); 415 ASSERT_TRUE(r.Changed());
280 EXPECT_EQ(input, r.replacement()); 416 EXPECT_EQ(input, r.replacement());
281 } 417 }
282 } 418 }
283 } 419 }
284 420
285 421
422 TEST_F(CommonOperatorReducerTest, SelectWithInt32ZeroConstant) {
423 Node* p0 = Parameter(0);
424 Node* p1 = Parameter(1);
425 Node* select = graph()->NewNode(common()->Select(kMachAnyTagged),
426 Int32Constant(0), p0, p1);
427 Reduction r = Reduce(select);
428 ASSERT_TRUE(r.Changed());
429 EXPECT_EQ(p1, r.replacement());
430 }
431
432
433 TEST_F(CommonOperatorReducerTest, SelectWithInt32OneConstant) {
434 Node* p0 = Parameter(0);
435 Node* p1 = Parameter(1);
436 Node* select = graph()->NewNode(common()->Select(kMachAnyTagged),
437 Int32Constant(1), p0, p1);
438 Reduction r = Reduce(select);
439 ASSERT_TRUE(r.Changed());
440 EXPECT_EQ(p0, r.replacement());
441 }
442
443
444 TEST_F(CommonOperatorReducerTest, SelectWithInt64ZeroConstant) {
445 Node* p0 = Parameter(0);
446 Node* p1 = Parameter(1);
447 Node* select = graph()->NewNode(common()->Select(kMachAnyTagged),
448 Int64Constant(0), p0, p1);
449 Reduction r = Reduce(select);
450 ASSERT_TRUE(r.Changed());
451 EXPECT_EQ(p1, r.replacement());
452 }
453
454
455 TEST_F(CommonOperatorReducerTest, SelectWithInt64OneConstant) {
456 Node* p0 = Parameter(0);
457 Node* p1 = Parameter(1);
458 Node* select = graph()->NewNode(common()->Select(kMachAnyTagged),
459 Int64Constant(1), p0, p1);
460 Reduction r = Reduce(select);
461 ASSERT_TRUE(r.Changed());
462 EXPECT_EQ(p0, r.replacement());
463 }
464
465
286 TEST_F(CommonOperatorReducerTest, SelectWithFalseConstant) { 466 TEST_F(CommonOperatorReducerTest, SelectWithFalseConstant) {
287 Node* p0 = Parameter(0); 467 Node* p0 = Parameter(0);
288 Node* p1 = Parameter(1); 468 Node* p1 = Parameter(1);
289 Node* select = graph()->NewNode(common()->Select(kMachAnyTagged), 469 Node* select = graph()->NewNode(common()->Select(kMachAnyTagged),
290 FalseConstant(), p0, p1); 470 FalseConstant(), p0, p1);
291 Reduction r = Reduce(select); 471 Reduction r = Reduce(select);
292 ASSERT_TRUE(r.Changed()); 472 ASSERT_TRUE(r.Changed());
293 EXPECT_EQ(p1, r.replacement()); 473 EXPECT_EQ(p1, r.replacement());
294 } 474 }
295 475
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
374 Node* select = 554 Node* select =
375 graph()->NewNode(common()->Select(kMachFloat64), check, p0, p1); 555 graph()->NewNode(common()->Select(kMachFloat64), check, p0, p1);
376 Reduction r = Reduce(select, MachineOperatorBuilder::kFloat64Min); 556 Reduction r = Reduce(select, MachineOperatorBuilder::kFloat64Min);
377 ASSERT_TRUE(r.Changed()); 557 ASSERT_TRUE(r.Changed());
378 EXPECT_THAT(r.replacement(), IsFloat64Min(p0, p1)); 558 EXPECT_THAT(r.replacement(), IsFloat64Min(p0, p1));
379 } 559 }
380 560
381 } // namespace compiler 561 } // namespace compiler
382 } // namespace internal 562 } // namespace internal
383 } // namespace v8 563 } // namespace v8
OLDNEW
« no previous file with comments | « test/cctest/compiler/test-loop-analysis.cc ('k') | test/unittests/compiler/common-operator-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698