| 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 494 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 505 TRACED_FOREACH(int32_t, k, kInt32Values) { | 505 TRACED_FOREACH(int32_t, k, kInt32Values) { |
| 506 TRACED_FOREACH(int32_t, l, kInt32Values) { | 506 TRACED_FOREACH(int32_t, l, kInt32Values) { |
| 507 if (k == 0 || k == -1 || l == 0 || l == -1) continue; | 507 if (k == 0 || k == -1 || l == 0 || l == -1) continue; |
| 508 | 508 |
| 509 // (x & K) & L => x & (K & L) | 509 // (x & K) & L => x & (K & L) |
| 510 Reduction const r1 = Reduce(graph()->NewNode( | 510 Reduction const r1 = Reduce(graph()->NewNode( |
| 511 machine()->Word32And(), | 511 machine()->Word32And(), |
| 512 graph()->NewNode(machine()->Word32And(), p0, Int32Constant(k)), | 512 graph()->NewNode(machine()->Word32And(), p0, Int32Constant(k)), |
| 513 Int32Constant(l))); | 513 Int32Constant(l))); |
| 514 ASSERT_TRUE(r1.Changed()); | 514 ASSERT_TRUE(r1.Changed()); |
| 515 EXPECT_THAT(r1.replacement(), IsWord32And(p0, IsInt32Constant(k & l))); | 515 EXPECT_THAT(r1.replacement(), |
| 516 (k & l) ? IsWord32And(p0, IsInt32Constant(k & l)) |
| 517 : IsInt32Constant(0)); |
| 516 | 518 |
| 517 // (K & x) & L => x & (K & L) | 519 // (K & x) & L => x & (K & L) |
| 518 Reduction const r2 = Reduce(graph()->NewNode( | 520 Reduction const r2 = Reduce(graph()->NewNode( |
| 519 machine()->Word32And(), | 521 machine()->Word32And(), |
| 520 graph()->NewNode(machine()->Word32And(), Int32Constant(k), p0), | 522 graph()->NewNode(machine()->Word32And(), Int32Constant(k), p0), |
| 521 Int32Constant(l))); | 523 Int32Constant(l))); |
| 522 ASSERT_TRUE(r2.Changed()); | 524 ASSERT_TRUE(r2.Changed()); |
| 523 EXPECT_THAT(r2.replacement(), IsWord32And(p0, IsInt32Constant(k & l))); | 525 EXPECT_THAT(r2.replacement(), |
| 526 (k & l) ? IsWord32And(p0, IsInt32Constant(k & l)) |
| 527 : IsInt32Constant(0)); |
| 524 } | 528 } |
| 525 } | 529 } |
| 526 } | 530 } |
| 527 | 531 |
| 528 | 532 |
| 529 TEST_F(MachineOperatorReducerTest, Word32AndWithInt32AddAndConstant) { | 533 TEST_F(MachineOperatorReducerTest, Word32AndWithInt32AddAndConstant) { |
| 530 Node* const p0 = Parameter(0); | 534 Node* const p0 = Parameter(0); |
| 531 | 535 |
| 532 TRACED_FOREACH(int32_t, k, kInt32Values) { | 536 TRACED_FOREACH(int32_t, k, kInt32Values) { |
| 533 TRACED_FORRANGE(int32_t, l, 1, 31) { | 537 TRACED_FORRANGE(int32_t, l, 1, 31) { |
| (...skipping 199 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 733 graph()->NewNode(machine()->Word32Sar(), p0, Int32Constant(x)), | 737 graph()->NewNode(machine()->Word32Sar(), p0, Int32Constant(x)), |
| 734 Int32Constant(x)); | 738 Int32Constant(x)); |
| 735 Reduction r = Reduce(node); | 739 Reduction r = Reduce(node); |
| 736 ASSERT_TRUE(r.Changed()); | 740 ASSERT_TRUE(r.Changed()); |
| 737 int32_t m = bit_cast<int32_t>(~((1U << x) - 1U)); | 741 int32_t m = bit_cast<int32_t>(~((1U << x) - 1U)); |
| 738 EXPECT_THAT(r.replacement(), IsWord32And(p0, IsInt32Constant(m))); | 742 EXPECT_THAT(r.replacement(), IsWord32And(p0, IsInt32Constant(m))); |
| 739 } | 743 } |
| 740 } | 744 } |
| 741 | 745 |
| 742 | 746 |
| 747 TEST_F(MachineOperatorReducerTest, |
| 748 Word32ShlWithWord32SarAndInt32AddAndConstant) { |
| 749 Node* const p0 = Parameter(0); |
| 750 TRACED_FOREACH(int32_t, k, kInt32Values) { |
| 751 TRACED_FORRANGE(int32_t, l, 1, 31) { |
| 752 // (x + (K << L)) >> L << L => (x & (-1 << L)) + (K << L) |
| 753 Reduction const r = Reduce(graph()->NewNode( |
| 754 machine()->Word32Shl(), |
| 755 graph()->NewNode(machine()->Word32Sar(), |
| 756 graph()->NewNode(machine()->Int32Add(), p0, |
| 757 Int32Constant(k << l)), |
| 758 Int32Constant(l)), |
| 759 Int32Constant(l))); |
| 760 ASSERT_TRUE(r.Changed()); |
| 761 EXPECT_THAT(r.replacement(), |
| 762 IsInt32Add(IsWord32And(p0, IsInt32Constant(-1 << l)), |
| 763 IsInt32Constant(k << l))); |
| 764 } |
| 765 } |
| 766 } |
| 767 |
| 768 |
| 743 TEST_F(MachineOperatorReducerTest, Word32ShlWithWord32Shr) { | 769 TEST_F(MachineOperatorReducerTest, Word32ShlWithWord32Shr) { |
| 744 Node* p0 = Parameter(0); | 770 Node* p0 = Parameter(0); |
| 745 TRACED_FORRANGE(int32_t, x, 1, 31) { | 771 TRACED_FORRANGE(int32_t, x, 1, 31) { |
| 746 Node* node = graph()->NewNode( | 772 Node* node = graph()->NewNode( |
| 747 machine()->Word32Shl(), | 773 machine()->Word32Shl(), |
| 748 graph()->NewNode(machine()->Word32Shr(), p0, Int32Constant(x)), | 774 graph()->NewNode(machine()->Word32Shr(), p0, Int32Constant(x)), |
| 749 Int32Constant(x)); | 775 Int32Constant(x)); |
| 750 Reduction r = Reduce(node); | 776 Reduction r = Reduce(node); |
| 751 ASSERT_TRUE(r.Changed()); | 777 ASSERT_TRUE(r.Changed()); |
| 752 int32_t m = bit_cast<int32_t>(~((1U << x) - 1U)); | 778 int32_t m = bit_cast<int32_t>(~((1U << x) - 1U)); |
| (...skipping 533 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1286 Reduction r = Reduce(node); | 1312 Reduction r = Reduce(node); |
| 1287 ASSERT_TRUE(r.Changed()); | 1313 ASSERT_TRUE(r.Changed()); |
| 1288 EXPECT_THAT(r.replacement(), | 1314 EXPECT_THAT(r.replacement(), |
| 1289 IsStore(rep, base, index, value, effect, control)); | 1315 IsStore(rep, base, index, value, effect, control)); |
| 1290 } | 1316 } |
| 1291 } | 1317 } |
| 1292 | 1318 |
| 1293 } // namespace compiler | 1319 } // namespace compiler |
| 1294 } // namespace internal | 1320 } // namespace internal |
| 1295 } // namespace v8 | 1321 } // namespace v8 |
| OLD | NEW |