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

[turbofan] Constant-fold ToNumber conversions.

We can constant-fold JSToNumber conversions during typed lowering
if the input is a known primitive constant (i.e. a string, oddball
or number). I.e. JSToNumber("123") can be constant-folded to 123.

R=jarin@chromium.org

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

Cr-Commit-Position: refs/heads/master@{#33654}
parent 0211c634
......@@ -780,8 +780,18 @@ Reduction JSTypedLowering::ReduceJSToNumberInput(Node* input) {
}
}
}
// Check if we have a cached conversion.
// Try constant-folding of JSToNumber with constant inputs.
Type* input_type = NodeProperties::GetType(input);
if (input_type->IsConstant()) {
Handle<Object> input_value = input_type->AsConstant()->Value();
if (input_value->IsString()) {
return Replace(jsgraph()->Constant(
String::ToNumber(Handle<String>::cast(input_value))));
} else if (input_value->IsOddball()) {
return Replace(jsgraph()->Constant(
Oddball::ToNumber(Handle<Oddball>::cast(input_value))));
}
}
if (input_type->Is(Type::Number())) {
// JSToNumber(x:number) => x
return Changed(input);
......
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