Commit 35cc4af7 authored by bmeurer@chromium.org's avatar bmeurer@chromium.org

[turbofan] Push TruncateFloat64ToInt32 into phis.

TEST=unittests
R=dcarney@chromium.org

Review URL: https://codereview.chromium.org/707683003

Cr-Commit-Position: refs/heads/master@{#25189}
git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@25189 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent f9575cef
......@@ -523,12 +523,8 @@ Reduction MachineOperatorReducer::Reduce(Node* node) {
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()));
......@@ -692,6 +688,36 @@ Reduction MachineOperatorReducer::ReduceUint32Mod(Node* node) {
}
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());
......
......@@ -65,6 +65,7 @@ class MachineOperatorReducer FINAL : public Reducer {
Reduction ReduceUint32Div(Node* node);
Reduction ReduceInt32Mod(Node* node);
Reduction ReduceUint32Mod(Node* node);
Reduction ReduceTruncateFloat64ToInt32(Node* node);
Reduction ReduceStore(Node* node);
Reduction ReduceProjection(size_t index, Node* node);
......
......@@ -455,6 +455,20 @@ TEST_F(MachineOperatorReducerTest, TruncateFloat64ToInt32WithConstant) {
}
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
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment