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/compiler/generic-node-inl.h" | 8 #include "src/compiler/generic-node-inl.h" |
9 #include "src/compiler/graph.h" | 9 #include "src/compiler/graph.h" |
10 #include "src/compiler/js-graph.h" | 10 #include "src/compiler/js-graph.h" |
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
124 } | 124 } |
125 if (m.LeftEqualsRight()) return ReplaceInt32(0); // x ^ x => 0 | 125 if (m.LeftEqualsRight()) return ReplaceInt32(0); // x ^ x => 0 |
126 break; | 126 break; |
127 } | 127 } |
128 case IrOpcode::kWord32Shl: { | 128 case IrOpcode::kWord32Shl: { |
129 Int32BinopMatcher m(node); | 129 Int32BinopMatcher m(node); |
130 if (m.right().Is(0)) return Replace(m.left().node()); // x << 0 => x | 130 if (m.right().Is(0)) return Replace(m.left().node()); // x << 0 => x |
131 if (m.IsFoldable()) { // K << K => K | 131 if (m.IsFoldable()) { // K << K => K |
132 return ReplaceInt32(m.left().Value() << m.right().Value()); | 132 return ReplaceInt32(m.left().Value() << m.right().Value()); |
133 } | 133 } |
| 134 if (m.right().IsInRange(1, 31)) { |
| 135 // (x >>> K) << K => x & ~(2^K - 1) |
| 136 // (x >> K) << K => x & ~(2^K - 1) |
| 137 if (m.left().IsWord32Sar() || m.left().IsWord32Shr()) { |
| 138 Int32BinopMatcher mleft(m.left().node()); |
| 139 if (mleft.right().Is(m.right().Value())) { |
| 140 node->set_op(machine()->Word32And()); |
| 141 node->ReplaceInput(0, mleft.left().node()); |
| 142 node->ReplaceInput( |
| 143 1, Uint32Constant(~((1U << m.right().Value()) - 1U))); |
| 144 return Changed(node); |
| 145 } |
| 146 } |
| 147 } |
134 break; | 148 break; |
135 } | 149 } |
136 case IrOpcode::kWord32Shr: { | 150 case IrOpcode::kWord32Shr: { |
137 Uint32BinopMatcher m(node); | 151 Uint32BinopMatcher m(node); |
138 if (m.right().Is(0)) return Replace(m.left().node()); // x >>> 0 => x | 152 if (m.right().Is(0)) return Replace(m.left().node()); // x >>> 0 => x |
139 if (m.IsFoldable()) { // K >>> K => K | 153 if (m.IsFoldable()) { // K >>> K => K |
140 return ReplaceInt32(m.left().Value() >> m.right().Value()); | 154 return ReplaceInt32(m.left().Value() >> m.right().Value()); |
141 } | 155 } |
142 break; | 156 break; |
143 } | 157 } |
(...skipping 351 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
495 MachineOperatorBuilder* MachineOperatorReducer::machine() const { | 509 MachineOperatorBuilder* MachineOperatorReducer::machine() const { |
496 return jsgraph()->machine(); | 510 return jsgraph()->machine(); |
497 } | 511 } |
498 | 512 |
499 | 513 |
500 Graph* MachineOperatorReducer::graph() const { return jsgraph()->graph(); } | 514 Graph* MachineOperatorReducer::graph() const { return jsgraph()->graph(); } |
501 | 515 |
502 } // namespace compiler | 516 } // namespace compiler |
503 } // namespace internal | 517 } // namespace internal |
504 } // namespace v8 | 518 } // namespace v8 |
OLD | NEW |