Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(492)

Side by Side Diff: src/compiler/machine-operator-reducer.cc

Issue 681133004: [turbofan] Complete support for integer division/modulus in simplified lowering. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Fixes Created 6 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « src/compiler/machine-operator.h ('k') | src/compiler/node-matchers.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 537 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 base::bits::SignedDiv32(m.left().Value(), m.right().Value())); 548 base::bits::SignedDiv32(m.left().Value(), m.right().Value()));
549 } 549 }
550 if (m.LeftEqualsRight()) { // x / x => x != 0 550 if (m.LeftEqualsRight()) { // x / x => x != 0
551 Node* const zero = Int32Constant(0); 551 Node* const zero = Int32Constant(0);
552 return Replace(Word32Equal(Word32Equal(m.left().node(), zero), zero)); 552 return Replace(Word32Equal(Word32Equal(m.left().node(), zero), zero));
553 } 553 }
554 if (m.right().Is(-1)) { // x / -1 => 0 - x 554 if (m.right().Is(-1)) { // x / -1 => 0 - x
555 node->set_op(machine()->Int32Sub()); 555 node->set_op(machine()->Int32Sub());
556 node->ReplaceInput(0, Int32Constant(0)); 556 node->ReplaceInput(0, Int32Constant(0));
557 node->ReplaceInput(1, m.left().node()); 557 node->ReplaceInput(1, m.left().node());
558 node->TrimInputCount(2);
558 return Changed(node); 559 return Changed(node);
559 } 560 }
560 if (m.right().HasValue()) { 561 if (m.right().HasValue()) {
561 int32_t const divisor = m.right().Value(); 562 int32_t const divisor = m.right().Value();
562 Node* const dividend = m.left().node(); 563 Node* const dividend = m.left().node();
563 Node* quotient = dividend; 564 Node* quotient = dividend;
564 if (base::bits::IsPowerOfTwo32(Abs(divisor))) { 565 if (base::bits::IsPowerOfTwo32(Abs(divisor))) {
565 uint32_t const shift = WhichPowerOf2Abs(divisor); 566 uint32_t const shift = WhichPowerOf2Abs(divisor);
566 DCHECK_NE(0, shift); 567 DCHECK_NE(0, shift);
567 if (shift > 1) { 568 if (shift > 1) {
568 quotient = Word32Sar(quotient, 31); 569 quotient = Word32Sar(quotient, 31);
569 } 570 }
570 quotient = Int32Add(Word32Shr(quotient, 32u - shift), dividend); 571 quotient = Int32Add(Word32Shr(quotient, 32u - shift), dividend);
571 quotient = Word32Sar(quotient, shift); 572 quotient = Word32Sar(quotient, shift);
572 } else { 573 } else {
573 quotient = TruncatingDiv(quotient, Abs(divisor)); 574 quotient = TruncatingDiv(quotient, Abs(divisor));
574 } 575 }
575 if (divisor < 0) { 576 if (divisor < 0) {
576 node->set_op(machine()->Int32Sub()); 577 node->set_op(machine()->Int32Sub());
577 node->ReplaceInput(0, Int32Constant(0)); 578 node->ReplaceInput(0, Int32Constant(0));
578 node->ReplaceInput(1, quotient); 579 node->ReplaceInput(1, quotient);
580 node->TrimInputCount(2);
579 return Changed(node); 581 return Changed(node);
580 } 582 }
581 return Replace(quotient); 583 return Replace(quotient);
582 } 584 }
583 return NoChange(); 585 return NoChange();
584 } 586 }
585 587
586 588
587 Reduction MachineOperatorReducer::ReduceUint32Div(Node* node) { 589 Reduction MachineOperatorReducer::ReduceUint32Div(Node* node) {
588 Uint32BinopMatcher m(node); 590 Uint32BinopMatcher m(node);
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
637 639
638 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false); 640 Node* merge = graph()->NewNode(common()->Merge(2), if_true, if_false);
639 Node* phi = 641 Node* phi =
640 graph()->NewNode(common()->Phi(kMachInt32, 2), neg, pos, merge); 642 graph()->NewNode(common()->Phi(kMachInt32, 2), neg, pos, merge);
641 return Replace(phi); 643 return Replace(phi);
642 } else { 644 } else {
643 Node* quotient = TruncatingDiv(dividend, divisor); 645 Node* quotient = TruncatingDiv(dividend, divisor);
644 node->set_op(machine()->Int32Sub()); 646 node->set_op(machine()->Int32Sub());
645 DCHECK_EQ(dividend, node->InputAt(0)); 647 DCHECK_EQ(dividend, node->InputAt(0));
646 node->ReplaceInput(1, Int32Mul(quotient, Int32Constant(divisor))); 648 node->ReplaceInput(1, Int32Mul(quotient, Int32Constant(divisor)));
649 node->TrimInputCount(2);
647 return Changed(node); 650 return Changed(node);
648 } 651 }
649 } 652 }
650 return NoChange(); 653 return NoChange();
651 } 654 }
652 655
653 656
654 Reduction MachineOperatorReducer::ReduceUint32Mod(Node* node) { 657 Reduction MachineOperatorReducer::ReduceUint32Mod(Node* node) {
655 Uint32BinopMatcher m(node); 658 Uint32BinopMatcher m(node);
656 if (m.left().Is(0)) return Replace(m.left().node()); // 0 % x => 0 659 if (m.left().Is(0)) return Replace(m.left().node()); // 0 % x => 0
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
715 MachineOperatorBuilder* MachineOperatorReducer::machine() const { 718 MachineOperatorBuilder* MachineOperatorReducer::machine() const {
716 return jsgraph()->machine(); 719 return jsgraph()->machine();
717 } 720 }
718 721
719 722
720 Graph* MachineOperatorReducer::graph() const { return jsgraph()->graph(); } 723 Graph* MachineOperatorReducer::graph() const { return jsgraph()->graph(); }
721 724
722 } // namespace compiler 725 } // namespace compiler
723 } // namespace internal 726 } // namespace internal
724 } // namespace v8 727 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/machine-operator.h ('k') | src/compiler/node-matchers.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698