Commit 3193f59a authored by bmeurer@chromium.org's avatar bmeurer@chromium.org

[turbofan] Add support for change/truncate to MachineOperatorReducer.

TEST=compiler-unittests
R=jarin@chromium.org

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

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@23293 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 8da0b4ec
......@@ -29,24 +29,29 @@ MachineOperatorReducer::MachineOperatorReducer(Graph* graph,
machine_(graph->zone()) {}
Node* MachineOperatorReducer::Int32Constant(int32_t value) {
Node** loc = cache_->FindInt32Constant(value);
Node* MachineOperatorReducer::Float64Constant(volatile double value) {
Node** loc = cache_->FindFloat64Constant(value);
if (*loc == NULL) {
*loc = graph_->NewNode(common_.Int32Constant(value));
*loc = graph_->NewNode(common_.Float64Constant(value));
}
return *loc;
}
Node* MachineOperatorReducer::Float64Constant(volatile double value) {
Node** loc = cache_->FindFloat64Constant(value);
Node* MachineOperatorReducer::Int32Constant(int32_t value) {
Node** loc = cache_->FindInt32Constant(value);
if (*loc == NULL) {
*loc = graph_->NewNode(common_.Float64Constant(value));
*loc = graph_->NewNode(common_.Int32Constant(value));
}
return *loc;
}
Node* MachineOperatorReducer::Int64Constant(int64_t value) {
return graph_->NewNode(common_.Int64Constant(value));
}
// Perform constant folding and strength reduction on machine operators.
Reduction MachineOperatorReducer::Reduce(Node* node) {
switch (node->opcode()) {
......@@ -392,6 +397,50 @@ Reduction MachineOperatorReducer::Reduce(Node* node) {
}
break;
}
case IrOpcode::kChangeFloat64ToInt32: {
Float64Matcher m(node->InputAt(0));
if (m.HasValue()) return ReplaceInt32(FastD2I(m.Value()));
if (m.IsChangeInt32ToFloat64()) return Replace(m.node()->InputAt(0));
break;
}
case IrOpcode::kChangeFloat64ToUint32: {
Float64Matcher m(node->InputAt(0));
if (m.HasValue()) return ReplaceInt32(FastD2UI(m.Value()));
if (m.IsChangeUint32ToFloat64()) return Replace(m.node()->InputAt(0));
break;
}
case IrOpcode::kChangeInt32ToFloat64: {
Int32Matcher m(node->InputAt(0));
if (m.HasValue()) return ReplaceFloat64(FastI2D(m.Value()));
break;
}
case IrOpcode::kChangeInt32ToInt64: {
Int32Matcher m(node->InputAt(0));
if (m.HasValue()) return ReplaceInt64(m.Value());
break;
}
case IrOpcode::kChangeUint32ToFloat64: {
Uint32Matcher m(node->InputAt(0));
if (m.HasValue()) return ReplaceFloat64(FastUI2D(m.Value()));
break;
}
case IrOpcode::kChangeUint32ToUint64: {
Uint32Matcher m(node->InputAt(0));
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::kTruncateInt64ToInt32: {
Int64Matcher m(node->InputAt(0));
if (m.HasValue()) return ReplaceInt32(static_cast<int32_t>(m.Value()));
if (m.IsChangeInt32ToInt64()) return Replace(m.node()->InputAt(0));
break;
}
// TODO(turbofan): strength-reduce and fold floating point operations.
default:
break;
......
......@@ -32,17 +32,19 @@ class MachineOperatorReducer : public Reducer {
CommonOperatorBuilder common_;
MachineOperatorBuilder machine_;
Node* Int32Constant(int32_t value);
Node* Float64Constant(volatile double value);
Node* Int32Constant(int32_t value);
Node* Int64Constant(int64_t value);
Reduction ReplaceBool(bool value) { return ReplaceInt32(value ? 1 : 0); }
Reduction ReplaceFloat64(volatile double value) {
return Replace(Float64Constant(value));
}
Reduction ReplaceInt32(int32_t value) {
return Replace(Int32Constant(value));
}
Reduction ReplaceFloat64(volatile double value) {
return Replace(Float64Constant(value));
Reduction ReplaceInt64(int64_t value) {
return Replace(Int64Constant(value));
}
};
}
......
......@@ -55,6 +55,11 @@ Node* GraphTest::Int32Constant(int32_t value) {
}
Node* GraphTest::Int64Constant(int64_t value) {
return graph()->NewNode(common()->Int64Constant(value));
}
Node* GraphTest::NumberConstant(double value) {
return graph()->NewNode(common()->NumberConstant(value));
}
......@@ -647,6 +652,12 @@ Matcher<Node*> IsInt32Constant(const Matcher<int32_t>& value_matcher) {
}
Matcher<Node*> IsInt64Constant(const Matcher<int64_t>& value_matcher) {
return MakeMatcher(
new IsConstantMatcher<int64_t>(IrOpcode::kInt64Constant, value_matcher));
}
Matcher<Node*> IsFloat64Constant(const Matcher<double>& value_matcher) {
return MakeMatcher(
new IsConstantMatcher<double>(IrOpcode::kFloat64Constant, value_matcher));
......
......@@ -32,6 +32,7 @@ class GraphTest : public CommonOperatorTest {
Node* Parameter(int32_t index);
Node* Float64Constant(double value);
Node* Int32Constant(int32_t value);
Node* Int64Constant(int64_t value);
Node* NumberConstant(double value);
Node* HeapConstant(const PrintableUnique<HeapObject>& value);
Node* FalseConstant();
......@@ -63,6 +64,7 @@ Matcher<Node*> IsHeapConstant(
const Matcher<PrintableUnique<HeapObject> >& value_matcher);
Matcher<Node*> IsFloat64Constant(const Matcher<double>& value_matcher);
Matcher<Node*> IsInt32Constant(const Matcher<int32_t>& value_matcher);
Matcher<Node*> IsInt64Constant(const Matcher<int64_t>& value_matcher);
Matcher<Node*> IsNumberConstant(const Matcher<double>& value_matcher);
Matcher<Node*> IsPhi(const Matcher<Node*>& value0_matcher,
const Matcher<Node*>& value1_matcher,
......
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