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 551 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
562 Reduction const r2 = Reduce(graph()->NewNode( | 562 Reduction const r2 = Reduce(graph()->NewNode( |
563 machine()->Word32And(), graph()->NewNode(machine()->Int32Add(), p0, s1), | 563 machine()->Word32And(), graph()->NewNode(machine()->Int32Add(), p0, s1), |
564 Int32Constant(-1 << l))); | 564 Int32Constant(-1 << l))); |
565 ASSERT_TRUE(r2.Changed()); | 565 ASSERT_TRUE(r2.Changed()); |
566 EXPECT_THAT(r2.replacement(), | 566 EXPECT_THAT(r2.replacement(), |
567 IsInt32Add(IsWord32And(p0, IsInt32Constant(-1 << l)), s1)); | 567 IsInt32Add(IsWord32And(p0, IsInt32Constant(-1 << l)), s1)); |
568 } | 568 } |
569 } | 569 } |
570 | 570 |
571 | 571 |
| 572 TEST_F(MachineOperatorReducerTest, |
| 573 Word32AndWithInt32AddAndInt32MulAndConstant) { |
| 574 Node* const p0 = Parameter(0); |
| 575 Node* const p1 = Parameter(1); |
| 576 |
| 577 TRACED_FORRANGE(int32_t, l, 1, 31) { |
| 578 TRACED_FOREACH(int32_t, k, kInt32Values) { |
| 579 if ((k << l) == 0) continue; |
| 580 // (y * (K << L) + x) & (-1 << L) => (x & (-1 << L)) + y * (K << L) |
| 581 Reduction const r1 = Reduce(graph()->NewNode( |
| 582 machine()->Word32And(), |
| 583 graph()->NewNode(machine()->Int32Add(), |
| 584 graph()->NewNode(machine()->Int32Mul(), p1, |
| 585 Int32Constant(k << l)), |
| 586 p0), |
| 587 Int32Constant(-1 << l))); |
| 588 ASSERT_TRUE(r1.Changed()); |
| 589 EXPECT_THAT(r1.replacement(), |
| 590 IsInt32Add(IsWord32And(p0, IsInt32Constant(-1 << l)), |
| 591 IsInt32Mul(p1, IsInt32Constant(k << l)))); |
| 592 |
| 593 // (x + y * (K << L)) & (-1 << L) => (x & (-1 << L)) + y * (K << L) |
| 594 Reduction const r2 = Reduce(graph()->NewNode( |
| 595 machine()->Word32And(), |
| 596 graph()->NewNode(machine()->Int32Add(), p0, |
| 597 graph()->NewNode(machine()->Int32Mul(), p1, |
| 598 Int32Constant(k << l))), |
| 599 Int32Constant(-1 << l))); |
| 600 ASSERT_TRUE(r2.Changed()); |
| 601 EXPECT_THAT(r2.replacement(), |
| 602 IsInt32Add(IsWord32And(p0, IsInt32Constant(-1 << l)), |
| 603 IsInt32Mul(p1, IsInt32Constant(k << l)))); |
| 604 } |
| 605 } |
| 606 } |
| 607 |
| 608 |
572 // ----------------------------------------------------------------------------- | 609 // ----------------------------------------------------------------------------- |
573 // Word32Xor | 610 // Word32Xor |
574 | 611 |
575 | 612 |
576 TEST_F(MachineOperatorReducerTest, Word32XorWithWord32XorAndMinusOne) { | 613 TEST_F(MachineOperatorReducerTest, Word32XorWithWord32XorAndMinusOne) { |
577 Node* const p0 = Parameter(0); | 614 Node* const p0 = Parameter(0); |
578 | 615 |
579 // (x ^ -1) ^ -1 => x | 616 // (x ^ -1) ^ -1 => x |
580 Reduction r1 = Reduce(graph()->NewNode( | 617 Reduction r1 = Reduce(graph()->NewNode( |
581 machine()->Word32Xor(), | 618 machine()->Word32Xor(), |
(...skipping 751 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1333 Reduction r = Reduce(node); | 1370 Reduction r = Reduce(node); |
1334 ASSERT_TRUE(r.Changed()); | 1371 ASSERT_TRUE(r.Changed()); |
1335 EXPECT_THAT(r.replacement(), | 1372 EXPECT_THAT(r.replacement(), |
1336 IsStore(rep, base, index, value, effect, control)); | 1373 IsStore(rep, base, index, value, effect, control)); |
1337 } | 1374 } |
1338 } | 1375 } |
1339 | 1376 |
1340 } // namespace compiler | 1377 } // namespace compiler |
1341 } // namespace internal | 1378 } // namespace internal |
1342 } // namespace v8 | 1379 } // namespace v8 |
OLD | NEW |