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

Unified Diff: src/compiler/machine-operator-reducer.cc

Issue 801263002: [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 side-by-side diff with in-line comments
Download patch
Index: src/compiler/machine-operator-reducer.cc
diff --git a/src/compiler/machine-operator-reducer.cc b/src/compiler/machine-operator-reducer.cc
index f8555da33bb7dc1864c3d42caaf8be5defe11d01..1c615294cdf228debbc60f36c565aec7707bc489 100644
--- a/src/compiler/machine-operator-reducer.cc
+++ b/src/compiler/machine-operator-reducer.cc
@@ -608,31 +608,52 @@ Reduction MachineOperatorReducer::ReduceUint32Mod(Node* node) {
}
-Reduction MachineOperatorReducer::ReduceTruncateFloat64ToInt32(Node* node) {
- Float64Matcher m(node->InputAt(0));
+Reduction MachineOperatorReducer::ReduceTruncateFloat64ToInt32Input(
+ Node* input) {
+ Float64Matcher m(input);
if (m.HasValue()) return ReplaceInt32(DoubleToInt32(m.Value()));
if (m.IsChangeInt32ToFloat64()) return Replace(m.node()->InputAt(0));
- if (m.IsPhi()) {
- Node* const phi = m.node();
- DCHECK_EQ(kRepFloat64, RepresentationOf(OpParameter<MachineType>(phi)));
- if (phi->OwnedBy(node)) {
- // TruncateFloat64ToInt32(Phi[Float64](x1,...,xn))
- // => Phi[Int32](TruncateFloat64ToInt32(x1),
- // ...,
- // TruncateFloat64ToInt32(xn))
- const int value_input_count = phi->InputCount() - 1;
- for (int i = 0; i < value_input_count; ++i) {
- Node* input = graph()->NewNode(machine()->TruncateFloat64ToInt32(),
- phi->InputAt(i));
- // TODO(bmeurer): Reschedule input for reduction once we have Revisit()
- // instead of recursing into ReduceTruncateFloat64ToInt32() here.
- Reduction reduction = ReduceTruncateFloat64ToInt32(input);
- if (reduction.Changed()) input = reduction.replacement();
- phi->ReplaceInput(i, input);
- }
- phi->set_op(common()->Phi(kMachInt32, value_input_count));
- return Replace(phi);
+ return NoChange();
+}
+
+
+Reduction MachineOperatorReducer::ReduceTruncateFloat64ToInt32(Node* node) {
+ // Try to reduce the input first.
+ Node* const input = node->InputAt(0);
+ Reduction reduction = ReduceTruncateFloat64ToInt32Input(input);
+ if (reduction.Changed()) return reduction;
+ if (input->opcode() == IrOpcode::kPhi) {
+ DCHECK_EQ(kRepFloat64, RepresentationOf(OpParameter<MachineType>(input)));
+ // TruncateFloat64ToInt32(Phi[Float64](x1,...,xn))
+ // => Phi[Int32](TruncateFloat64ToInt32(x1),
+ // ...,
+ // TruncateFloat64ToInt32(xn))
+ int const input_count = input->InputCount() - 1;
+ Node* const control = input->InputAt(input_count);
+ DCHECK_LE(0, input_count);
+ node->set_op(common()->Phi(kMachInt32, input_count));
+ for (int i = 0; i < input_count; ++i) {
+ Node* value = input->InputAt(i);
+ // Recursively try to reduce the value first.
+ Reduction const reduction = ReduceTruncateFloat64ToInt32Input(value);
+ if (reduction.Changed()) {
+ value = reduction.replacement();
+ } else {
+ value = graph()->NewNode(machine()->TruncateFloat64ToInt32(), value);
+ }
+ if (i < node->InputCount()) {
+ node->ReplaceInput(i, value);
+ } else {
+ node->AppendInput(graph()->zone(), value);
+ }
+ }
+ if (input_count < node->InputCount()) {
+ node->ReplaceInput(input_count, control);
+ } else {
+ node->AppendInput(graph()->zone(), control);
}
+ node->TrimInputCount(input_count + 1);
+ return Changed(node);
}
return NoChange();
}
« 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