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 518 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
529 } | 529 } |
530 } | 530 } |
531 | 531 |
532 | 532 |
533 TEST_F(MachineOperatorReducerTest, Word32AndWithInt32AddAndConstant) { | 533 TEST_F(MachineOperatorReducerTest, Word32AndWithInt32AddAndConstant) { |
534 Node* const p0 = Parameter(0); | 534 Node* const p0 = Parameter(0); |
535 Node* const p1 = Parameter(1); | 535 Node* const p1 = Parameter(1); |
536 | 536 |
537 TRACED_FORRANGE(int32_t, l, 1, 31) { | 537 TRACED_FORRANGE(int32_t, l, 1, 31) { |
538 TRACED_FOREACH(int32_t, k, kInt32Values) { | 538 TRACED_FOREACH(int32_t, k, kInt32Values) { |
| 539 if ((k << l) == 0) continue; |
539 // (x + (K << L)) & (-1 << L) => (x & (-1 << L)) + (K << L) | 540 // (x + (K << L)) & (-1 << L) => (x & (-1 << L)) + (K << L) |
540 Reduction const r = Reduce(graph()->NewNode( | 541 Reduction const r = Reduce(graph()->NewNode( |
541 machine()->Word32And(), | 542 machine()->Word32And(), |
542 graph()->NewNode(machine()->Int32Add(), p0, Int32Constant(k << l)), | 543 graph()->NewNode(machine()->Int32Add(), p0, Int32Constant(k << l)), |
543 Int32Constant(-1 << l))); | 544 Int32Constant(-1 << l))); |
544 ASSERT_TRUE(r.Changed()); | 545 ASSERT_TRUE(r.Changed()); |
545 EXPECT_THAT(r.replacement(), | 546 EXPECT_THAT(r.replacement(), |
546 IsInt32Add(IsWord32And(p0, IsInt32Constant(-1 << l)), | 547 IsInt32Add(IsWord32And(p0, IsInt32Constant(-1 << l)), |
547 IsInt32Constant(k << l))); | 548 IsInt32Constant(k << l))); |
548 } | 549 } |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
761 EXPECT_THAT(r.replacement(), IsWord32And(p0, IsInt32Constant(m))); | 762 EXPECT_THAT(r.replacement(), IsWord32And(p0, IsInt32Constant(m))); |
762 } | 763 } |
763 } | 764 } |
764 | 765 |
765 | 766 |
766 TEST_F(MachineOperatorReducerTest, | 767 TEST_F(MachineOperatorReducerTest, |
767 Word32ShlWithWord32SarAndInt32AddAndConstant) { | 768 Word32ShlWithWord32SarAndInt32AddAndConstant) { |
768 Node* const p0 = Parameter(0); | 769 Node* const p0 = Parameter(0); |
769 TRACED_FOREACH(int32_t, k, kInt32Values) { | 770 TRACED_FOREACH(int32_t, k, kInt32Values) { |
770 TRACED_FORRANGE(int32_t, l, 1, 31) { | 771 TRACED_FORRANGE(int32_t, l, 1, 31) { |
| 772 if ((k << l) == 0) continue; |
771 // (x + (K << L)) >> L << L => (x & (-1 << L)) + (K << L) | 773 // (x + (K << L)) >> L << L => (x & (-1 << L)) + (K << L) |
772 Reduction const r = Reduce(graph()->NewNode( | 774 Reduction const r = Reduce(graph()->NewNode( |
773 machine()->Word32Shl(), | 775 machine()->Word32Shl(), |
774 graph()->NewNode(machine()->Word32Sar(), | 776 graph()->NewNode(machine()->Word32Sar(), |
775 graph()->NewNode(machine()->Int32Add(), p0, | 777 graph()->NewNode(machine()->Int32Add(), p0, |
776 Int32Constant(k << l)), | 778 Int32Constant(k << l)), |
777 Int32Constant(l)), | 779 Int32Constant(l)), |
778 Int32Constant(l))); | 780 Int32Constant(l))); |
779 ASSERT_TRUE(r.Changed()); | 781 ASSERT_TRUE(r.Changed()); |
780 EXPECT_THAT(r.replacement(), | 782 EXPECT_THAT(r.replacement(), |
(...skipping 550 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1331 Reduction r = Reduce(node); | 1333 Reduction r = Reduce(node); |
1332 ASSERT_TRUE(r.Changed()); | 1334 ASSERT_TRUE(r.Changed()); |
1333 EXPECT_THAT(r.replacement(), | 1335 EXPECT_THAT(r.replacement(), |
1334 IsStore(rep, base, index, value, effect, control)); | 1336 IsStore(rep, base, index, value, effect, control)); |
1335 } | 1337 } |
1336 } | 1338 } |
1337 | 1339 |
1338 } // namespace compiler | 1340 } // namespace compiler |
1339 } // namespace internal | 1341 } // namespace internal |
1340 } // namespace v8 | 1342 } // namespace v8 |
OLD | NEW |