Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6)

Unified Diff: src/compiler/js-native-context-specialization.cc

Issue 2537763002: [turbofan] Also optimize instanceof with bound functions. (Closed)
Patch Set: Created 4 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « src/compiler/js-native-context-specialization.h ('k') | test/mjsunit/compiler/instanceof-opt3.js » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: src/compiler/js-native-context-specialization.cc
diff --git a/src/compiler/js-native-context-specialization.cc b/src/compiler/js-native-context-specialization.cc
index 6a503e702ba49898300ba430aa82eb91877cd8bb..4ab0ad8eded8d95781f53a2ee93b777da8e01fd2 100644
--- a/src/compiler/js-native-context-specialization.cc
+++ b/src/compiler/js-native-context-specialization.cc
@@ -71,6 +71,8 @@ Reduction JSNativeContextSpecialization::Reduce(Node* node) {
switch (node->opcode()) {
case IrOpcode::kJSInstanceOf:
return ReduceJSInstanceOf(node);
+ case IrOpcode::kJSOrdinaryHasInstance:
+ return ReduceJSOrdinaryHasInstance(node);
case IrOpcode::kJSLoadContext:
return ReduceJSLoadContext(node);
case IrOpcode::kJSLoadNamed:
@@ -133,7 +135,8 @@ Reduction JSNativeContextSpecialization::ReduceJSInstanceOf(Node* node) {
NodeProperties::ReplaceValueInput(node, object, 1);
NodeProperties::ReplaceEffectInput(node, effect);
NodeProperties::ChangeOp(node, javascript()->OrdinaryHasInstance());
- return Changed(node);
+ Reduction const reduction = ReduceJSOrdinaryHasInstance(node);
+ return reduction.Changed() ? reduction : Changed(node);
}
} else if (access_info.IsDataConstant()) {
DCHECK(access_info.constant()->IsCallable());
@@ -174,6 +177,31 @@ Reduction JSNativeContextSpecialization::ReduceJSInstanceOf(Node* node) {
return NoChange();
}
+Reduction JSNativeContextSpecialization::ReduceJSOrdinaryHasInstance(
+ Node* node) {
+ DCHECK_EQ(IrOpcode::kJSOrdinaryHasInstance, node->opcode());
+ Node* constructor = NodeProperties::GetValueInput(node, 0);
+ Node* object = NodeProperties::GetValueInput(node, 1);
+
+ // Check if the {constructor} is a JSBoundFunction.
+ HeapObjectMatcher m(constructor);
+ if (m.HasValue() && m.Value()->IsJSBoundFunction()) {
+ // OrdinaryHasInstance on bound functions turns into a recursive
+ // invocation of the instanceof operator again.
+ // ES6 section 7.3.19 OrdinaryHasInstance (C, O) step 2.
+ Handle<JSBoundFunction> function = Handle<JSBoundFunction>::cast(m.Value());
+ Handle<JSReceiver> bound_target_function(function->bound_target_function());
+ NodeProperties::ReplaceValueInput(node, object, 0);
+ NodeProperties::ReplaceValueInput(
+ node, jsgraph()->HeapConstant(bound_target_function), 1);
+ NodeProperties::ChangeOp(node, javascript()->InstanceOf());
+ Reduction const reduction = ReduceJSInstanceOf(node);
+ return reduction.Changed() ? reduction : Changed(node);
+ }
+
+ return NoChange();
+}
+
Reduction JSNativeContextSpecialization::ReduceJSLoadContext(Node* node) {
DCHECK_EQ(IrOpcode::kJSLoadContext, node->opcode());
ContextAccess const& access = ContextAccessOf(node->op());
« no previous file with comments | « src/compiler/js-native-context-specialization.h ('k') | test/mjsunit/compiler/instanceof-opt3.js » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698