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/compiler/machine-operator-reducer.h" | 5 #include "src/compiler/machine-operator-reducer.h" |
6 #include "src/base/bits.h" | 6 #include "src/base/bits.h" |
7 #include "src/base/division-by-constant.h" | 7 #include "src/base/division-by-constant.h" |
8 #include "src/base/ieee754.h" | 8 #include "src/base/ieee754.h" |
9 #include "src/compiler/js-graph.h" | 9 #include "src/compiler/js-graph.h" |
10 #include "src/compiler/typer.h" | 10 #include "src/compiler/typer.h" |
(...skipping 711 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
722 EXPECT_EQ(reduction1.replacement(), node1); | 722 EXPECT_EQ(reduction1.replacement(), node1); |
723 EXPECT_THAT(reduction1.replacement(), IsWord32Ror(value, sub)); | 723 EXPECT_THAT(reduction1.replacement(), IsWord32Ror(value, sub)); |
724 | 724 |
725 // (x >>> (32 - y)) | (x << y) => x ror (32 - y) | 725 // (x >>> (32 - y)) | (x << y) => x ror (32 - y) |
726 Node* node2 = graph()->NewNode(machine()->Word32Or(), shr_l, shl_l); | 726 Node* node2 = graph()->NewNode(machine()->Word32Or(), shr_l, shl_l); |
727 Reduction reduction2 = Reduce(node2); | 727 Reduction reduction2 = Reduce(node2); |
728 EXPECT_TRUE(reduction2.Changed()); | 728 EXPECT_TRUE(reduction2.Changed()); |
729 EXPECT_EQ(reduction2.replacement(), node2); | 729 EXPECT_EQ(reduction2.replacement(), node2); |
730 EXPECT_THAT(reduction2.replacement(), IsWord32Ror(value, sub)); | 730 EXPECT_THAT(reduction2.replacement(), IsWord32Ror(value, sub)); |
731 | 731 |
732 // (x << y) ^ (x >>> (32 - y)) => x ror (32 - y) | |
733 Node* node3 = graph()->NewNode(machine()->Word32Xor(), shl_l, shr_l); | |
734 Reduction reduction3 = Reduce(node3); | |
735 EXPECT_TRUE(reduction3.Changed()); | |
736 EXPECT_EQ(reduction3.replacement(), node3); | |
737 EXPECT_THAT(reduction3.replacement(), IsWord32Ror(value, sub)); | |
738 | |
739 // (x >>> (32 - y)) ^ (x << y) => x ror (32 - y) | |
740 Node* node4 = graph()->NewNode(machine()->Word32Xor(), shr_l, shl_l); | |
741 Reduction reduction4 = Reduce(node4); | |
742 EXPECT_TRUE(reduction4.Changed()); | |
743 EXPECT_EQ(reduction4.replacement(), node4); | |
744 EXPECT_THAT(reduction4.replacement(), IsWord32Ror(value, sub)); | |
745 | |
746 // Testing rotate right. | 732 // Testing rotate right. |
747 Node* shl_r = graph()->NewNode(machine()->Word32Shl(), value, sub); | 733 Node* shl_r = graph()->NewNode(machine()->Word32Shl(), value, sub); |
748 Node* shr_r = graph()->NewNode(machine()->Word32Shr(), value, shift); | 734 Node* shr_r = graph()->NewNode(machine()->Word32Shr(), value, shift); |
749 | 735 |
750 // (x << (32 - y)) | (x >>> y) => x ror y | 736 // (x << (32 - y)) | (x >>> y) => x ror y |
751 Node* node5 = graph()->NewNode(machine()->Word32Or(), shl_r, shr_r); | 737 Node* node3 = graph()->NewNode(machine()->Word32Or(), shl_r, shr_r); |
752 Reduction reduction5 = Reduce(node5); | 738 Reduction reduction3 = Reduce(node3); |
753 EXPECT_TRUE(reduction5.Changed()); | 739 EXPECT_TRUE(reduction3.Changed()); |
754 EXPECT_EQ(reduction5.replacement(), node5); | 740 EXPECT_EQ(reduction3.replacement(), node3); |
755 EXPECT_THAT(reduction5.replacement(), IsWord32Ror(value, shift)); | 741 EXPECT_THAT(reduction3.replacement(), IsWord32Ror(value, shift)); |
756 | 742 |
757 // (x >>> y) | (x << (32 - y)) => x ror y | 743 // (x >>> y) | (x << (32 - y)) => x ror y |
758 Node* node6 = graph()->NewNode(machine()->Word32Or(), shr_r, shl_r); | 744 Node* node4 = graph()->NewNode(machine()->Word32Or(), shr_r, shl_r); |
759 Reduction reduction6 = Reduce(node6); | 745 Reduction reduction4 = Reduce(node4); |
760 EXPECT_TRUE(reduction6.Changed()); | 746 EXPECT_TRUE(reduction4.Changed()); |
761 EXPECT_EQ(reduction6.replacement(), node6); | 747 EXPECT_EQ(reduction4.replacement(), node4); |
762 EXPECT_THAT(reduction6.replacement(), IsWord32Ror(value, shift)); | 748 EXPECT_THAT(reduction4.replacement(), IsWord32Ror(value, shift)); |
| 749 } |
763 | 750 |
764 // (x << (32 - y)) ^ (x >>> y) => x ror y | |
765 Node* node7 = graph()->NewNode(machine()->Word32Xor(), shl_r, shr_r); | |
766 Reduction reduction7 = Reduce(node7); | |
767 EXPECT_TRUE(reduction7.Changed()); | |
768 EXPECT_EQ(reduction7.replacement(), node7); | |
769 EXPECT_THAT(reduction7.replacement(), IsWord32Ror(value, shift)); | |
770 | |
771 // (x >>> y) ^ (x << (32 - y)) => x ror y | |
772 Node* node8 = graph()->NewNode(machine()->Word32Xor(), shr_r, shl_r); | |
773 Reduction reduction8 = Reduce(node8); | |
774 EXPECT_TRUE(reduction8.Changed()); | |
775 EXPECT_EQ(reduction8.replacement(), node8); | |
776 EXPECT_THAT(reduction8.replacement(), IsWord32Ror(value, shift)); | |
777 } | |
778 | 751 |
779 TEST_F(MachineOperatorReducerTest, ReduceToWord32RorWithConstant) { | 752 TEST_F(MachineOperatorReducerTest, ReduceToWord32RorWithConstant) { |
780 Node* value = Parameter(0); | 753 Node* value = Parameter(0); |
781 TRACED_FORRANGE(int32_t, k, 0, 31) { | 754 TRACED_FORRANGE(int32_t, k, 0, 31) { |
782 Node* shl = | 755 Node* shl = |
783 graph()->NewNode(machine()->Word32Shl(), value, Int32Constant(k)); | 756 graph()->NewNode(machine()->Word32Shl(), value, Int32Constant(k)); |
784 Node* shr = | 757 Node* shr = |
785 graph()->NewNode(machine()->Word32Shr(), value, Int32Constant(32 - k)); | 758 graph()->NewNode(machine()->Word32Shr(), value, Int32Constant(32 - k)); |
786 | 759 |
787 // (x << K) | (x >>> ((32 - K) - y)) => x ror (32 - K) | 760 // (x << K) | (x >>> ((32 - K) - y)) => x ror (32 - K) |
(...skipping 1288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2076 Reduction r = Reduce(node); | 2049 Reduction r = Reduce(node); |
2077 ASSERT_TRUE(r.Changed()); | 2050 ASSERT_TRUE(r.Changed()); |
2078 EXPECT_THAT(r.replacement(), | 2051 EXPECT_THAT(r.replacement(), |
2079 IsStore(rep, base, index, value, effect, control)); | 2052 IsStore(rep, base, index, value, effect, control)); |
2080 } | 2053 } |
2081 } | 2054 } |
2082 | 2055 |
2083 } // namespace compiler | 2056 } // namespace compiler |
2084 } // namespace internal | 2057 } // namespace internal |
2085 } // namespace v8 | 2058 } // namespace v8 |
OLD | NEW |