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

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

Issue 698963002: [turbofan] Strip useless sign-extension for store8/store16. (Closed) Base URL: https://v8.googlecode.com/svn/branches/bleeding_edge
Patch Set: 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
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 516 matching lines...) Expand 10 before | Expand all | Expand 10 after
527 if (m.HasValue()) return ReplaceInt32(static_cast<int32_t>(m.Value())); 527 if (m.HasValue()) return ReplaceInt32(static_cast<int32_t>(m.Value()));
528 if (m.IsChangeInt32ToInt64()) return Replace(m.node()->InputAt(0)); 528 if (m.IsChangeInt32ToInt64()) return Replace(m.node()->InputAt(0));
529 break; 529 break;
530 } 530 }
531 case IrOpcode::kTruncateFloat64ToFloat32: { 531 case IrOpcode::kTruncateFloat64ToFloat32: {
532 Float64Matcher m(node->InputAt(0)); 532 Float64Matcher m(node->InputAt(0));
533 if (m.HasValue()) return ReplaceFloat32(DoubleToFloat32(m.Value())); 533 if (m.HasValue()) return ReplaceFloat32(DoubleToFloat32(m.Value()));
534 if (m.IsChangeFloat32ToFloat64()) return Replace(m.node()->InputAt(0)); 534 if (m.IsChangeFloat32ToFloat64()) return Replace(m.node()->InputAt(0));
535 break; 535 break;
536 } 536 }
537 case IrOpcode::kStore: { 537 case IrOpcode::kStore:
538 Node* const value = node->InputAt(2); 538 return ReduceStore(node);
539 // TODO(turbofan): Extend to 64-bit?
540 if (value->opcode() == IrOpcode::kWord32And) {
541 MachineType const rep = static_cast<MachineType>(
542 StoreRepresentationOf(node->op()).machine_type() & kRepMask);
543 Uint32BinopMatcher m(value);
544 if (m.right().HasValue() &&
545 ((rep == kRepWord8 && (m.right().Value() & 0xff) == 0xff) ||
546 (rep == kRepWord16 && (m.right().Value() & 0xffff) == 0xffff))) {
547 node->ReplaceInput(2, m.left().node());
548 return Changed(node);
549 }
550 }
551 break;
552 }
553 default: 539 default:
554 break; 540 break;
555 } 541 }
556 return NoChange(); 542 return NoChange();
557 } 543 }
558 544
559 545
560 Reduction MachineOperatorReducer::ReduceInt32Div(Node* node) { 546 Reduction MachineOperatorReducer::ReduceInt32Div(Node* node) {
561 Int32BinopMatcher m(node); 547 Int32BinopMatcher m(node);
562 if (m.left().Is(0)) return Replace(m.left().node()); // 0 / x => 0 548 if (m.left().Is(0)) return Replace(m.left().node()); // 0 / x => 0
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after
705 DCHECK_EQ(dividend, node->InputAt(0)); 691 DCHECK_EQ(dividend, node->InputAt(0));
706 node->ReplaceInput(1, Int32Mul(quotient, Uint32Constant(divisor))); 692 node->ReplaceInput(1, Int32Mul(quotient, Uint32Constant(divisor)));
707 } 693 }
708 node->TrimInputCount(2); 694 node->TrimInputCount(2);
709 return Changed(node); 695 return Changed(node);
710 } 696 }
711 return NoChange(); 697 return NoChange();
712 } 698 }
713 699
714 700
701 Reduction MachineOperatorReducer::ReduceStore(Node* node) {
702 MachineType const rep =
703 RepresentationOf(StoreRepresentationOf(node->op()).machine_type());
704 Node* const value = node->InputAt(2);
705 switch (value->opcode()) {
706 case IrOpcode::kWord32And: {
707 Uint32BinopMatcher m(value);
708 if (m.right().HasValue() &&
709 ((rep == kRepWord8 && (m.right().Value() & 0xff) == 0xff) ||
710 (rep == kRepWord16 && (m.right().Value() & 0xffff) == 0xffff))) {
711 node->ReplaceInput(2, m.left().node());
712 return Changed(node);
713 }
714 break;
715 }
716 case IrOpcode::kWord32Sar: {
717 Int32BinopMatcher m(value);
718 if (m.left().IsWord32Shl() &&
719 ((rep == kRepWord8 && m.right().IsInRange(1, 24)) ||
720 (rep == kRepWord16 && m.right().IsInRange(1, 16)))) {
721 Int32BinopMatcher mleft(m.left().node());
722 if (mleft.right().Is(m.right().Value())) {
723 node->ReplaceInput(2, mleft.left().node());
724 return Changed(node);
725 }
726 }
727 break;
728 }
729 default:
730 break;
731 }
732 return NoChange();
733 }
734
735
715 Reduction MachineOperatorReducer::ReduceProjection(size_t index, Node* node) { 736 Reduction MachineOperatorReducer::ReduceProjection(size_t index, Node* node) {
716 switch (node->opcode()) { 737 switch (node->opcode()) {
717 case IrOpcode::kInt32AddWithOverflow: { 738 case IrOpcode::kInt32AddWithOverflow: {
718 DCHECK(index == 0 || index == 1); 739 DCHECK(index == 0 || index == 1);
719 Int32BinopMatcher m(node); 740 Int32BinopMatcher m(node);
720 if (m.IsFoldable()) { 741 if (m.IsFoldable()) {
721 int32_t val; 742 int32_t val;
722 bool ovf = base::bits::SignedAddOverflow32(m.left().Value(), 743 bool ovf = base::bits::SignedAddOverflow32(m.left().Value(),
723 m.right().Value(), &val); 744 m.right().Value(), &val);
724 return ReplaceInt32((index == 0) ? val : ovf); 745 return ReplaceInt32((index == 0) ? val : ovf);
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
757 MachineOperatorBuilder* MachineOperatorReducer::machine() const { 778 MachineOperatorBuilder* MachineOperatorReducer::machine() const {
758 return jsgraph()->machine(); 779 return jsgraph()->machine();
759 } 780 }
760 781
761 782
762 Graph* MachineOperatorReducer::graph() const { return jsgraph()->graph(); } 783 Graph* MachineOperatorReducer::graph() const { return jsgraph()->graph(); }
763 784
764 } // namespace compiler 785 } // namespace compiler
765 } // namespace internal 786 } // namespace internal
766 } // namespace v8 787 } // namespace v8
OLDNEW
« no previous file with comments | « src/compiler/machine-operator-reducer.h ('k') | test/unittests/compiler/machine-operator-reducer-unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698