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/operator.h" | 8 #include "src/compiler/operator.h" |
9 #include "src/compiler/simplified-operator.h" | 9 #include "src/compiler/simplified-operator.h" |
10 #include "src/machine-type.h" | 10 #include "src/machine-type.h" |
(...skipping 356 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
367 graph()->SetEnd(graph()->NewNode(common()->End(1), ret)); | 367 graph()->SetEnd(graph()->NewNode(common()->End(1), ret)); |
368 StrictMock<MockAdvancedReducerEditor> editor; | 368 StrictMock<MockAdvancedReducerEditor> editor; |
369 EXPECT_CALL(editor, Replace(merge, IsDead())); | 369 EXPECT_CALL(editor, Replace(merge, IsDead())); |
370 Reduction const r = Reduce(&editor, ret); | 370 Reduction const r = Reduce(&editor, ret); |
371 ASSERT_TRUE(r.Changed()); | 371 ASSERT_TRUE(r.Changed()); |
372 EXPECT_THAT(r.replacement(), IsDead()); | 372 EXPECT_THAT(r.replacement(), IsDead()); |
373 EXPECT_THAT(graph()->end(), IsEnd(ret, IsReturn(vtrue, etrue, if_true), | 373 EXPECT_THAT(graph()->end(), IsEnd(ret, IsReturn(vtrue, etrue, if_true), |
374 IsReturn(vfalse, efalse, if_false))); | 374 IsReturn(vfalse, efalse, if_false))); |
375 } | 375 } |
376 | 376 |
| 377 TEST_F(CommonOperatorReducerTest, MultiReturnWithPhiAndEffectPhiAndMerge) { |
| 378 Node* cond = Parameter(2); |
| 379 Node* branch = graph()->NewNode(common()->Branch(), cond, graph()->start()); |
| 380 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); |
| 381 Node* etrue = graph()->start(); |
| 382 Node* vtrue1 = Parameter(0); |
| 383 Node* vtrue2 = Parameter(1); |
| 384 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); |
| 385 Node* efalse = graph()->start(); |
| 386 Node* vfalse1 = Parameter(1); |
| 387 Node* vfalse2 = Parameter(0); |
| 388 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); |
| 389 Node* ephi = graph()->NewNode(common()->EffectPhi(2), etrue, efalse, merge); |
| 390 Node* phi1 = graph()->NewNode( |
| 391 common()->Phi(MachineRepresentation::kTagged, 2), vtrue1, vfalse1, merge); |
| 392 Node* phi2 = graph()->NewNode( |
| 393 common()->Phi(MachineRepresentation::kTagged, 2), vtrue2, vfalse2, merge); |
| 394 |
| 395 Node* zero = graph()->NewNode(common()->Int32Constant(0)); |
| 396 Node* ret = |
| 397 graph()->NewNode(common()->Return(2), zero, phi1, phi2, ephi, merge); |
| 398 graph()->SetEnd(graph()->NewNode(common()->End(1), ret)); |
| 399 StrictMock<MockAdvancedReducerEditor> editor; |
| 400 Reduction const r = Reduce(&editor, ret); |
| 401 // For now a return with multiple return values should not be reduced. |
| 402 ASSERT_TRUE(!r.Changed()); |
| 403 } |
377 | 404 |
378 // ----------------------------------------------------------------------------- | 405 // ----------------------------------------------------------------------------- |
379 // Select | 406 // Select |
380 | 407 |
381 | 408 |
382 TEST_F(CommonOperatorReducerTest, SelectWithSameThenAndElse) { | 409 TEST_F(CommonOperatorReducerTest, SelectWithSameThenAndElse) { |
383 Node* const input = graph()->NewNode(&kOp0); | 410 Node* const input = graph()->NewNode(&kOp0); |
384 TRACED_FOREACH(BranchHint, hint, kBranchHints) { | 411 TRACED_FOREACH(BranchHint, hint, kBranchHints) { |
385 TRACED_FOREACH(MachineRepresentation, rep, kMachineRepresentations) { | 412 TRACED_FOREACH(MachineRepresentation, rep, kMachineRepresentations) { |
386 Reduction r = Reduce( | 413 Reduction r = Reduce( |
(...skipping 73 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
460 graph()->NewNode(common()->Select(MachineRepresentation::kFloat64), check, | 487 graph()->NewNode(common()->Select(MachineRepresentation::kFloat64), check, |
461 p0, graph()->NewNode(machine()->Float64Sub(), c0, p0)); | 488 p0, graph()->NewNode(machine()->Float64Sub(), c0, p0)); |
462 Reduction r = Reduce(select); | 489 Reduction r = Reduce(select); |
463 ASSERT_TRUE(r.Changed()); | 490 ASSERT_TRUE(r.Changed()); |
464 EXPECT_THAT(r.replacement(), IsFloat64Abs(p0)); | 491 EXPECT_THAT(r.replacement(), IsFloat64Abs(p0)); |
465 } | 492 } |
466 | 493 |
467 } // namespace compiler | 494 } // namespace compiler |
468 } // namespace internal | 495 } // namespace internal |
469 } // namespace v8 | 496 } // namespace v8 |
OLD | NEW |