Commit 1a5db24e authored by bmeurer's avatar bmeurer Committed by Commit bot

[turbofan] Use PlainPrimitiveToNumber whenever possible.

TEST=cctest,unittests
R=jarin@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#26071}
parent a956bf58
......@@ -537,7 +537,7 @@ Reduction JSTypedLowering::ReduceJSToNumberInput(Node* input) {
return Changed(input); // JSToNumber(JSToNumber(x)) => JSToNumber(x)
}
// Check if we have a cached conversion.
Node* conversion = FindConversion<IrOpcode::kJSToNumber>(input);
Node* conversion = FindConversion<IrOpcode::kPlainPrimitiveToNumber>(input);
if (conversion) return Replace(conversion);
Type* input_type = NodeProperties::GetBounds(input).upper;
if (input_type->Is(Type::Number())) {
......@@ -571,18 +571,19 @@ Reduction JSTypedLowering::ReduceJSToNumber(Node* node) {
}
Type* const input_type = NodeProperties::GetBounds(input).upper;
if (input_type->Is(Type::PlainPrimitive())) {
RelaxEffects(node);
if (input->opcode() == IrOpcode::kPhi) {
// JSToNumber(phi(x1,...,xn,control):plain-primitive,context)
// => phi(JSToNumber(x1,no-context),
// => phi(PlainPrimitiveToNumber(x1),
// ...,
// JSToNumber(xn,no-context),control)
// PlainPrimitiveToNumber(xn),
// control)
int const input_count = input->InputCount() - 1;
Node* const control = input->InputAt(input_count);
DCHECK_LE(0, input_count);
DCHECK(NodeProperties::IsControl(control));
DCHECK(NodeProperties::GetBounds(node).upper->Is(Type::Number()));
DCHECK(!NodeProperties::GetBounds(input).upper->Is(Type::Number()));
RelaxEffects(node);
node->set_op(common()->Phi(kMachAnyTagged, input_count));
for (int i = 0; i < input_count; ++i) {
// We must be very careful not to introduce cycles when pushing
......@@ -608,13 +609,12 @@ Reduction JSTypedLowering::ReduceJSToNumber(Node* node) {
}
if (input->opcode() == IrOpcode::kSelect) {
// JSToNumber(select(c,x1,x2):plain-primitive,context)
// => select(c,JSToNumber(x1,no-context),JSToNumber(x2,no-context))
// => select(c,PlainPrimitiveToNumber(x1),PlainPrimitiveToNumber(x2))
int const input_count = input->InputCount();
BranchHint const input_hint = SelectParametersOf(input->op()).hint();
DCHECK_EQ(3, input_count);
DCHECK(NodeProperties::GetBounds(node).upper->Is(Type::Number()));
DCHECK(!NodeProperties::GetBounds(input).upper->Is(Type::Number()));
RelaxEffects(node);
node->set_op(common()->Select(kMachAnyTagged, input_hint));
node->ReplaceInput(0, input->InputAt(0));
for (int i = 1; i < input_count; ++i) {
......@@ -630,24 +630,12 @@ Reduction JSTypedLowering::ReduceJSToNumber(Node* node) {
node->TrimInputCount(input_count);
return Changed(node);
}
// JSToNumber(x:plain-primitive,context) => PlainPrimitiveToNumber(x)
node->set_op(simplified()->PlainPrimitiveToNumber());
node->TrimInputCount(1);
// Remember this conversion.
InsertConversion(node);
if (NodeProperties::GetContextInput(node) !=
jsgraph()->NoContextConstant() ||
NodeProperties::GetEffectInput(node) != graph()->start() ||
NodeProperties::GetControlInput(node) != graph()->start()) {
// JSToNumber(x:plain-primitive,context,effect,control)
// => JSToNumber(x,no-context,start,start)
RelaxEffects(node);
NodeProperties::ReplaceContextInput(node, jsgraph()->NoContextConstant());
NodeProperties::ReplaceControlInput(node, graph()->start());
NodeProperties::ReplaceEffectInput(node, graph()->start());
if (OperatorProperties::HasFrameStateInput(node->op())) {
NodeProperties::ReplaceFrameStateInput(node,
jsgraph()->EmptyFrameState());
}
return Changed(node);
}
return Changed(node);
}
return NoChange();
}
......@@ -952,16 +940,8 @@ Node* JSTypedLowering::ConvertToNumber(Node* input) {
// Avoid inserting too many eager ToNumber() operations.
Reduction const reduction = ReduceJSToNumberInput(input);
if (reduction.Changed()) return reduction.replacement();
// TODO(jarin) Use PlainPrimitiveToNumber once we have it.
Node* const conversion =
FLAG_turbo_deoptimization
? graph()->NewNode(javascript()->ToNumber(), input,
jsgraph()->NoContextConstant(),
jsgraph()->EmptyFrameState(), graph()->start(),
graph()->start())
: graph()->NewNode(javascript()->ToNumber(), input,
jsgraph()->NoContextConstant(), graph()->start(),
graph()->start());
graph()->NewNode(simplified()->PlainPrimitiveToNumber(), input);
InsertConversion(conversion);
return conversion;
}
......@@ -981,7 +961,7 @@ Node* JSTypedLowering::FindConversion(Node* input) {
void JSTypedLowering::InsertConversion(Node* conversion) {
DCHECK(conversion->opcode() == IrOpcode::kJSToNumber);
DCHECK(conversion->opcode() == IrOpcode::kPlainPrimitiveToNumber);
size_t const input_id = conversion->InputAt(0)->id();
if (input_id >= conversions_.size()) {
conversions_.resize(2 * input_id + 1);
......
......@@ -488,7 +488,7 @@ TEST(JSToNumberOfNumberOrOtherPrimitive) {
for (size_t i = 0; i < arraysize(others); i++) {
Type* t = Type::Union(Type::Number(), others[i], R.main_zone());
Node* r = R.ReduceUnop(R.javascript.ToNumber(), t);
CHECK_EQ(IrOpcode::kJSToNumber, r->opcode());
CHECK_EQ(IrOpcode::kPlainPrimitiveToNumber, r->opcode());
}
}
......@@ -1033,7 +1033,8 @@ TEST(OrderCompareEffects) {
BinopEffectsTester B(ops[j], Type::Symbol(), Type::String());
CHECK_EQ(ops[j + 1]->opcode(), B.result->op()->opcode());
Node* i0 = B.CheckConvertedInput(IrOpcode::kJSToNumber, 0, true);
Node* i0 =
B.CheckConvertedInput(IrOpcode::kPlainPrimitiveToNumber, 0, false);
Node* i1 = B.CheckConvertedInput(IrOpcode::kJSToNumber, 1, true);
// Inputs should be commuted.
......
......@@ -372,8 +372,7 @@ TEST_F(JSTypedLoweringTest, JSToNumberWithPlainPrimitive) {
Reduction r = Reduce(graph()->NewNode(javascript()->ToNumber(), input,
context, effect, control));
ASSERT_TRUE(r.Changed());
EXPECT_THAT(r.replacement(), IsToNumber(input, IsNumberConstant(BitEq(0.0)),
graph()->start(), control));
EXPECT_THAT(r.replacement(), IsPlainPrimitiveToNumber(input));
}
......
......@@ -1308,6 +1308,7 @@ IS_UNOP_MATCHER(Float64RoundTruncate)
IS_UNOP_MATCHER(Float64RoundTiesAway)
IS_UNOP_MATCHER(NumberToInt32)
IS_UNOP_MATCHER(NumberToUint32)
IS_UNOP_MATCHER(PlainPrimitiveToNumber)
#undef IS_UNOP_MATCHER
} // namespace compiler
......
......@@ -85,6 +85,7 @@ Matcher<Node*> IsNumberSubtract(const Matcher<Node*>& lhs_matcher,
const Matcher<Node*>& rhs_matcher);
Matcher<Node*> IsNumberMultiply(const Matcher<Node*>& lhs_matcher,
const Matcher<Node*>& rhs_matcher);
Matcher<Node*> IsPlainPrimitiveToNumber(const Matcher<Node*>& value_matcher);
Matcher<Node*> IsLoadField(const Matcher<FieldAccess>& access_matcher,
const Matcher<Node*>& base_matcher,
const Matcher<Node*>& effect_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