Commit 98aaeed6 authored by Benedikt Meurer's avatar Benedikt Meurer Committed by Commit Bot

[turbofan] Strength reduce JSResolvePromise to JSFulfillPromise.

We can strength-reduce JSResolvePromise(p,v) to JSFulfillPromise(p,v)
if the v is known to be a primitive. This not only avoids the dynamic
checks for v inside JSResolvePromise, but also removes the need to
have a frame state, as the JSFulfillPromise operation cannot call
back into arbitrary JavaScript, and thus cannot deoptimize lazily.

This triggers for example for async functions where the return value
is known (to TurboFan) to be a primitive value.

Bug: v8:7253
Change-Id: I4698d6026e0632ab3e2fef6c7f4aaacf6c2a508c
Reviewed-on: https://chromium-review.googlesource.com/c/1288449
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Reviewed-by: 's avatarMaya Lekova <mslekova@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56758}
parent bf95c6fa
......@@ -2224,6 +2224,22 @@ Reduction JSTypedLowering::ReduceJSParseInt(Node* node) {
return NoChange();
}
Reduction JSTypedLowering::ReduceJSResolvePromise(Node* node) {
DCHECK_EQ(IrOpcode::kJSResolvePromise, node->opcode());
Node* resolution = NodeProperties::GetValueInput(node, 1);
Type resolution_type = NodeProperties::GetType(resolution);
// We can strength-reduce JSResolvePromise to JSFulfillPromise
// if the {resolution} is known to be a primitive, as in that
// case we don't perform the implicit chaining (via "then").
if (resolution_type.Is(Type::Primitive())) {
// JSResolvePromise(p,v:primitive) -> JSFulfillPromise(p,v)
node->RemoveInput(3); // frame state
NodeProperties::ChangeOp(node, javascript()->FulfillPromise());
return Changed(node);
}
return NoChange();
}
Reduction JSTypedLowering::Reduce(Node* node) {
DisallowHeapAccess no_heap_access;
......@@ -2332,6 +2348,8 @@ Reduction JSTypedLowering::Reduce(Node* node) {
return ReduceObjectIsArray(node);
case IrOpcode::kJSParseInt:
return ReduceJSParseInt(node);
case IrOpcode::kJSResolvePromise:
return ReduceJSResolvePromise(node);
default:
break;
}
......
......@@ -87,6 +87,7 @@ class V8_EXPORT_PRIVATE JSTypedLowering final
Reduction ReduceSpeculativeNumberComparison(Node* node);
Reduction ReduceObjectIsArray(Node* node);
Reduction ReduceJSParseInt(Node* node);
Reduction ReduceJSResolvePromise(Node* node);
// Helper for ReduceJSLoadModule and ReduceJSStoreModule.
Node* BuildGetModuleCell(Node* node);
......
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