| 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/generic-node-inl.h" | 11 #include "src/compiler/generic-node-inl.h" |
| 11 #include "src/compiler/graph.h" | 12 #include "src/compiler/graph.h" |
| 12 #include "src/compiler/js-graph.h" | 13 #include "src/compiler/js-graph.h" |
| 13 #include "src/compiler/node-matchers.h" | 14 #include "src/compiler/node-matchers.h" |
| 14 | 15 |
| 15 namespace v8 { | 16 namespace v8 { |
| 16 namespace internal { | 17 namespace internal { |
| 17 namespace compiler { | 18 namespace compiler { |
| 18 | 19 |
| 19 MachineOperatorReducer::MachineOperatorReducer(JSGraph* jsgraph) | 20 MachineOperatorReducer::MachineOperatorReducer(JSGraph* jsgraph) |
| (...skipping 613 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 633 } | 634 } |
| 634 if (m.right().HasValue()) { | 635 if (m.right().HasValue()) { |
| 635 Node* const dividend = m.left().node(); | 636 Node* const dividend = m.left().node(); |
| 636 int32_t const divisor = Abs(m.right().Value()); | 637 int32_t const divisor = Abs(m.right().Value()); |
| 637 if (base::bits::IsPowerOfTwo32(divisor)) { | 638 if (base::bits::IsPowerOfTwo32(divisor)) { |
| 638 uint32_t const mask = divisor - 1; | 639 uint32_t const mask = divisor - 1; |
| 639 Node* const zero = Int32Constant(0); | 640 Node* const zero = Int32Constant(0); |
| 640 | 641 |
| 641 Node* check = | 642 Node* check = |
| 642 graph()->NewNode(machine()->Int32LessThan(), dividend, zero); | 643 graph()->NewNode(machine()->Int32LessThan(), dividend, zero); |
| 643 Node* branch = graph()->NewNode(common()->Branch(BranchHint::kFalse), | 644 Diamond d(graph(), common(), check, BranchHint::kFalse); |
| 644 check, graph()->start()); | |
| 645 | |
| 646 Node* if_true = graph()->NewNode(common()->IfTrue(), branch); | |
| 647 Node* neg = Int32Sub(zero, Word32And(Int32Sub(zero, dividend), mask)); | 645 Node* neg = Int32Sub(zero, Word32And(Int32Sub(zero, dividend), mask)); |
| 648 | |
| 649 Node* if_false = graph()->NewNode(common()->IfFalse(), branch); | |
| 650 Node* pos = Word32And(dividend, mask); | 646 Node* pos = Word32And(dividend, mask); |
| 651 | 647 d.OverwriteWithPhi(node, kMachInt32, neg, pos); |
| 652 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); | |
| 653 | |
| 654 DCHECK_EQ(3, node->InputCount()); | |
| 655 node->set_op(common()->Phi(kMachInt32, 2)); | |
| 656 node->ReplaceInput(0, neg); | |
| 657 node->ReplaceInput(1, pos); | |
| 658 node->ReplaceInput(2, merge); | |
| 659 } else { | 648 } else { |
| 660 Node* quotient = Int32Div(dividend, divisor); | 649 Node* quotient = Int32Div(dividend, divisor); |
| 661 node->set_op(machine()->Int32Sub()); | 650 node->set_op(machine()->Int32Sub()); |
| 662 DCHECK_EQ(dividend, node->InputAt(0)); | 651 DCHECK_EQ(dividend, node->InputAt(0)); |
| 663 node->ReplaceInput(1, Int32Mul(quotient, Int32Constant(divisor))); | 652 node->ReplaceInput(1, Int32Mul(quotient, Int32Constant(divisor))); |
| 664 node->TrimInputCount(2); | 653 node->TrimInputCount(2); |
| 665 } | 654 } |
| 666 return Changed(node); | 655 return Changed(node); |
| 667 } | 656 } |
| 668 return NoChange(); | 657 return NoChange(); |
| (...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 778 MachineOperatorBuilder* MachineOperatorReducer::machine() const { | 767 MachineOperatorBuilder* MachineOperatorReducer::machine() const { |
| 779 return jsgraph()->machine(); | 768 return jsgraph()->machine(); |
| 780 } | 769 } |
| 781 | 770 |
| 782 | 771 |
| 783 Graph* MachineOperatorReducer::graph() const { return jsgraph()->graph(); } | 772 Graph* MachineOperatorReducer::graph() const { return jsgraph()->graph(); } |
| 784 | 773 |
| 785 } // namespace compiler | 774 } // namespace compiler |
| 786 } // namespace internal | 775 } // namespace internal |
| 787 } // namespace v8 | 776 } // namespace v8 |
| OLD | NEW |