[turbofan] Optimize redundant JSToObject operations.

We don't need to keep JSToObject operations in the graph if there's some
preceeding map check that already provides information that the input is
indeed already a receiver.

Change-Id: I2d04895831ff561624fbe91a2fe03bb6e5d918a5
Reviewed-on: https://chromium-review.googlesource.com/1174259
Reviewed-by: Jaroslav Sevcik <jarin@chromium.org>
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#55120}
This commit is contained in:
Benedikt Meurer 2018-08-14 11:18:40 +02:00 committed by Commit Bot
parent c8376b0069
commit ae09fa8354
2 changed files with 22 additions and 0 deletions

View File

@ -110,6 +110,8 @@ Reduction JSNativeContextSpecialization::Reduce(Node* node) {
return ReduceJSStoreDataPropertyInLiteral(node);
case IrOpcode::kJSStoreInArrayLiteral:
return ReduceJSStoreInArrayLiteral(node);
case IrOpcode::kJSToObject:
return ReduceJSToObject(node);
default:
break;
}
@ -2181,6 +2183,25 @@ Reduction JSNativeContextSpecialization::ReduceJSStoreInArrayLiteral(
store_mode);
}
Reduction JSNativeContextSpecialization::ReduceJSToObject(Node* node) {
DCHECK_EQ(IrOpcode::kJSToObject, node->opcode());
Node* receiver = NodeProperties::GetValueInput(node, 0);
Node* effect = NodeProperties::GetEffectInput(node);
ZoneHandleSet<Map> receiver_maps;
NodeProperties::InferReceiverMapsResult result =
NodeProperties::InferReceiverMaps(isolate(), receiver, effect,
&receiver_maps);
if (result == NodeProperties::kNoReceiverMaps) return NoChange();
for (size_t i = 0; i < receiver_maps.size(); ++i) {
if (!receiver_maps[i]->IsJSReceiverMap()) return NoChange();
}
ReplaceWithValue(node, receiver, effect);
return Replace(receiver);
}
namespace {
ExternalArrayType GetArrayTypeFromElementsKind(ElementsKind kind) {

View File

@ -76,6 +76,7 @@ class JSNativeContextSpecialization final : public AdvancedReducer {
Reduction ReduceJSStoreNamedOwn(Node* node);
Reduction ReduceJSStoreDataPropertyInLiteral(Node* node);
Reduction ReduceJSStoreInArrayLiteral(Node* node);
Reduction ReduceJSToObject(Node* node);
Reduction ReduceElementAccess(Node* node, Node* index, Node* value,
MapHandles const& receiver_maps,