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/base/division-by-constant.h" | 6 #include "src/base/division-by-constant.h" |
7 #include "src/compiler/js-graph.h" | 7 #include "src/compiler/js-graph.h" |
8 #include "src/compiler/machine-operator-reducer.h" | 8 #include "src/compiler/machine-operator-reducer.h" |
9 #include "src/compiler/typer.h" | 9 #include "src/compiler/typer.h" |
10 #include "test/unittests/compiler/graph-unittest.h" | 10 #include "test/unittests/compiler/graph-unittest.h" |
(...skipping 598 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
609 Reduction const r2 = Reduce(graph()->NewNode( | 609 Reduction const r2 = Reduce(graph()->NewNode( |
610 machine()->Word32And(), graph()->NewNode(machine()->Int32Add(), p0, s1), | 610 machine()->Word32And(), graph()->NewNode(machine()->Int32Add(), p0, s1), |
611 Int32Constant(-1 << l))); | 611 Int32Constant(-1 << l))); |
612 ASSERT_TRUE(r2.Changed()); | 612 ASSERT_TRUE(r2.Changed()); |
613 EXPECT_THAT(r2.replacement(), | 613 EXPECT_THAT(r2.replacement(), |
614 IsInt32Add(IsWord32And(p0, IsInt32Constant(-1 << l)), s1)); | 614 IsInt32Add(IsWord32And(p0, IsInt32Constant(-1 << l)), s1)); |
615 } | 615 } |
616 } | 616 } |
617 | 617 |
618 | 618 |
| 619 TEST_F(MachineOperatorReducerTest, Word32AndWithInt32MulAndConstant) { |
| 620 Node* const p0 = Parameter(0); |
| 621 |
| 622 TRACED_FORRANGE(int32_t, l, 1, 31) { |
| 623 TRACED_FOREACH(int32_t, k, kInt32Values) { |
| 624 if ((k << l) == 0) continue; |
| 625 |
| 626 // (x * (K << L)) & (-1 << L) => x * (K << L) |
| 627 Reduction const r1 = Reduce(graph()->NewNode( |
| 628 machine()->Word32And(), |
| 629 graph()->NewNode(machine()->Int32Mul(), p0, Int32Constant(k << l)), |
| 630 Int32Constant(-1 << l))); |
| 631 ASSERT_TRUE(r1.Changed()); |
| 632 EXPECT_THAT(r1.replacement(), IsInt32Mul(p0, IsInt32Constant(k << l))); |
| 633 |
| 634 // ((K << L) * x) & (-1 << L) => x * (K << L) |
| 635 Reduction const r2 = Reduce(graph()->NewNode( |
| 636 machine()->Word32And(), |
| 637 graph()->NewNode(machine()->Int32Mul(), Int32Constant(k << l), p0), |
| 638 Int32Constant(-1 << l))); |
| 639 ASSERT_TRUE(r2.Changed()); |
| 640 EXPECT_THAT(r2.replacement(), IsInt32Mul(p0, IsInt32Constant(k << l))); |
| 641 } |
| 642 } |
| 643 } |
| 644 |
| 645 |
619 TEST_F(MachineOperatorReducerTest, | 646 TEST_F(MachineOperatorReducerTest, |
620 Word32AndWithInt32AddAndInt32MulAndConstant) { | 647 Word32AndWithInt32AddAndInt32MulAndConstant) { |
621 Node* const p0 = Parameter(0); | 648 Node* const p0 = Parameter(0); |
622 Node* const p1 = Parameter(1); | 649 Node* const p1 = Parameter(1); |
623 | 650 |
624 TRACED_FORRANGE(int32_t, l, 1, 31) { | 651 TRACED_FORRANGE(int32_t, l, 1, 31) { |
625 TRACED_FOREACH(int32_t, k, kInt32Values) { | 652 TRACED_FOREACH(int32_t, k, kInt32Values) { |
626 if ((k << l) == 0) continue; | 653 if ((k << l) == 0) continue; |
627 // (y * (K << L) + x) & (-1 << L) => (x & (-1 << L)) + y * (K << L) | 654 // (y * (K << L) + x) & (-1 << L) => (x & (-1 << L)) + y * (K << L) |
628 Reduction const r1 = Reduce(graph()->NewNode( | 655 Reduction const r1 = Reduce(graph()->NewNode( |
(...skipping 870 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1499 Reduction r = Reduce(node); | 1526 Reduction r = Reduce(node); |
1500 ASSERT_TRUE(r.Changed()); | 1527 ASSERT_TRUE(r.Changed()); |
1501 EXPECT_THAT(r.replacement(), | 1528 EXPECT_THAT(r.replacement(), |
1502 IsStore(rep, base, index, value, effect, control)); | 1529 IsStore(rep, base, index, value, effect, control)); |
1503 } | 1530 } |
1504 } | 1531 } |
1505 | 1532 |
1506 } // namespace compiler | 1533 } // namespace compiler |
1507 } // namespace internal | 1534 } // namespace internal |
1508 } // namespace v8 | 1535 } // namespace v8 |
OLD | NEW |