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 926 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
937 Reduction MachineOperatorReducer::ReduceWord32Or(Node* node) { | 937 Reduction MachineOperatorReducer::ReduceWord32Or(Node* node) { |
938 DCHECK_EQ(IrOpcode::kWord32Or, node->opcode()); | 938 DCHECK_EQ(IrOpcode::kWord32Or, node->opcode()); |
939 Int32BinopMatcher m(node); | 939 Int32BinopMatcher m(node); |
940 if (m.right().Is(0)) return Replace(m.left().node()); // x | 0 => x | 940 if (m.right().Is(0)) return Replace(m.left().node()); // x | 0 => x |
941 if (m.right().Is(-1)) return Replace(m.right().node()); // x | -1 => -1 | 941 if (m.right().Is(-1)) return Replace(m.right().node()); // x | -1 => -1 |
942 if (m.IsFoldable()) { // K | K => K | 942 if (m.IsFoldable()) { // K | K => K |
943 return ReplaceInt32(m.left().Value() | m.right().Value()); | 943 return ReplaceInt32(m.left().Value() | m.right().Value()); |
944 } | 944 } |
945 if (m.LeftEqualsRight()) return Replace(m.left().node()); // x | x => x | 945 if (m.LeftEqualsRight()) return Replace(m.left().node()); // x | x => x |
946 | 946 |
947 Node* shl = NULL; | 947 Node* shl = nullptr; |
948 Node* shr = NULL; | 948 Node* shr = nullptr; |
949 // Recognize rotation, we are matching either: | 949 // Recognize rotation, we are matching either: |
950 // * x << y | x >>> (32 - y) => x ror (32 - y), i.e x rol y | 950 // * x << y | x >>> (32 - y) => x ror (32 - y), i.e x rol y |
951 // * x << (32 - y) | x >>> y => x ror y | 951 // * x << (32 - y) | x >>> y => x ror y |
952 // as well as their commuted form. | 952 // as well as their commuted form. |
953 if (m.left().IsWord32Shl() && m.right().IsWord32Shr()) { | 953 if (m.left().IsWord32Shl() && m.right().IsWord32Shr()) { |
954 shl = m.left().node(); | 954 shl = m.left().node(); |
955 shr = m.right().node(); | 955 shr = m.right().node(); |
956 } else if (m.left().IsWord32Shr() && m.right().IsWord32Shl()) { | 956 } else if (m.left().IsWord32Shr() && m.right().IsWord32Shl()) { |
957 shl = m.right().node(); | 957 shl = m.right().node(); |
958 shr = m.left().node(); | 958 shr = m.left().node(); |
959 } else { | 959 } else { |
960 return NoChange(); | 960 return NoChange(); |
961 } | 961 } |
962 | 962 |
963 Int32BinopMatcher mshl(shl); | 963 Int32BinopMatcher mshl(shl); |
964 Int32BinopMatcher mshr(shr); | 964 Int32BinopMatcher mshr(shr); |
965 if (mshl.left().node() != mshr.left().node()) return NoChange(); | 965 if (mshl.left().node() != mshr.left().node()) return NoChange(); |
966 | 966 |
967 if (mshl.right().HasValue() && mshr.right().HasValue()) { | 967 if (mshl.right().HasValue() && mshr.right().HasValue()) { |
968 // Case where y is a constant. | 968 // Case where y is a constant. |
969 if (mshl.right().Value() + mshr.right().Value() != 32) return NoChange(); | 969 if (mshl.right().Value() + mshr.right().Value() != 32) return NoChange(); |
970 } else { | 970 } else { |
971 Node* sub = NULL; | 971 Node* sub = nullptr; |
972 Node* y = NULL; | 972 Node* y = nullptr; |
973 if (mshl.right().IsInt32Sub()) { | 973 if (mshl.right().IsInt32Sub()) { |
974 sub = mshl.right().node(); | 974 sub = mshl.right().node(); |
975 y = mshr.right().node(); | 975 y = mshr.right().node(); |
976 } else if (mshr.right().IsInt32Sub()) { | 976 } else if (mshr.right().IsInt32Sub()) { |
977 sub = mshr.right().node(); | 977 sub = mshr.right().node(); |
978 y = mshl.right().node(); | 978 y = mshl.right().node(); |
979 } else { | 979 } else { |
980 return NoChange(); | 980 return NoChange(); |
981 } | 981 } |
982 | 982 |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1082 MachineOperatorBuilder* MachineOperatorReducer::machine() const { | 1082 MachineOperatorBuilder* MachineOperatorReducer::machine() const { |
1083 return jsgraph()->machine(); | 1083 return jsgraph()->machine(); |
1084 } | 1084 } |
1085 | 1085 |
1086 | 1086 |
1087 Graph* MachineOperatorReducer::graph() const { return jsgraph()->graph(); } | 1087 Graph* MachineOperatorReducer::graph() const { return jsgraph()->graph(); } |
1088 | 1088 |
1089 } // namespace compiler | 1089 } // namespace compiler |
1090 } // namespace internal | 1090 } // namespace internal |
1091 } // namespace v8 | 1091 } // namespace v8 |
OLD | NEW |