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 514 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 EXPECT_THAT(r2.replacement(), | 525 EXPECT_THAT(r2.replacement(), |
526 (k & l) ? IsWord32And(p0, IsInt32Constant(k & l)) | 526 (k & l) ? IsWord32And(p0, IsInt32Constant(k & l)) |
527 : IsInt32Constant(0)); | 527 : IsInt32Constant(0)); |
528 } | 528 } |
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 | 536 |
536 TRACED_FOREACH(int32_t, k, kInt32Values) { | 537 TRACED_FORRANGE(int32_t, l, 1, 31) { |
537 TRACED_FORRANGE(int32_t, l, 1, 31) { | 538 TRACED_FOREACH(int32_t, k, kInt32Values) { |
538 // (x + (K << L)) & (-1 << L) => (x & (-1 << L)) + (K << L) | 539 // (x + (K << L)) & (-1 << L) => (x & (-1 << L)) + (K << L) |
539 Reduction const r = Reduce(graph()->NewNode( | 540 Reduction const r = Reduce(graph()->NewNode( |
540 machine()->Word32And(), | 541 machine()->Word32And(), |
541 graph()->NewNode(machine()->Int32Add(), p0, Int32Constant(k << l)), | 542 graph()->NewNode(machine()->Int32Add(), p0, Int32Constant(k << l)), |
542 Int32Constant(-1 << l))); | 543 Int32Constant(-1 << l))); |
543 ASSERT_TRUE(r.Changed()); | 544 ASSERT_TRUE(r.Changed()); |
544 EXPECT_THAT(r.replacement(), | 545 EXPECT_THAT(r.replacement(), |
545 IsInt32Add(IsWord32And(p0, IsInt32Constant(-1 << l)), | 546 IsInt32Add(IsWord32And(p0, IsInt32Constant(-1 << l)), |
546 IsInt32Constant(k << l))); | 547 IsInt32Constant(k << l))); |
547 } | 548 } |
| 549 |
| 550 Node* s1 = graph()->NewNode(machine()->Word32Shl(), p1, Int32Constant(l)); |
| 551 |
| 552 // (y << L + x) & (-1 << L) => (x & (-1 << L)) + y << L |
| 553 Reduction const r1 = Reduce(graph()->NewNode( |
| 554 machine()->Word32And(), graph()->NewNode(machine()->Int32Add(), s1, p0), |
| 555 Int32Constant(-1 << l))); |
| 556 ASSERT_TRUE(r1.Changed()); |
| 557 EXPECT_THAT(r1.replacement(), |
| 558 IsInt32Add(IsWord32And(p0, IsInt32Constant(-1 << l)), s1)); |
| 559 |
| 560 // (x + y << L) & (-1 << L) => (x & (-1 << L)) + y << L |
| 561 Reduction const r2 = Reduce(graph()->NewNode( |
| 562 machine()->Word32And(), graph()->NewNode(machine()->Int32Add(), p0, s1), |
| 563 Int32Constant(-1 << l))); |
| 564 ASSERT_TRUE(r2.Changed()); |
| 565 EXPECT_THAT(r2.replacement(), |
| 566 IsInt32Add(IsWord32And(p0, IsInt32Constant(-1 << l)), s1)); |
548 } | 567 } |
549 } | 568 } |
550 | 569 |
551 | 570 |
552 // ----------------------------------------------------------------------------- | 571 // ----------------------------------------------------------------------------- |
553 // Word32Xor | 572 // Word32Xor |
554 | 573 |
555 | 574 |
556 TEST_F(MachineOperatorReducerTest, Word32XorWithWord32XorAndMinusOne) { | 575 TEST_F(MachineOperatorReducerTest, Word32XorWithWord32XorAndMinusOne) { |
557 Node* const p0 = Parameter(0); | 576 Node* const p0 = Parameter(0); |
(...skipping 754 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1312 Reduction r = Reduce(node); | 1331 Reduction r = Reduce(node); |
1313 ASSERT_TRUE(r.Changed()); | 1332 ASSERT_TRUE(r.Changed()); |
1314 EXPECT_THAT(r.replacement(), | 1333 EXPECT_THAT(r.replacement(), |
1315 IsStore(rep, base, index, value, effect, control)); | 1334 IsStore(rep, base, index, value, effect, control)); |
1316 } | 1335 } |
1317 } | 1336 } |
1318 | 1337 |
1319 } // namespace compiler | 1338 } // namespace compiler |
1320 } // namespace internal | 1339 } // namespace internal |
1321 } // namespace v8 | 1340 } // namespace v8 |
OLD | NEW |