Fix typed lowering of JSUnaryNot to work with graph reducer.

R=titzer@chromium.org
TEST=cctest/test-js-typed-lowering/UnaryNot[Effects]

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

git-svn-id: https://v8.googlecode.com/svn/branches/bleeding_edge@23561 ce2b1a6d-e550-0410-aec6-3dcde31c8c00
parent 3a7b5b44
......@@ -280,7 +280,6 @@ REPLACE_RUNTIME_CALL(JSCreateGlobalContext, Runtime::kAbort)
UNIMPLEMENTED(); \
return node; \
}
REPLACE_UNIMPLEMENTED(JSToString)
REPLACE_UNIMPLEMENTED(JSToName)
REPLACE_UNIMPLEMENTED(JSYield)
REPLACE_UNIMPLEMENTED(JSDebugger)
......@@ -402,6 +401,12 @@ Node* JSGenericLowering::LowerJSToBoolean(Node* node) {
}
Node* JSGenericLowering::LowerJSToString(Node* node) {
ReplaceWithBuiltinCall(node, Builtins::TO_STRING, 1);
return node;
}
Node* JSGenericLowering::LowerJSToObject(Node* node) {
ReplaceWithBuiltinCall(node, Builtins::TO_OBJECT, 1);
return node;
......
......@@ -587,19 +587,19 @@ Reduction JSTypedLowering::Reduce(Node* node) {
Reduction result = ReduceJSToBooleanInput(node->InputAt(0));
Node* value;
if (result.Changed()) {
// !x => BooleanNot(x)
// JSUnaryNot(x) => BooleanNot(x)
value =
graph()->NewNode(simplified()->BooleanNot(), result.replacement());
NodeProperties::ReplaceWithValue(node, value);
return Changed(value);
} else {
// !x => BooleanNot(JSToBoolean(x))
// JSUnaryNot(x) => BooleanNot(JSToBoolean(x))
value = graph()->NewNode(simplified()->BooleanNot(), node);
node->set_op(javascript()->ToBoolean());
NodeProperties::ReplaceWithValue(node, value, node);
// Note: ReplaceUses() smashes all uses, so smash it back here.
value->ReplaceInput(0, node);
return ReplaceWith(value);
return Changed(node);
}
}
case IrOpcode::kJSToBoolean:
......
......@@ -755,9 +755,18 @@ TEST(UnaryNot) {
Operator* opnot = R.javascript.UnaryNot();
for (size_t i = 0; i < arraysize(kJSTypes); i++) {
Node* r = R.ReduceUnop(opnot, kJSTypes[i]);
Node* orig = R.Unop(opnot, R.Parameter(kJSTypes[i]));
Node* use = R.graph.NewNode(R.common.Return(), orig);
Node* r = R.reduce(orig);
// TODO(titzer): test will break if/when js-typed-lowering constant folds.
CHECK_EQ(IrOpcode::kBooleanNot, r->opcode());
CHECK_EQ(IrOpcode::kBooleanNot, use->InputAt(0)->opcode());
if (r == orig && orig->opcode() == IrOpcode::kJSToBoolean) {
// The original node was turned into a ToBoolean.
CHECK_EQ(IrOpcode::kJSToBoolean, r->opcode());
} else {
CHECK_EQ(IrOpcode::kBooleanNot, r->opcode());
}
}
}
......@@ -1184,16 +1193,16 @@ TEST(UnaryNotEffects) {
Node* value_use = R.graph.NewNode(R.common.Return(), orig);
Node* r = R.reduce(orig);
// TODO(titzer): test will break if/when js-typed-lowering constant folds.
CHECK_EQ(IrOpcode::kBooleanNot, r->opcode());
CHECK_EQ(r, value_use->InputAt(0));
CHECK_EQ(IrOpcode::kBooleanNot, value_use->InputAt(0)->opcode());
if (r->InputAt(0) == orig && orig->opcode() == IrOpcode::kJSToBoolean) {
if (r == orig && orig->opcode() == IrOpcode::kJSToBoolean) {
// The original node was turned into a ToBoolean, which has an effect.
CHECK_EQ(IrOpcode::kJSToBoolean, r->opcode());
R.CheckEffectInput(R.start(), orig);
R.CheckEffectInput(orig, effect_use);
} else {
// effect should have been removed from this node.
CHECK_EQ(IrOpcode::kBooleanNot, r->opcode());
R.CheckEffectInput(R.start(), effect_use);
}
}
......
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