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

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

Issue 794473003: Revert of [turbofan] Correctify TruncateFloat64ToInt32 reduction in MachineOperatorReducer. (Closed) Base URL: https://chromium.googlesource.com/v8/v8.git@master
Patch Set: Created 6 years 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
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/diamond.h" 10 #include "src/compiler/diamond.h"
(...skipping 590 matching lines...) Expand 10 before | Expand all | Expand 10 after
601 DCHECK_EQ(dividend, node->InputAt(0)); 601 DCHECK_EQ(dividend, node->InputAt(0));
602 node->ReplaceInput(1, Int32Mul(quotient, Uint32Constant(divisor))); 602 node->ReplaceInput(1, Int32Mul(quotient, Uint32Constant(divisor)));
603 } 603 }
604 node->TrimInputCount(2); 604 node->TrimInputCount(2);
605 return Changed(node); 605 return Changed(node);
606 } 606 }
607 return NoChange(); 607 return NoChange();
608 } 608 }
609 609
610 610
611 Reduction MachineOperatorReducer::ReduceTruncateFloat64ToInt32Input(
612 Node* input) {
613 Float64Matcher m(input);
614 if (m.HasValue()) return ReplaceInt32(DoubleToInt32(m.Value()));
615 if (m.IsChangeInt32ToFloat64()) return Replace(m.node()->InputAt(0));
616 return NoChange();
617 }
618
619
620 Reduction MachineOperatorReducer::ReduceTruncateFloat64ToInt32(Node* node) { 611 Reduction MachineOperatorReducer::ReduceTruncateFloat64ToInt32(Node* node) {
621 // Try to reduce the input first. 612 Float64Matcher m(node->InputAt(0));
622 Node* const input = node->InputAt(0); 613 if (m.HasValue()) return ReplaceInt32(DoubleToInt32(m.Value()));
623 Reduction reduction = ReduceTruncateFloat64ToInt32Input(input); 614 if (m.IsChangeInt32ToFloat64()) return Replace(m.node()->InputAt(0));
624 if (reduction.Changed()) return reduction; 615 if (m.IsPhi()) {
625 if (input->opcode() == IrOpcode::kPhi) { 616 Node* const phi = m.node();
626 DCHECK_EQ(kRepFloat64, RepresentationOf(OpParameter<MachineType>(input))); 617 DCHECK_EQ(kRepFloat64, RepresentationOf(OpParameter<MachineType>(phi)));
627 // TruncateFloat64ToInt32(Phi[Float64](x1,...,xn)) 618 if (phi->OwnedBy(node)) {
628 // => Phi[Int32](TruncateFloat64ToInt32(x1), 619 // TruncateFloat64ToInt32(Phi[Float64](x1,...,xn))
629 // ..., 620 // => Phi[Int32](TruncateFloat64ToInt32(x1),
630 // TruncateFloat64ToInt32(xn)) 621 // ...,
631 int const input_count = input->InputCount() - 1; 622 // TruncateFloat64ToInt32(xn))
632 Node* const control = input->InputAt(input_count); 623 const int value_input_count = phi->InputCount() - 1;
633 DCHECK_LE(0, input_count); 624 for (int i = 0; i < value_input_count; ++i) {
634 node->set_op(common()->Phi(kMachInt32, input_count)); 625 Node* input = graph()->NewNode(machine()->TruncateFloat64ToInt32(),
635 for (int i = 0; i < input_count; ++i) { 626 phi->InputAt(i));
636 Node* value = input->InputAt(i); 627 // TODO(bmeurer): Reschedule input for reduction once we have Revisit()
637 // Recursively try to reduce the value first. 628 // instead of recursing into ReduceTruncateFloat64ToInt32() here.
638 Reduction const reduction = ReduceTruncateFloat64ToInt32Input(value); 629 Reduction reduction = ReduceTruncateFloat64ToInt32(input);
639 if (reduction.Changed()) { 630 if (reduction.Changed()) input = reduction.replacement();
640 value = reduction.replacement(); 631 phi->ReplaceInput(i, input);
641 } else {
642 value = graph()->NewNode(machine()->TruncateFloat64ToInt32(), value);
643 } 632 }
644 if (i < node->InputCount()) { 633 phi->set_op(common()->Phi(kMachInt32, value_input_count));
645 node->ReplaceInput(i, value); 634 return Replace(phi);
646 } else {
647 node->AppendInput(graph()->zone(), value);
648 }
649 } 635 }
650 if (input_count < node->InputCount()) {
651 node->ReplaceInput(input_count, control);
652 } else {
653 node->AppendInput(graph()->zone(), control);
654 }
655 node->TrimInputCount(input_count + 1);
656 return Changed(node);
657 } 636 }
658 return NoChange(); 637 return NoChange();
659 } 638 }
660 639
661 640
662 Reduction MachineOperatorReducer::ReduceStore(Node* node) { 641 Reduction MachineOperatorReducer::ReduceStore(Node* node) {
663 MachineType const rep = 642 MachineType const rep =
664 RepresentationOf(StoreRepresentationOf(node->op()).machine_type()); 643 RepresentationOf(StoreRepresentationOf(node->op()).machine_type());
665 Node* const value = node->InputAt(2); 644 Node* const value = node->InputAt(2);
666 switch (value->opcode()) { 645 switch (value->opcode()) {
(...skipping 234 matching lines...) Expand 10 before | Expand all | Expand 10 after
901 MachineOperatorBuilder* MachineOperatorReducer::machine() const { 880 MachineOperatorBuilder* MachineOperatorReducer::machine() const {
902 return jsgraph()->machine(); 881 return jsgraph()->machine();
903 } 882 }
904 883
905 884
906 Graph* MachineOperatorReducer::graph() const { return jsgraph()->graph(); } 885 Graph* MachineOperatorReducer::graph() const { return jsgraph()->graph(); }
907 886
908 } // namespace compiler 887 } // namespace compiler
909 } // namespace internal 888 } // namespace internal
910 } // namespace v8 889 } // 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