Chromium Code Reviews| 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/generic-node-inl.h" | 10 #include "src/compiler/generic-node-inl.h" |
| (...skipping 582 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 593 if (m.right().Is(1)) return Replace(m.left().node()); // x / 1 => x | 593 if (m.right().Is(1)) return Replace(m.left().node()); // x / 1 => x |
| 594 if (m.IsFoldable()) { // K / K => K | 594 if (m.IsFoldable()) { // K / K => K |
| 595 return ReplaceUint32( | 595 return ReplaceUint32( |
| 596 base::bits::UnsignedDiv32(m.left().Value(), m.right().Value())); | 596 base::bits::UnsignedDiv32(m.left().Value(), m.right().Value())); |
| 597 } | 597 } |
| 598 if (m.LeftEqualsRight()) { // x / x => x != 0 | 598 if (m.LeftEqualsRight()) { // x / x => x != 0 |
| 599 Node* const zero = Int32Constant(0); | 599 Node* const zero = Int32Constant(0); |
| 600 return Replace(Word32Equal(Word32Equal(m.left().node(), zero), zero)); | 600 return Replace(Word32Equal(Word32Equal(m.left().node(), zero), zero)); |
| 601 } | 601 } |
| 602 if (m.right().IsPowerOf2()) { // x / 2^n => x >> n | 602 if (m.right().IsPowerOf2()) { // x / 2^n => x >> n |
| 603 node->ReplaceInput(1, Uint32Constant(WhichPowerOf2(m.right().Value()))); | |
|
Benedikt Meurer
2014/10/29 18:26:45
Let's keep the set_op() before ReplaceInput.
Jarin
2014/10/29 21:12:24
Done.
I am wondering what's the reason for this.
| |
| 604 node->TrimInputCount(2); | |
| 603 node->set_op(machine()->Word32Shr()); | 605 node->set_op(machine()->Word32Shr()); |
| 604 node->ReplaceInput(1, Uint32Constant(WhichPowerOf2(m.right().Value()))); | |
| 605 return Changed(node); | 606 return Changed(node); |
| 606 } | 607 } |
| 607 return NoChange(); | 608 return NoChange(); |
| 608 } | 609 } |
| 609 | 610 |
| 610 | 611 |
| 611 Reduction MachineOperatorReducer::ReduceInt32Mod(Node* node) { | 612 Reduction MachineOperatorReducer::ReduceInt32Mod(Node* node) { |
| 612 Int32BinopMatcher m(node); | 613 Int32BinopMatcher m(node); |
| 613 if (m.left().Is(0)) return Replace(m.left().node()); // 0 % x => 0 | 614 if (m.left().Is(0)) return Replace(m.left().node()); // 0 % x => 0 |
| 614 if (m.right().Is(0)) return Replace(m.right().node()); // x % 0 => 0 | 615 if (m.right().Is(0)) return Replace(m.right().node()); // x % 0 => 0 |
| (...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 658 Uint32BinopMatcher m(node); | 659 Uint32BinopMatcher m(node); |
| 659 if (m.left().Is(0)) return Replace(m.left().node()); // 0 % x => 0 | 660 if (m.left().Is(0)) return Replace(m.left().node()); // 0 % x => 0 |
| 660 if (m.right().Is(0)) return Replace(m.right().node()); // x % 0 => 0 | 661 if (m.right().Is(0)) return Replace(m.right().node()); // x % 0 => 0 |
| 661 if (m.right().Is(1)) return ReplaceUint32(0); // x % 1 => 0 | 662 if (m.right().Is(1)) return ReplaceUint32(0); // x % 1 => 0 |
| 662 if (m.LeftEqualsRight()) return ReplaceInt32(0); // x % x => 0 | 663 if (m.LeftEqualsRight()) return ReplaceInt32(0); // x % x => 0 |
| 663 if (m.IsFoldable()) { // K % K => K | 664 if (m.IsFoldable()) { // K % K => K |
| 664 return ReplaceUint32( | 665 return ReplaceUint32( |
| 665 base::bits::UnsignedMod32(m.left().Value(), m.right().Value())); | 666 base::bits::UnsignedMod32(m.left().Value(), m.right().Value())); |
| 666 } | 667 } |
| 667 if (m.right().IsPowerOf2()) { // x % 2^n => x & 2^n-1 | 668 if (m.right().IsPowerOf2()) { // x % 2^n => x & 2^n-1 |
| 669 node->ReplaceInput(1, Uint32Constant(m.right().Value() - 1)); | |
| 670 node->TrimInputCount(2); | |
| 668 node->set_op(machine()->Word32And()); | 671 node->set_op(machine()->Word32And()); |
|
Benedikt Meurer
2014/10/29 18:26:45
Same here.
Jarin
2014/10/29 21:12:24
Done.
| |
| 669 node->ReplaceInput(1, Uint32Constant(m.right().Value() - 1)); | |
| 670 return Changed(node); | 672 return Changed(node); |
| 671 } | 673 } |
| 672 return NoChange(); | 674 return NoChange(); |
| 673 } | 675 } |
| 674 | 676 |
| 675 | 677 |
| 676 Reduction MachineOperatorReducer::ReduceProjection(size_t index, Node* node) { | 678 Reduction MachineOperatorReducer::ReduceProjection(size_t index, Node* node) { |
| 677 switch (node->opcode()) { | 679 switch (node->opcode()) { |
| 678 case IrOpcode::kInt32AddWithOverflow: { | 680 case IrOpcode::kInt32AddWithOverflow: { |
| 679 DCHECK(index == 0 || index == 1); | 681 DCHECK(index == 0 || index == 1); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 718 MachineOperatorBuilder* MachineOperatorReducer::machine() const { | 720 MachineOperatorBuilder* MachineOperatorReducer::machine() const { |
| 719 return jsgraph()->machine(); | 721 return jsgraph()->machine(); |
| 720 } | 722 } |
| 721 | 723 |
| 722 | 724 |
| 723 Graph* MachineOperatorReducer::graph() const { return jsgraph()->graph(); } | 725 Graph* MachineOperatorReducer::graph() const { return jsgraph()->graph(); } |
| 724 | 726 |
| 725 } // namespace compiler | 727 } // namespace compiler |
| 726 } // namespace internal | 728 } // namespace internal |
| 727 } // namespace v8 | 729 } // namespace v8 |
| OLD | NEW |