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 21 matching lines...) Expand all Loading... |
32 | 32 |
33 | 33 |
34 Node* MachineOperatorReducer::Int64Constant(int64_t value) { | 34 Node* MachineOperatorReducer::Int64Constant(int64_t value) { |
35 return graph()->NewNode(common()->Int64Constant(value)); | 35 return graph()->NewNode(common()->Int64Constant(value)); |
36 } | 36 } |
37 | 37 |
38 | 38 |
39 // Perform constant folding and strength reduction on machine operators. | 39 // Perform constant folding and strength reduction on machine operators. |
40 Reduction MachineOperatorReducer::Reduce(Node* node) { | 40 Reduction MachineOperatorReducer::Reduce(Node* node) { |
41 switch (node->opcode()) { | 41 switch (node->opcode()) { |
| 42 case IrOpcode::kProjection: |
| 43 return ReduceProjection(OpParameter<size_t>(node), node->InputAt(0)); |
42 case IrOpcode::kWord32And: { | 44 case IrOpcode::kWord32And: { |
43 Int32BinopMatcher m(node); | 45 Int32BinopMatcher m(node); |
44 if (m.right().Is(0)) return Replace(m.right().node()); // x & 0 => 0 | 46 if (m.right().Is(0)) return Replace(m.right().node()); // x & 0 => 0 |
45 if (m.right().Is(-1)) return Replace(m.left().node()); // x & -1 => x | 47 if (m.right().Is(-1)) return Replace(m.left().node()); // x & -1 => x |
46 if (m.IsFoldable()) { // K & K => K | 48 if (m.IsFoldable()) { // K & K => K |
47 return ReplaceInt32(m.left().Value() & m.right().Value()); | 49 return ReplaceInt32(m.left().Value() & m.right().Value()); |
48 } | 50 } |
49 if (m.LeftEqualsRight()) return Replace(m.left().node()); // x & x => x | 51 if (m.LeftEqualsRight()) return Replace(m.left().node()); // x & x => x |
50 break; | 52 break; |
51 } | 53 } |
(...skipping 374 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
426 break; | 428 break; |
427 } | 429 } |
428 // TODO(turbofan): strength-reduce and fold floating point operations. | 430 // TODO(turbofan): strength-reduce and fold floating point operations. |
429 default: | 431 default: |
430 break; | 432 break; |
431 } | 433 } |
432 return NoChange(); | 434 return NoChange(); |
433 } | 435 } |
434 | 436 |
435 | 437 |
| 438 Reduction MachineOperatorReducer::ReduceProjection(size_t index, Node* node) { |
| 439 switch (node->opcode()) { |
| 440 case IrOpcode::kInt32AddWithOverflow: { |
| 441 DCHECK(index == 0 || index == 1); |
| 442 Int32BinopMatcher m(node); |
| 443 if (m.IsFoldable()) { |
| 444 int32_t val; |
| 445 bool ovf = base::bits::SignedAddOverflow32(m.left().Value(), |
| 446 m.right().Value(), &val); |
| 447 return ReplaceInt32((index == 0) ? val : ovf); |
| 448 } |
| 449 if (m.right().Is(0)) { |
| 450 return (index == 0) ? Replace(m.left().node()) : ReplaceInt32(0); |
| 451 } |
| 452 break; |
| 453 } |
| 454 case IrOpcode::kInt32SubWithOverflow: { |
| 455 DCHECK(index == 0 || index == 1); |
| 456 Int32BinopMatcher m(node); |
| 457 if (m.IsFoldable()) { |
| 458 int32_t val; |
| 459 bool ovf = base::bits::SignedSubOverflow32(m.left().Value(), |
| 460 m.right().Value(), &val); |
| 461 return ReplaceInt32((index == 0) ? val : ovf); |
| 462 } |
| 463 if (m.right().Is(0)) { |
| 464 return (index == 0) ? Replace(m.left().node()) : ReplaceInt32(0); |
| 465 } |
| 466 break; |
| 467 } |
| 468 default: |
| 469 break; |
| 470 } |
| 471 return NoChange(); |
| 472 } |
| 473 |
| 474 |
436 CommonOperatorBuilder* MachineOperatorReducer::common() const { | 475 CommonOperatorBuilder* MachineOperatorReducer::common() const { |
437 return jsgraph()->common(); | 476 return jsgraph()->common(); |
438 } | 477 } |
439 | 478 |
440 | 479 |
441 Graph* MachineOperatorReducer::graph() const { return jsgraph()->graph(); } | 480 Graph* MachineOperatorReducer::graph() const { return jsgraph()->graph(); } |
442 | 481 |
443 } // namespace compiler | 482 } // namespace compiler |
444 } // namespace internal | 483 } // namespace internal |
445 } // namespace v8 | 484 } // namespace v8 |
OLD | NEW |