if (m.HasValue()) return ReplaceInt64(static_cast<uint64_t>(m.Value()));
break;
}
- case IrOpcode::kTruncateFloat64ToInt32: {
- Float64Matcher m(node->InputAt(0));
- if (m.HasValue()) return ReplaceInt32(DoubleToInt32(m.Value()));
- if (m.IsChangeInt32ToFloat64()) return Replace(m.node()->InputAt(0));
- break;
- }
+ case IrOpcode::kTruncateFloat64ToInt32:
+ return ReduceTruncateFloat64ToInt32(node);
case IrOpcode::kTruncateInt64ToInt32: {
Int64Matcher m(node->InputAt(0));
if (m.HasValue()) return ReplaceInt32(static_cast<int32_t>(m.Value()));
}
+Reduction MachineOperatorReducer::ReduceTruncateFloat64ToInt32(Node* node) {
+ Float64Matcher m(node->InputAt(0));
+ 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::ReduceStore(Node* node) {
MachineType const rep =
RepresentationOf(StoreRepresentationOf(node->op()).machine_type());
}
+TEST_F(MachineOperatorReducerTest, TruncateFloat64ToInt32WithPhi) {
+ Node* const p0 = Parameter(0);
+ Node* const p1 = Parameter(1);
+ Node* const merge = graph()->start();
+ Reduction reduction = Reduce(graph()->NewNode(
+ machine()->TruncateFloat64ToInt32(),
+ graph()->NewNode(common()->Phi(kMachFloat64, 2), p0, p1, merge)));
+ ASSERT_TRUE(reduction.Changed());
+ EXPECT_THAT(reduction.replacement(),
+ IsPhi(kMachInt32, IsTruncateFloat64ToInt32(p0),
+ IsTruncateFloat64ToInt32(p1), merge));
+}
+
+
// -----------------------------------------------------------------------------
// TruncateInt64ToInt32