| 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 217 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 return Changed(node); | 228 return Changed(node); |
| 229 } | 229 } |
| 230 if (m.right().IsPowerOf2()) { // x * 2^n => x << n | 230 if (m.right().IsPowerOf2()) { // x * 2^n => x << n |
| 231 node->ReplaceInput(1, Int32Constant(WhichPowerOf2(m.right().Value()))); | 231 node->ReplaceInput(1, Int32Constant(WhichPowerOf2(m.right().Value()))); |
| 232 NodeProperties::ChangeOp(node, machine()->Word32Shl()); | 232 NodeProperties::ChangeOp(node, machine()->Word32Shl()); |
| 233 Reduction reduction = ReduceWord32Shl(node); | 233 Reduction reduction = ReduceWord32Shl(node); |
| 234 return reduction.Changed() ? reduction : Changed(node); | 234 return reduction.Changed() ? reduction : Changed(node); |
| 235 } | 235 } |
| 236 break; | 236 break; |
| 237 } | 237 } |
| 238 case IrOpcode::kInt32MulWithOverflow: { |
| 239 Int32BinopMatcher m(node); |
| 240 if (m.right().Is(2)) { |
| 241 node->ReplaceInput(1, m.left().node()); |
| 242 NodeProperties::ChangeOp(node, machine()->Int32AddWithOverflow()); |
| 243 return Changed(node); |
| 244 } |
| 245 if (m.right().Is(-1)) { |
| 246 node->ReplaceInput(0, Int32Constant(0)); |
| 247 node->ReplaceInput(1, m.left().node()); |
| 248 NodeProperties::ChangeOp(node, machine()->Int32SubWithOverflow()); |
| 249 return Changed(node); |
| 250 } |
| 251 break; |
| 252 } |
| 238 case IrOpcode::kInt32Div: | 253 case IrOpcode::kInt32Div: |
| 239 return ReduceInt32Div(node); | 254 return ReduceInt32Div(node); |
| 240 case IrOpcode::kUint32Div: | 255 case IrOpcode::kUint32Div: |
| 241 return ReduceUint32Div(node); | 256 return ReduceUint32Div(node); |
| 242 case IrOpcode::kInt32Mod: | 257 case IrOpcode::kInt32Mod: |
| 243 return ReduceInt32Mod(node); | 258 return ReduceInt32Mod(node); |
| 244 case IrOpcode::kUint32Mod: | 259 case IrOpcode::kUint32Mod: |
| 245 return ReduceUint32Mod(node); | 260 return ReduceUint32Mod(node); |
| 246 case IrOpcode::kInt32LessThan: { | 261 case IrOpcode::kInt32LessThan: { |
| 247 Int32BinopMatcher m(node); | 262 Int32BinopMatcher m(node); |
| (...skipping 576 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 824 | 839 |
| 825 Reduction MachineOperatorReducer::ReduceProjection(size_t index, Node* node) { | 840 Reduction MachineOperatorReducer::ReduceProjection(size_t index, Node* node) { |
| 826 switch (node->opcode()) { | 841 switch (node->opcode()) { |
| 827 case IrOpcode::kInt32AddWithOverflow: { | 842 case IrOpcode::kInt32AddWithOverflow: { |
| 828 DCHECK(index == 0 || index == 1); | 843 DCHECK(index == 0 || index == 1); |
| 829 Int32BinopMatcher m(node); | 844 Int32BinopMatcher m(node); |
| 830 if (m.IsFoldable()) { | 845 if (m.IsFoldable()) { |
| 831 int32_t val; | 846 int32_t val; |
| 832 bool ovf = base::bits::SignedAddOverflow32(m.left().Value(), | 847 bool ovf = base::bits::SignedAddOverflow32(m.left().Value(), |
| 833 m.right().Value(), &val); | 848 m.right().Value(), &val); |
| 834 return ReplaceInt32((index == 0) ? val : ovf); | 849 return ReplaceInt32(index == 0 ? val : ovf); |
| 835 } | 850 } |
| 836 if (m.right().Is(0)) { | 851 if (m.right().Is(0)) { |
| 837 return (index == 0) ? Replace(m.left().node()) : ReplaceInt32(0); | 852 return Replace(index == 0 ? m.left().node() : m.right().node()); |
| 838 } | 853 } |
| 839 break; | 854 break; |
| 840 } | 855 } |
| 841 case IrOpcode::kInt32SubWithOverflow: { | 856 case IrOpcode::kInt32SubWithOverflow: { |
| 842 DCHECK(index == 0 || index == 1); | 857 DCHECK(index == 0 || index == 1); |
| 843 Int32BinopMatcher m(node); | 858 Int32BinopMatcher m(node); |
| 844 if (m.IsFoldable()) { | 859 if (m.IsFoldable()) { |
| 845 int32_t val; | 860 int32_t val; |
| 846 bool ovf = base::bits::SignedSubOverflow32(m.left().Value(), | 861 bool ovf = base::bits::SignedSubOverflow32(m.left().Value(), |
| 847 m.right().Value(), &val); | 862 m.right().Value(), &val); |
| 848 return ReplaceInt32((index == 0) ? val : ovf); | 863 return ReplaceInt32(index == 0 ? val : ovf); |
| 849 } | 864 } |
| 850 if (m.right().Is(0)) { | 865 if (m.right().Is(0)) { |
| 851 return (index == 0) ? Replace(m.left().node()) : ReplaceInt32(0); | 866 return Replace(index == 0 ? m.left().node() : m.right().node()); |
| 852 } | 867 } |
| 853 break; | 868 break; |
| 854 } | 869 } |
| 870 case IrOpcode::kInt32MulWithOverflow: { |
| 871 DCHECK(index == 0 || index == 1); |
| 872 Int32BinopMatcher m(node); |
| 873 if (m.IsFoldable()) { |
| 874 int32_t val; |
| 875 bool ovf = base::bits::SignedMulOverflow32(m.left().Value(), |
| 876 m.right().Value(), &val); |
| 877 return ReplaceInt32(index == 0 ? val : ovf); |
| 878 } |
| 879 if (m.right().Is(0)) { |
| 880 return Replace(m.right().node()); |
| 881 } |
| 882 if (m.right().Is(1)) { |
| 883 return index == 0 ? Replace(m.left().node()) : ReplaceInt32(0); |
| 884 } |
| 885 break; |
| 886 } |
| 855 default: | 887 default: |
| 856 break; | 888 break; |
| 857 } | 889 } |
| 858 return NoChange(); | 890 return NoChange(); |
| 859 } | 891 } |
| 860 | 892 |
| 861 | 893 |
| 862 Reduction MachineOperatorReducer::ReduceWord32Shifts(Node* node) { | 894 Reduction MachineOperatorReducer::ReduceWord32Shifts(Node* node) { |
| 863 DCHECK((node->opcode() == IrOpcode::kWord32Shl) || | 895 DCHECK((node->opcode() == IrOpcode::kWord32Shl) || |
| 864 (node->opcode() == IrOpcode::kWord32Shr) || | 896 (node->opcode() == IrOpcode::kWord32Shr) || |
| (...skipping 345 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1210 MachineOperatorBuilder* MachineOperatorReducer::machine() const { | 1242 MachineOperatorBuilder* MachineOperatorReducer::machine() const { |
| 1211 return jsgraph()->machine(); | 1243 return jsgraph()->machine(); |
| 1212 } | 1244 } |
| 1213 | 1245 |
| 1214 | 1246 |
| 1215 Graph* MachineOperatorReducer::graph() const { return jsgraph()->graph(); } | 1247 Graph* MachineOperatorReducer::graph() const { return jsgraph()->graph(); } |
| 1216 | 1248 |
| 1217 } // namespace compiler | 1249 } // namespace compiler |
| 1218 } // namespace internal | 1250 } // namespace internal |
| 1219 } // namespace v8 | 1251 } // namespace v8 |
| OLD | NEW |