| 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 | 6 |
| 7 #include "src/base/bits.h" | 7 #include "src/base/bits.h" |
| 8 #include "src/base/division-by-constant.h" | 8 #include "src/base/division-by-constant.h" |
| 9 #include "src/codegen.h" | 9 #include "src/codegen.h" |
| 10 #include "src/compiler/diamond.h" | 10 #include "src/compiler/diamond.h" |
| (...skipping 785 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 796 if (m.left().IsWord32And() && m.right().HasValue()) { | 796 if (m.left().IsWord32And() && m.right().HasValue()) { |
| 797 Int32BinopMatcher mleft(m.left().node()); | 797 Int32BinopMatcher mleft(m.left().node()); |
| 798 if (mleft.right().HasValue()) { // (x & K) & K => x & K | 798 if (mleft.right().HasValue()) { // (x & K) & K => x & K |
| 799 node->ReplaceInput(0, mleft.left().node()); | 799 node->ReplaceInput(0, mleft.left().node()); |
| 800 node->ReplaceInput( | 800 node->ReplaceInput( |
| 801 1, Int32Constant(m.right().Value() & mleft.right().Value())); | 801 1, Int32Constant(m.right().Value() & mleft.right().Value())); |
| 802 Reduction const reduction = ReduceWord32And(node); | 802 Reduction const reduction = ReduceWord32And(node); |
| 803 return reduction.Changed() ? reduction : Changed(node); | 803 return reduction.Changed() ? reduction : Changed(node); |
| 804 } | 804 } |
| 805 } | 805 } |
| 806 if (m.left().IsInt32Add() && m.right().IsNegativePowerOf2()) { | 806 if (m.right().IsNegativePowerOf2()) { |
| 807 Int32BinopMatcher mleft(m.left().node()); | 807 int32_t const mask = m.right().Value(); |
| 808 if (mleft.right().HasValue() && | 808 if (m.left().IsWord32Shl()) { |
| 809 (mleft.right().Value() & m.right().Value()) == mleft.right().Value()) { | 809 Uint32BinopMatcher mleft(m.left().node()); |
| 810 // (x + (K << L)) & (-1 << L) => (x & (-1 << L)) + (K << L) | 810 if (mleft.right().HasValue() && |
| 811 node->set_op(machine()->Int32Add()); | 811 mleft.right().Value() >= base::bits::CountTrailingZeros32(mask)) { |
| 812 node->ReplaceInput(0, Word32And(mleft.left().node(), m.right().node())); | 812 // (x << L) & (-1 << K) => x << L iff K >= L |
| 813 node->ReplaceInput(1, mleft.right().node()); | 813 return Replace(mleft.node()); |
| 814 Reduction const reduction = ReduceInt32Add(node); | 814 } |
| 815 return reduction.Changed() ? reduction : Changed(node); | 815 } else if (m.left().IsInt32Add()) { |
| 816 } | 816 Int32BinopMatcher mleft(m.left().node()); |
| 817 if (mleft.left().IsInt32Mul()) { | 817 if (mleft.right().HasValue() && |
| 818 Int32BinopMatcher mleftleft(mleft.left().node()); | 818 (mleft.right().Value() & mask) == mleft.right().Value()) { |
| 819 if (mleftleft.right().IsMultipleOf(-m.right().Value())) { | 819 // (x + (K << L)) & (-1 << L) => (x & (-1 << L)) + (K << L) |
| 820 // (y * (K << L) + x) & (-1 << L) => (x & (-1 << L)) + y * (K << L) | |
| 821 node->set_op(machine()->Int32Add()); | 820 node->set_op(machine()->Int32Add()); |
| 822 node->ReplaceInput(0, | 821 node->ReplaceInput(0, Word32And(mleft.left().node(), m.right().node())); |
| 823 Word32And(mleft.right().node(), m.right().node())); | 822 node->ReplaceInput(1, mleft.right().node()); |
| 824 node->ReplaceInput(1, mleftleft.node()); | |
| 825 Reduction const reduction = ReduceInt32Add(node); | 823 Reduction const reduction = ReduceInt32Add(node); |
| 826 return reduction.Changed() ? reduction : Changed(node); | 824 return reduction.Changed() ? reduction : Changed(node); |
| 827 } | 825 } |
| 828 } | 826 if (mleft.left().IsInt32Mul()) { |
| 829 if (mleft.right().IsInt32Mul()) { | 827 Int32BinopMatcher mleftleft(mleft.left().node()); |
| 830 Int32BinopMatcher mleftright(mleft.right().node()); | 828 if (mleftleft.right().IsMultipleOf(-mask)) { |
| 831 if (mleftright.right().IsMultipleOf(-m.right().Value())) { | 829 // (y * (K << L) + x) & (-1 << L) => (x & (-1 << L)) + y * (K << L) |
| 832 // (x + y * (K << L)) & (-1 << L) => (x & (-1 << L)) + y * (K << L) | 830 node->set_op(machine()->Int32Add()); |
| 833 node->set_op(machine()->Int32Add()); | 831 node->ReplaceInput(0, |
| 834 node->ReplaceInput(0, Word32And(mleft.left().node(), m.right().node())); | 832 Word32And(mleft.right().node(), m.right().node())); |
| 835 node->ReplaceInput(1, mleftright.node()); | 833 node->ReplaceInput(1, mleftleft.node()); |
| 836 Reduction const reduction = ReduceInt32Add(node); | 834 Reduction const reduction = ReduceInt32Add(node); |
| 837 return reduction.Changed() ? reduction : Changed(node); | 835 return reduction.Changed() ? reduction : Changed(node); |
| 836 } |
| 838 } | 837 } |
| 839 } | 838 if (mleft.right().IsInt32Mul()) { |
| 840 if (mleft.left().IsWord32Shl()) { | 839 Int32BinopMatcher mleftright(mleft.right().node()); |
| 841 Int32BinopMatcher mleftleft(mleft.left().node()); | 840 if (mleftright.right().IsMultipleOf(-mask)) { |
| 842 if (mleftleft.right().Is( | 841 // (x + y * (K << L)) & (-1 << L) => (x & (-1 << L)) + y * (K << L) |
| 843 base::bits::CountTrailingZeros32(m.right().Value()))) { | 842 node->set_op(machine()->Int32Add()); |
| 844 // (y << L + x) & (-1 << L) => (x & (-1 << L)) + y << L | 843 node->ReplaceInput(0, |
| 845 node->set_op(machine()->Int32Add()); | 844 Word32And(mleft.left().node(), m.right().node())); |
| 846 node->ReplaceInput(0, | 845 node->ReplaceInput(1, mleftright.node()); |
| 847 Word32And(mleft.right().node(), m.right().node())); | 846 Reduction const reduction = ReduceInt32Add(node); |
| 848 node->ReplaceInput(1, mleftleft.node()); | 847 return reduction.Changed() ? reduction : Changed(node); |
| 849 Reduction const reduction = ReduceInt32Add(node); | 848 } |
| 850 return reduction.Changed() ? reduction : Changed(node); | |
| 851 } | 849 } |
| 852 } | 850 if (mleft.left().IsWord32Shl()) { |
| 853 if (mleft.right().IsWord32Shl()) { | 851 Int32BinopMatcher mleftleft(mleft.left().node()); |
| 854 Int32BinopMatcher mleftright(mleft.right().node()); | 852 if (mleftleft.right().Is(base::bits::CountTrailingZeros32(mask))) { |
| 855 if (mleftright.right().Is( | 853 // (y << L + x) & (-1 << L) => (x & (-1 << L)) + y << L |
| 856 base::bits::CountTrailingZeros32(m.right().Value()))) { | 854 node->set_op(machine()->Int32Add()); |
| 857 // (x + y << L) & (-1 << L) => (x & (-1 << L)) + y << L | 855 node->ReplaceInput(0, |
| 858 node->set_op(machine()->Int32Add()); | 856 Word32And(mleft.right().node(), m.right().node())); |
| 859 node->ReplaceInput(0, Word32And(mleft.left().node(), m.right().node())); | 857 node->ReplaceInput(1, mleftleft.node()); |
| 860 node->ReplaceInput(1, mleftright.node()); | 858 Reduction const reduction = ReduceInt32Add(node); |
| 861 Reduction const reduction = ReduceInt32Add(node); | 859 return reduction.Changed() ? reduction : Changed(node); |
| 862 return reduction.Changed() ? reduction : Changed(node); | 860 } |
| 861 } |
| 862 if (mleft.right().IsWord32Shl()) { |
| 863 Int32BinopMatcher mleftright(mleft.right().node()); |
| 864 if (mleftright.right().Is(base::bits::CountTrailingZeros32(mask))) { |
| 865 // (x + y << L) & (-1 << L) => (x & (-1 << L)) + y << L |
| 866 node->set_op(machine()->Int32Add()); |
| 867 node->ReplaceInput(0, |
| 868 Word32And(mleft.left().node(), m.right().node())); |
| 869 node->ReplaceInput(1, mleftright.node()); |
| 870 Reduction const reduction = ReduceInt32Add(node); |
| 871 return reduction.Changed() ? reduction : Changed(node); |
| 872 } |
| 863 } | 873 } |
| 864 } | 874 } |
| 865 } | 875 } |
| 866 return NoChange(); | 876 return NoChange(); |
| 867 } | 877 } |
| 868 | 878 |
| 869 | 879 |
| 870 Reduction MachineOperatorReducer::ReduceWord32Or(Node* node) { | 880 Reduction MachineOperatorReducer::ReduceWord32Or(Node* node) { |
| 871 DCHECK_EQ(IrOpcode::kWord32Or, node->opcode()); | 881 DCHECK_EQ(IrOpcode::kWord32Or, node->opcode()); |
| 872 Int32BinopMatcher m(node); | 882 Int32BinopMatcher m(node); |
| (...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 932 MachineOperatorBuilder* MachineOperatorReducer::machine() const { | 942 MachineOperatorBuilder* MachineOperatorReducer::machine() const { |
| 933 return jsgraph()->machine(); | 943 return jsgraph()->machine(); |
| 934 } | 944 } |
| 935 | 945 |
| 936 | 946 |
| 937 Graph* MachineOperatorReducer::graph() const { return jsgraph()->graph(); } | 947 Graph* MachineOperatorReducer::graph() const { return jsgraph()->graph(); } |
| 938 | 948 |
| 939 } // namespace compiler | 949 } // namespace compiler |
| 940 } // namespace internal | 950 } // namespace internal |
| 941 } // namespace v8 | 951 } // namespace v8 |
| OLD | NEW |