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/base/ieee754.h" | 9 #include "src/base/ieee754.h" |
10 #include "src/codegen.h" | 10 #include "src/codegen.h" |
(...skipping 135 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
146 if (m.left().IsWord32Xor() && m.right().Is(-1)) { | 146 if (m.left().IsWord32Xor() && m.right().Is(-1)) { |
147 Int32BinopMatcher mleft(m.left().node()); | 147 Int32BinopMatcher mleft(m.left().node()); |
148 if (mleft.right().Is(-1)) { // (x ^ -1) ^ -1 => x | 148 if (mleft.right().Is(-1)) { // (x ^ -1) ^ -1 => x |
149 return Replace(mleft.left().node()); | 149 return Replace(mleft.left().node()); |
150 } | 150 } |
151 } | 151 } |
152 break; | 152 break; |
153 } | 153 } |
154 case IrOpcode::kWord32Shl: | 154 case IrOpcode::kWord32Shl: |
155 return ReduceWord32Shl(node); | 155 return ReduceWord32Shl(node); |
156 case IrOpcode::kWord32Shr: { | 156 case IrOpcode::kWord32Shr: |
157 Uint32BinopMatcher m(node); | 157 return ReduceWord32Shr(node); |
158 if (m.right().Is(0)) return Replace(m.left().node()); // x >>> 0 => x | |
159 if (m.IsFoldable()) { // K >>> K => K | |
160 return ReplaceInt32(m.left().Value() >> m.right().Value()); | |
161 } | |
162 return ReduceWord32Shifts(node); | |
163 } | |
164 case IrOpcode::kWord32Sar: | 158 case IrOpcode::kWord32Sar: |
165 return ReduceWord32Sar(node); | 159 return ReduceWord32Sar(node); |
166 case IrOpcode::kWord32Ror: { | 160 case IrOpcode::kWord32Ror: { |
167 Int32BinopMatcher m(node); | 161 Int32BinopMatcher m(node); |
168 if (m.right().Is(0)) return Replace(m.left().node()); // x ror 0 => x | 162 if (m.right().Is(0)) return Replace(m.left().node()); // x ror 0 => x |
169 if (m.IsFoldable()) { // K ror K => K | 163 if (m.IsFoldable()) { // K ror K => K |
170 return ReplaceInt32( | 164 return ReplaceInt32( |
171 base::bits::RotateRight32(m.left().Value(), m.right().Value())); | 165 base::bits::RotateRight32(m.left().Value(), m.right().Value())); |
172 } | 166 } |
173 break; | 167 break; |
(...skipping 634 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
808 Uint32Constant(~((1U << m.right().Value()) - 1U))); | 802 Uint32Constant(~((1U << m.right().Value()) - 1U))); |
809 NodeProperties::ChangeOp(node, machine()->Word32And()); | 803 NodeProperties::ChangeOp(node, machine()->Word32And()); |
810 Reduction reduction = ReduceWord32And(node); | 804 Reduction reduction = ReduceWord32And(node); |
811 return reduction.Changed() ? reduction : Changed(node); | 805 return reduction.Changed() ? reduction : Changed(node); |
812 } | 806 } |
813 } | 807 } |
814 } | 808 } |
815 return ReduceWord32Shifts(node); | 809 return ReduceWord32Shifts(node); |
816 } | 810 } |
817 | 811 |
| 812 Reduction MachineOperatorReducer::ReduceWord32Shr(Node* node) { |
| 813 Uint32BinopMatcher m(node); |
| 814 if (m.right().Is(0)) return Replace(m.left().node()); // x >>> 0 => x |
| 815 if (m.IsFoldable()) { // K >>> K => K |
| 816 return ReplaceInt32(m.left().Value() >> m.right().Value()); |
| 817 } |
| 818 if (m.left().IsWord32And() && m.right().HasValue()) { |
| 819 Uint32BinopMatcher mleft(m.left().node()); |
| 820 if (mleft.right().HasValue()) { |
| 821 uint32_t shift = m.right().Value() & 0x1f; |
| 822 uint32_t mask = mleft.right().Value(); |
| 823 if ((mask >> shift) == 0) { |
| 824 // (m >>> s) == 0 implies ((x & m) >>> s) == 0 |
| 825 return ReplaceInt32(0); |
| 826 } |
| 827 } |
| 828 } |
| 829 return ReduceWord32Shifts(node); |
| 830 } |
818 | 831 |
819 Reduction MachineOperatorReducer::ReduceWord32Sar(Node* node) { | 832 Reduction MachineOperatorReducer::ReduceWord32Sar(Node* node) { |
820 Int32BinopMatcher m(node); | 833 Int32BinopMatcher m(node); |
821 if (m.right().Is(0)) return Replace(m.left().node()); // x >> 0 => x | 834 if (m.right().Is(0)) return Replace(m.left().node()); // x >> 0 => x |
822 if (m.IsFoldable()) { // K >> K => K | 835 if (m.IsFoldable()) { // K >> K => K |
823 return ReplaceInt32(m.left().Value() >> m.right().Value()); | 836 return ReplaceInt32(m.left().Value() >> m.right().Value()); |
824 } | 837 } |
825 if (m.left().IsWord32Shl()) { | 838 if (m.left().IsWord32Shl()) { |
826 Int32BinopMatcher mleft(m.left().node()); | 839 Int32BinopMatcher mleft(m.left().node()); |
827 if (mleft.left().IsComparison()) { | 840 if (mleft.left().IsComparison()) { |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1102 MachineOperatorBuilder* MachineOperatorReducer::machine() const { | 1115 MachineOperatorBuilder* MachineOperatorReducer::machine() const { |
1103 return jsgraph()->machine(); | 1116 return jsgraph()->machine(); |
1104 } | 1117 } |
1105 | 1118 |
1106 | 1119 |
1107 Graph* MachineOperatorReducer::graph() const { return jsgraph()->graph(); } | 1120 Graph* MachineOperatorReducer::graph() const { return jsgraph()->graph(); } |
1108 | 1121 |
1109 } // namespace compiler | 1122 } // namespace compiler |
1110 } // namespace internal | 1123 } // namespace internal |
1111 } // namespace v8 | 1124 } // namespace v8 |
OLD | NEW |