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/codegen.h" | 8 #include "src/codegen.h" |
9 #include "src/compiler/generic-node-inl.h" | 9 #include "src/compiler/generic-node-inl.h" |
10 #include "src/compiler/graph.h" | 10 #include "src/compiler/graph.h" |
(...skipping 228 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 return ReplaceInt32(m.left().Value() / m.right().Value()); | 239 return ReplaceInt32(m.left().Value() / m.right().Value()); |
240 } | 240 } |
241 if (m.right().Is(-1)) { // x / -1 => 0 - x | 241 if (m.right().Is(-1)) { // x / -1 => 0 - x |
242 node->set_op(machine()->Int32Sub()); | 242 node->set_op(machine()->Int32Sub()); |
243 node->ReplaceInput(0, Int32Constant(0)); | 243 node->ReplaceInput(0, Int32Constant(0)); |
244 node->ReplaceInput(1, m.left().node()); | 244 node->ReplaceInput(1, m.left().node()); |
245 return Changed(node); | 245 return Changed(node); |
246 } | 246 } |
247 break; | 247 break; |
248 } | 248 } |
249 case IrOpcode::kInt32UDiv: { | 249 case IrOpcode::kUint32Div: { |
250 Uint32BinopMatcher m(node); | 250 Uint32BinopMatcher m(node); |
251 if (m.right().Is(1)) return Replace(m.left().node()); // x / 1 => x | 251 if (m.right().Is(1)) return Replace(m.left().node()); // x / 1 => x |
252 // TODO(turbofan): if (m.left().Is(0)) | 252 // TODO(turbofan): if (m.left().Is(0)) |
253 // TODO(turbofan): if (m.right().Is(0)) | 253 // TODO(turbofan): if (m.right().Is(0)) |
254 // TODO(turbofan): if (m.LeftEqualsRight()) | 254 // TODO(turbofan): if (m.LeftEqualsRight()) |
255 if (m.IsFoldable() && !m.right().Is(0)) { // K / K => K | 255 if (m.IsFoldable() && !m.right().Is(0)) { // K / K => K |
256 return ReplaceInt32(m.left().Value() / m.right().Value()); | 256 return ReplaceInt32(m.left().Value() / m.right().Value()); |
257 } | 257 } |
258 if (m.right().IsPowerOf2()) { // x / 2^n => x >> n | 258 if (m.right().IsPowerOf2()) { // x / 2^n => x >> n |
259 node->set_op(machine()->Word32Shr()); | 259 node->set_op(machine()->Word32Shr()); |
260 node->ReplaceInput(1, Int32Constant(WhichPowerOf2(m.right().Value()))); | 260 node->ReplaceInput(1, Int32Constant(WhichPowerOf2(m.right().Value()))); |
261 return Changed(node); | 261 return Changed(node); |
262 } | 262 } |
263 break; | 263 break; |
264 } | 264 } |
265 case IrOpcode::kInt32Mod: { | 265 case IrOpcode::kInt32Mod: { |
266 Int32BinopMatcher m(node); | 266 Int32BinopMatcher m(node); |
267 if (m.right().Is(1)) return ReplaceInt32(0); // x % 1 => 0 | 267 if (m.right().Is(1)) return ReplaceInt32(0); // x % 1 => 0 |
268 if (m.right().Is(-1)) return ReplaceInt32(0); // x % -1 => 0 | 268 if (m.right().Is(-1)) return ReplaceInt32(0); // x % -1 => 0 |
269 // TODO(turbofan): if (m.left().Is(0)) | 269 // TODO(turbofan): if (m.left().Is(0)) |
270 // TODO(turbofan): if (m.right().IsPowerOf2()) | 270 // TODO(turbofan): if (m.right().IsPowerOf2()) |
271 // TODO(turbofan): if (m.right().Is(0)) | 271 // TODO(turbofan): if (m.right().Is(0)) |
272 // TODO(turbofan): if (m.LeftEqualsRight()) | 272 // TODO(turbofan): if (m.LeftEqualsRight()) |
273 if (m.IsFoldable() && !m.right().Is(0)) { // K % K => K | 273 if (m.IsFoldable() && !m.right().Is(0)) { // K % K => K |
274 return ReplaceInt32(m.left().Value() % m.right().Value()); | 274 return ReplaceInt32(m.left().Value() % m.right().Value()); |
275 } | 275 } |
276 break; | 276 break; |
277 } | 277 } |
278 case IrOpcode::kInt32UMod: { | 278 case IrOpcode::kUint32Mod: { |
279 Uint32BinopMatcher m(node); | 279 Uint32BinopMatcher m(node); |
280 if (m.right().Is(1)) return ReplaceInt32(0); // x % 1 => 0 | 280 if (m.right().Is(1)) return ReplaceInt32(0); // x % 1 => 0 |
281 // TODO(turbofan): if (m.left().Is(0)) | 281 // TODO(turbofan): if (m.left().Is(0)) |
282 // TODO(turbofan): if (m.right().Is(0)) | 282 // TODO(turbofan): if (m.right().Is(0)) |
283 // TODO(turbofan): if (m.LeftEqualsRight()) | 283 // TODO(turbofan): if (m.LeftEqualsRight()) |
284 if (m.IsFoldable() && !m.right().Is(0)) { // K % K => K | 284 if (m.IsFoldable() && !m.right().Is(0)) { // K % K => K |
285 return ReplaceInt32(m.left().Value() % m.right().Value()); | 285 return ReplaceInt32(m.left().Value() % m.right().Value()); |
286 } | 286 } |
287 if (m.right().IsPowerOf2()) { // x % 2^n => x & 2^n-1 | 287 if (m.right().IsPowerOf2()) { // x % 2^n => x & 2^n-1 |
288 node->set_op(machine()->Word32And()); | 288 node->set_op(machine()->Word32And()); |
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
525 MachineOperatorBuilder* MachineOperatorReducer::machine() const { | 525 MachineOperatorBuilder* MachineOperatorReducer::machine() const { |
526 return jsgraph()->machine(); | 526 return jsgraph()->machine(); |
527 } | 527 } |
528 | 528 |
529 | 529 |
530 Graph* MachineOperatorReducer::graph() const { return jsgraph()->graph(); } | 530 Graph* MachineOperatorReducer::graph() const { return jsgraph()->graph(); } |
531 | 531 |
532 } // namespace compiler | 532 } // namespace compiler |
533 } // namespace internal | 533 } // namespace internal |
534 } // namespace v8 | 534 } // namespace v8 |
OLD | NEW |