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/base/bits.h" | 5 #include "src/base/bits.h" |
6 #include "src/compiler/js-graph.h" | 6 #include "src/compiler/js-graph.h" |
7 #include "src/compiler/machine-operator-reducer.h" | 7 #include "src/compiler/machine-operator-reducer.h" |
8 #include "src/compiler/typer.h" | 8 #include "src/compiler/typer.h" |
9 #include "test/unittests/compiler/graph-unittest.h" | 9 #include "test/unittests/compiler/graph-unittest.h" |
| 10 #include "testing/gmock-support.h" |
| 11 |
| 12 using testing::AllOf; |
| 13 using testing::Capture; |
| 14 using testing::CaptureEq; |
10 | 15 |
11 namespace v8 { | 16 namespace v8 { |
12 namespace internal { | 17 namespace internal { |
13 namespace compiler { | 18 namespace compiler { |
14 | 19 |
15 class MachineOperatorReducerTest : public GraphTest { | 20 class MachineOperatorReducerTest : public GraphTest { |
16 public: | 21 public: |
17 explicit MachineOperatorReducerTest(int num_parameters = 2) | 22 explicit MachineOperatorReducerTest(int num_parameters = 2) |
18 : GraphTest(num_parameters) {} | 23 : GraphTest(num_parameters) {} |
19 | 24 |
(...skipping 537 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
557 Int32Constant(x)); | 562 Int32Constant(x)); |
558 Reduction r = Reduce(node); | 563 Reduction r = Reduce(node); |
559 ASSERT_TRUE(r.Changed()); | 564 ASSERT_TRUE(r.Changed()); |
560 int32_t m = bit_cast<int32_t>(~((1U << x) - 1U)); | 565 int32_t m = bit_cast<int32_t>(~((1U << x) - 1U)); |
561 EXPECT_THAT(r.replacement(), IsWord32And(p0, IsInt32Constant(m))); | 566 EXPECT_THAT(r.replacement(), IsWord32And(p0, IsInt32Constant(m))); |
562 } | 567 } |
563 } | 568 } |
564 | 569 |
565 | 570 |
566 // ----------------------------------------------------------------------------- | 571 // ----------------------------------------------------------------------------- |
| 572 // Int32Mod |
| 573 |
| 574 |
| 575 TEST_F(MachineOperatorReducerTest, Int32ModWithPowerOfTwo) { |
| 576 Node* p0 = Parameter(0); |
| 577 TRACED_FORRANGE(int32_t, x, 1, 30) { |
| 578 int32_t const divisor = 1 << x; |
| 579 Node* node = |
| 580 graph()->NewNode(machine()->Int32Mod(), p0, Int32Constant(divisor)); |
| 581 Reduction r = Reduce(node); |
| 582 ASSERT_TRUE(r.Changed()); |
| 583 |
| 584 Capture<Node*> branch; |
| 585 Node* phi = r.replacement(); |
| 586 int32_t const mask = divisor - 1; |
| 587 EXPECT_THAT( |
| 588 phi, IsPhi(kMachInt32, |
| 589 IsInt32Sub(IsInt32Constant(0), |
| 590 IsWord32And(IsInt32Sub(IsInt32Constant(0), p0), |
| 591 IsInt32Constant(mask))), |
| 592 IsWord32And(p0, IsInt32Constant(mask)), |
| 593 IsMerge(IsIfTrue(CaptureEq(&branch)), |
| 594 IsIfFalse(AllOf( |
| 595 CaptureEq(&branch), |
| 596 IsBranch(IsInt32LessThan(p0, IsInt32Constant(0)), |
| 597 graph()->start())))))); |
| 598 } |
| 599 } |
| 600 |
| 601 |
| 602 // ----------------------------------------------------------------------------- |
567 // Int32AddWithOverflow | 603 // Int32AddWithOverflow |
568 | 604 |
569 | 605 |
570 TEST_F(MachineOperatorReducerTest, Int32AddWithOverflowWithZero) { | 606 TEST_F(MachineOperatorReducerTest, Int32AddWithOverflowWithZero) { |
571 Node* p0 = Parameter(0); | 607 Node* p0 = Parameter(0); |
572 { | 608 { |
573 Node* add = graph()->NewNode(machine()->Int32AddWithOverflow(), | 609 Node* add = graph()->NewNode(machine()->Int32AddWithOverflow(), |
574 Int32Constant(0), p0); | 610 Int32Constant(0), p0); |
575 | 611 |
576 Reduction r = Reduce(graph()->NewNode(common()->Projection(1), add)); | 612 Reduction r = Reduce(graph()->NewNode(common()->Projection(1), add)); |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
721 Reduction r = Reduce(node); | 757 Reduction r = Reduce(node); |
722 ASSERT_TRUE(r.Changed()); | 758 ASSERT_TRUE(r.Changed()); |
723 EXPECT_THAT(r.replacement(), | 759 EXPECT_THAT(r.replacement(), |
724 IsStore(rep, base, index, value, effect, control)); | 760 IsStore(rep, base, index, value, effect, control)); |
725 } | 761 } |
726 } | 762 } |
727 | 763 |
728 } // namespace compiler | 764 } // namespace compiler |
729 } // namespace internal | 765 } // namespace internal |
730 } // namespace v8 | 766 } // namespace v8 |
OLD | NEW |