| 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 620 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 631 if (m.IsFoldable()) { // K % K => K | 631 if (m.IsFoldable()) { // K % K => K |
| 632 return ReplaceInt32( | 632 return ReplaceInt32( |
| 633 base::bits::SignedMod32(m.left().Value(), m.right().Value())); | 633 base::bits::SignedMod32(m.left().Value(), m.right().Value())); |
| 634 } | 634 } |
| 635 if (m.right().HasValue()) { | 635 if (m.right().HasValue()) { |
| 636 Node* const dividend = m.left().node(); | 636 Node* const dividend = m.left().node(); |
| 637 int32_t const divisor = Abs(m.right().Value()); | 637 int32_t const divisor = Abs(m.right().Value()); |
| 638 if (base::bits::IsPowerOfTwo32(divisor)) { | 638 if (base::bits::IsPowerOfTwo32(divisor)) { |
| 639 uint32_t const mask = divisor - 1; | 639 uint32_t const mask = divisor - 1; |
| 640 Node* const zero = Int32Constant(0); | 640 Node* const zero = Int32Constant(0); |
| 641 | 641 node->set_op(common()->Select(kMachInt32, BranchHint::kFalse)); |
| 642 Node* check = | 642 node->ReplaceInput( |
| 643 graph()->NewNode(machine()->Int32LessThan(), dividend, zero); | 643 0, graph()->NewNode(machine()->Int32LessThan(), dividend, zero)); |
| 644 Diamond d(graph(), common(), check, BranchHint::kFalse); | 644 node->ReplaceInput( |
| 645 Node* neg = Int32Sub(zero, Word32And(Int32Sub(zero, dividend), mask)); | 645 1, Int32Sub(zero, Word32And(Int32Sub(zero, dividend), mask))); |
| 646 Node* pos = Word32And(dividend, mask); | 646 node->ReplaceInput(2, Word32And(dividend, mask)); |
| 647 d.OverwriteWithPhi(node, kMachInt32, neg, pos); | |
| 648 } else { | 647 } else { |
| 649 Node* quotient = Int32Div(dividend, divisor); | 648 Node* quotient = Int32Div(dividend, divisor); |
| 650 node->set_op(machine()->Int32Sub()); | 649 node->set_op(machine()->Int32Sub()); |
| 651 DCHECK_EQ(dividend, node->InputAt(0)); | 650 DCHECK_EQ(dividend, node->InputAt(0)); |
| 652 node->ReplaceInput(1, Int32Mul(quotient, Int32Constant(divisor))); | 651 node->ReplaceInput(1, Int32Mul(quotient, Int32Constant(divisor))); |
| 653 node->TrimInputCount(2); | 652 node->TrimInputCount(2); |
| 654 } | 653 } |
| 655 return Changed(node); | 654 return Changed(node); |
| 656 } | 655 } |
| 657 return NoChange(); | 656 return NoChange(); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 767 MachineOperatorBuilder* MachineOperatorReducer::machine() const { | 766 MachineOperatorBuilder* MachineOperatorReducer::machine() const { |
| 768 return jsgraph()->machine(); | 767 return jsgraph()->machine(); |
| 769 } | 768 } |
| 770 | 769 |
| 771 | 770 |
| 772 Graph* MachineOperatorReducer::graph() const { return jsgraph()->graph(); } | 771 Graph* MachineOperatorReducer::graph() const { return jsgraph()->graph(); } |
| 773 | 772 |
| 774 } // namespace compiler | 773 } // namespace compiler |
| 775 } // namespace internal | 774 } // namespace internal |
| 776 } // namespace v8 | 775 } // namespace v8 |
| OLD | NEW |