[turbofan] Constant-fold "length" property on strings.

When lowering loads of "length" on compile-time constant strings,
generate constant length instead of a load.

R=yangguo@chromium.org

Review-Url: https://codereview.chromium.org/2442233002
Cr-Commit-Position: refs/heads/master@{#40518}
This commit is contained in:
bmeurer 2016-10-23 23:25:07 -07:00 committed by Commit bot
parent caf6613c82
commit a2d4a7932e

View File

@ -360,9 +360,9 @@ Reduction JSNativeContextSpecialization::ReduceJSLoadNamed(Node* node) {
// Check if we have a constant receiver.
HeapObjectMatcher m(receiver);
if (m.HasValue()) {
// Optimize "prototype" property of functions.
if (m.Value()->IsJSFunction() &&
p.name().is_identical_to(factory()->prototype_string())) {
// Optimize "prototype" property of functions.
Handle<JSFunction> function = Handle<JSFunction>::cast(m.Value());
if (function->has_initial_map()) {
// We need to add a code dependency on the initial map of the
@ -378,6 +378,13 @@ Reduction JSNativeContextSpecialization::ReduceJSLoadNamed(Node* node) {
return Replace(value);
}
}
} else if (m.Value()->IsString() &&
p.name().is_identical_to(factory()->length_string())) {
// Constant-fold "length" property on constant strings.
Handle<String> string = Handle<String>::cast(m.Value());
Node* value = jsgraph()->Constant(string->length());
ReplaceWithValue(node, value);
return Replace(value);
}
}