Commit c7b15fb7 authored by Benedikt Meurer's avatar Benedikt Meurer Committed by Commit Bot

[turbofan] Lower to JSToNumeric to JSToNumber if possible.

This addresses a TODO in JSTypedLowering and generally makes the more
easier to follow since the methods deal only with one kind of Node now.

Bug: v8:8015
Change-Id: I8c3521b8d630dbe272264dc01e9ab3a5b0a8f682
Reviewed-on: https://chromium-review.googlesource.com/1196883Reviewed-by: 's avatarSigurd Schneider <sigurds@chromium.org>
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55530}
parent 82061873
...@@ -374,7 +374,7 @@ class JSBinopReduction final { ...@@ -374,7 +374,7 @@ class JSBinopReduction final {
Node* ConvertPlainPrimitiveToNumber(Node* node) { Node* ConvertPlainPrimitiveToNumber(Node* node) {
DCHECK(NodeProperties::GetType(node).Is(Type::PlainPrimitive())); DCHECK(NodeProperties::GetType(node).Is(Type::PlainPrimitive()));
// Avoid inserting too many eager ToNumber() operations. // Avoid inserting too many eager ToNumber() operations.
Reduction const reduction = lowering_->ReduceJSToNumberOrNumericInput(node); Reduction const reduction = lowering_->ReduceJSToNumberInput(node);
if (reduction.Changed()) return reduction.replacement(); if (reduction.Changed()) return reduction.replacement();
if (NodeProperties::GetType(node).Is(Type::Number())) { if (NodeProperties::GetType(node).Is(Type::Number())) {
return node; return node;
...@@ -967,9 +967,8 @@ Reduction JSTypedLowering::ReduceJSToLength(Node* node) { ...@@ -967,9 +967,8 @@ Reduction JSTypedLowering::ReduceJSToLength(Node* node) {
return NoChange(); return NoChange();
} }
Reduction JSTypedLowering::ReduceJSToNumberOrNumericInput(Node* input) { Reduction JSTypedLowering::ReduceJSToNumberInput(Node* input) {
// Try constant-folding of JSToNumber/JSToNumeric with constant inputs. Here // Try constant-folding of JSToNumber with constant inputs.
// we only cover cases where ToNumber and ToNumeric coincide.
Type input_type = NodeProperties::GetType(input); Type input_type = NodeProperties::GetType(input);
if (input_type.Is(Type::String())) { if (input_type.Is(Type::String())) {
...@@ -1002,10 +1001,10 @@ Reduction JSTypedLowering::ReduceJSToNumberOrNumericInput(Node* input) { ...@@ -1002,10 +1001,10 @@ Reduction JSTypedLowering::ReduceJSToNumberOrNumericInput(Node* input) {
return NoChange(); return NoChange();
} }
Reduction JSTypedLowering::ReduceJSToNumberOrNumeric(Node* node) { Reduction JSTypedLowering::ReduceJSToNumber(Node* node) {
// Try to reduce the input first. // Try to reduce the input first.
Node* const input = node->InputAt(0); Node* const input = node->InputAt(0);
Reduction reduction = ReduceJSToNumberOrNumericInput(input); Reduction reduction = ReduceJSToNumberInput(input);
if (reduction.Changed()) { if (reduction.Changed()) {
ReplaceWithValue(node, reduction.replacement()); ReplaceWithValue(node, reduction.replacement());
return reduction; return reduction;
...@@ -1021,7 +1020,18 @@ Reduction JSTypedLowering::ReduceJSToNumberOrNumeric(Node* node) { ...@@ -1021,7 +1020,18 @@ Reduction JSTypedLowering::ReduceJSToNumberOrNumeric(Node* node) {
NodeProperties::ChangeOp(node, simplified()->PlainPrimitiveToNumber()); NodeProperties::ChangeOp(node, simplified()->PlainPrimitiveToNumber());
return Changed(node); return Changed(node);
} }
// TODO(neis): Reduce ToNumeric to ToNumber if input can't be BigInt? return NoChange();
}
Reduction JSTypedLowering::ReduceJSToNumeric(Node* node) {
Node* const input = NodeProperties::GetValueInput(node, 0);
Type const input_type = NodeProperties::GetType(input);
if (input_type.Is(Type::Number())) {
// ToNumeric(x:number) => ToNumber(x)
NodeProperties::ChangeOp(node, javascript()->ToNumber());
Reduction const reduction = ReduceJSToNumber(node);
return reduction.Changed() ? reduction : Changed(node);
}
return NoChange(); return NoChange();
} }
...@@ -2308,8 +2318,9 @@ Reduction JSTypedLowering::Reduce(Node* node) { ...@@ -2308,8 +2318,9 @@ Reduction JSTypedLowering::Reduce(Node* node) {
return ReduceJSToName(node); return ReduceJSToName(node);
case IrOpcode::kJSToNumber: case IrOpcode::kJSToNumber:
case IrOpcode::kJSToNumberConvertBigInt: case IrOpcode::kJSToNumberConvertBigInt:
return ReduceJSToNumber(node);
case IrOpcode::kJSToNumeric: case IrOpcode::kJSToNumeric:
return ReduceJSToNumberOrNumeric(node); return ReduceJSToNumeric(node);
case IrOpcode::kJSToString: case IrOpcode::kJSToString:
return ReduceJSToString(node); return ReduceJSToString(node);
case IrOpcode::kJSToObject: case IrOpcode::kJSToObject:
......
...@@ -60,8 +60,9 @@ class V8_EXPORT_PRIVATE JSTypedLowering final ...@@ -60,8 +60,9 @@ class V8_EXPORT_PRIVATE JSTypedLowering final
Reduction ReduceJSToInteger(Node* node); Reduction ReduceJSToInteger(Node* node);
Reduction ReduceJSToLength(Node* node); Reduction ReduceJSToLength(Node* node);
Reduction ReduceJSToName(Node* node); Reduction ReduceJSToName(Node* node);
Reduction ReduceJSToNumberOrNumericInput(Node* input); Reduction ReduceJSToNumberInput(Node* input);
Reduction ReduceJSToNumberOrNumeric(Node* node); Reduction ReduceJSToNumber(Node* node);
Reduction ReduceJSToNumeric(Node* node);
Reduction ReduceJSToStringInput(Node* input); Reduction ReduceJSToStringInput(Node* input);
Reduction ReduceJSToString(Node* node); Reduction ReduceJSToString(Node* node);
Reduction ReduceJSToObject(Node* node); Reduction ReduceJSToObject(Node* node);
......
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