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

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

Issue 684193002: [turbofan] Fix input count in Uint32Mod/Div reduction. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: Change order of node transformation. 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 | « no previous file | test/cctest/compiler/test-machine-operator-reducer.cc » ('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 582 matching lines...) Expand 10 before | Expand all | Expand 10 after
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->TrimInputCount(2);
603 node->set_op(machine()->Word32Shr()); 604 node->set_op(machine()->Word32Shr());
604 node->ReplaceInput(1, Uint32Constant(WhichPowerOf2(m.right().Value()))); 605 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);
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
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->TrimInputCount(2);
668 node->set_op(machine()->Word32And()); 670 node->set_op(machine()->Word32And());
669 node->ReplaceInput(1, Uint32Constant(m.right().Value() - 1)); 671 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()) {
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
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
OLDNEW
« no previous file with comments | « no previous file | test/cctest/compiler/test-machine-operator-reducer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698