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 555 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
566 | 566 |
567 | 567 |
568 // ----------------------------------------------------------------------------- | 568 // ----------------------------------------------------------------------------- |
569 // Word32Ror | 569 // Word32Ror |
570 | 570 |
571 | 571 |
572 TEST_F(MachineOperatorReducerTest, ReduceToWord32RorWithParameters) { | 572 TEST_F(MachineOperatorReducerTest, ReduceToWord32RorWithParameters) { |
573 Node* value = Parameter(0); | 573 Node* value = Parameter(0); |
574 Node* shift = Parameter(1); | 574 Node* shift = Parameter(1); |
575 Node* shl = graph()->NewNode(machine()->Word32Shl(), value, shift); | 575 Node* shl = graph()->NewNode(machine()->Word32Shl(), value, shift); |
576 Node* shr = graph()->NewNode( | 576 Node* sub = graph()->NewNode(machine()->Int32Sub(), Int32Constant(32), shift); |
577 machine()->Word32Shr(), value, | 577 Node* shr = graph()->NewNode(machine()->Word32Shr(), value, sub); |
578 graph()->NewNode(machine()->Int32Sub(), Int32Constant(32), shift)); | |
579 | 578 |
580 // (x << y) | (x >> (32 - y)) => x ror y | 579 // (x << y) | (x >>> (32 - y)) => x ror (32 - y) |
581 Node* node1 = graph()->NewNode(machine()->Word32Or(), shl, shr); | 580 Node* node1 = graph()->NewNode(machine()->Word32Or(), shl, shr); |
582 Reduction reduction1 = Reduce(node1); | 581 Reduction reduction1 = Reduce(node1); |
583 EXPECT_TRUE(reduction1.Changed()); | 582 EXPECT_TRUE(reduction1.Changed()); |
584 EXPECT_EQ(reduction1.replacement(), node1); | 583 EXPECT_EQ(reduction1.replacement(), node1); |
585 EXPECT_THAT(reduction1.replacement(), IsWord32Ror(value, shift)); | 584 EXPECT_THAT(reduction1.replacement(), IsWord32Ror(value, sub)); |
586 | 585 |
587 // (x >> (32 - y)) | (x << y) => x ror y | 586 // (x >>> (32 - y)) | (x << y) => x ror y |
588 Node* node2 = graph()->NewNode(machine()->Word32Or(), shr, shl); | 587 Node* node2 = graph()->NewNode(machine()->Word32Or(), shr, shl); |
589 Reduction reduction2 = Reduce(node2); | 588 Reduction reduction2 = Reduce(node2); |
590 EXPECT_TRUE(reduction2.Changed()); | 589 EXPECT_TRUE(reduction2.Changed()); |
591 EXPECT_EQ(reduction2.replacement(), node2); | 590 EXPECT_EQ(reduction2.replacement(), node2); |
592 EXPECT_THAT(reduction2.replacement(), IsWord32Ror(value, shift)); | 591 EXPECT_THAT(reduction2.replacement(), IsWord32Ror(value, sub)); |
593 } | 592 } |
594 | 593 |
595 | 594 |
596 TEST_F(MachineOperatorReducerTest, ReduceToWord32RorWithConstant) { | 595 TEST_F(MachineOperatorReducerTest, ReduceToWord32RorWithConstant) { |
597 Node* value = Parameter(0); | 596 Node* value = Parameter(0); |
598 TRACED_FORRANGE(int32_t, k, 0, 31) { | 597 TRACED_FORRANGE(int32_t, k, 0, 31) { |
599 Node* shl = | 598 Node* shl = |
600 graph()->NewNode(machine()->Word32Shl(), value, Int32Constant(k)); | 599 graph()->NewNode(machine()->Word32Shl(), value, Int32Constant(k)); |
601 Node* shr = | 600 Node* shr = |
602 graph()->NewNode(machine()->Word32Shr(), value, Int32Constant(32 - k)); | 601 graph()->NewNode(machine()->Word32Shr(), value, Int32Constant(32 - k)); |
603 | 602 |
604 // (x << K) | (x >> ((32 - K) - y)) => x ror K | 603 // (x << K) | (x >>> ((32 - K) - y)) => x ror (32 - K) |
605 Node* node1 = graph()->NewNode(machine()->Word32Or(), shl, shr); | 604 Node* node1 = graph()->NewNode(machine()->Word32Or(), shl, shr); |
606 Reduction reduction1 = Reduce(node1); | 605 Reduction reduction1 = Reduce(node1); |
607 EXPECT_TRUE(reduction1.Changed()); | 606 EXPECT_TRUE(reduction1.Changed()); |
608 EXPECT_EQ(reduction1.replacement(), node1); | 607 EXPECT_EQ(reduction1.replacement(), node1); |
609 EXPECT_THAT(reduction1.replacement(), | 608 EXPECT_THAT(reduction1.replacement(), |
610 IsWord32Ror(value, IsInt32Constant(k))); | 609 IsWord32Ror(value, IsInt32Constant(32 - k))); |
611 | 610 |
612 // (x >> (32 - K)) | (x << K) => x ror K | 611 // (x >>> (32 - K)) | (x << K) => x ror K |
613 Node* node2 = graph()->NewNode(machine()->Word32Or(), shr, shl); | 612 Node* node2 = graph()->NewNode(machine()->Word32Or(), shr, shl); |
614 Reduction reduction2 = Reduce(node2); | 613 Reduction reduction2 = Reduce(node2); |
615 EXPECT_TRUE(reduction2.Changed()); | 614 EXPECT_TRUE(reduction2.Changed()); |
616 EXPECT_EQ(reduction2.replacement(), node2); | 615 EXPECT_EQ(reduction2.replacement(), node2); |
617 EXPECT_THAT(reduction2.replacement(), | 616 EXPECT_THAT(reduction2.replacement(), |
618 IsWord32Ror(value, IsInt32Constant(k))); | 617 IsWord32Ror(value, IsInt32Constant(32 - k))); |
619 } | 618 } |
620 } | 619 } |
621 | 620 |
622 | 621 |
623 TEST_F(MachineOperatorReducerTest, Word32RorWithZeroShift) { | 622 TEST_F(MachineOperatorReducerTest, Word32RorWithZeroShift) { |
624 Node* value = Parameter(0); | 623 Node* value = Parameter(0); |
625 Node* node = | 624 Node* node = |
626 graph()->NewNode(machine()->Word32Ror(), value, Int32Constant(0)); | 625 graph()->NewNode(machine()->Word32Ror(), value, Int32Constant(0)); |
627 Reduction reduction = Reduce(node); | 626 Reduction reduction = Reduce(node); |
628 EXPECT_TRUE(reduction.Changed()); | 627 EXPECT_TRUE(reduction.Changed()); |
(...skipping 619 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1248 Reduction r = Reduce(node); | 1247 Reduction r = Reduce(node); |
1249 ASSERT_TRUE(r.Changed()); | 1248 ASSERT_TRUE(r.Changed()); |
1250 EXPECT_THAT(r.replacement(), | 1249 EXPECT_THAT(r.replacement(), |
1251 IsStore(rep, base, index, value, effect, control)); | 1250 IsStore(rep, base, index, value, effect, control)); |
1252 } | 1251 } |
1253 } | 1252 } |
1254 | 1253 |
1255 } // namespace compiler | 1254 } // namespace compiler |
1256 } // namespace internal | 1255 } // namespace internal |
1257 } // namespace v8 | 1256 } // namespace v8 |
OLD | NEW |