[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}
This commit is contained in:
bmeurer 2016-02-01 23:01:39 -08:00 committed by Commit bot
parent 0211c634f4
commit 1f85ff077d

View File

@ -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);