Commit 5950c007 authored by Mathias Bynens's avatar Mathias Bynens Committed by Commit Bot

[turbofan] Prefer memoized JSGraph constants

For numbers, `JSGraph::Constant(Handle<Object> value)` first checks the
type of `value`, and then calls `JSGraph::Constant` for its type, which
in turn performs some further checks before returning a value.

This patch saves a few `if` checks by making the following changes:

- JSGraph::Constant(0) → JSGraph::ZeroConstant()
- JSGraph::Constant(1) → JSGraph::OneConstant()

Change-Id: I6946c280437b7f1fe80d7c45c6fd9b3571907e07
Reviewed-on: https://chromium-review.googlesource.com/840982Reviewed-by: 's avatarBenedikt Meurer <bmeurer@chromium.org>
Commit-Queue: Mathias Bynens <mathias@chromium.org>
Cr-Commit-Position: refs/heads/master@{#50288}
parent 460af931
......@@ -906,7 +906,7 @@ Reduction JSCallReducer::ReduceArrayForEach(Handle<JSFunction> function,
SafeLoadElement(kind, receiver, control, &effect, &k, p.feedback());
Node* next_k =
graph()->NewNode(simplified()->NumberAdd(), k, jsgraph()->Constant(1));
graph()->NewNode(simplified()->NumberAdd(), k, jsgraph()->OneConstant());
checkpoint_params[3] = next_k;
Node* hole_true = nullptr;
......@@ -1119,7 +1119,7 @@ Reduction JSCallReducer::ReduceArrayReduce(Handle<JSFunction> function,
SafeLoadElement(kind, receiver, control, &effect, &k, p.feedback());
Node* next_k =
graph()->NewNode(simplified()->NumberAdd(), k, jsgraph()->Constant(1));
graph()->NewNode(simplified()->NumberAdd(), k, jsgraph()->OneConstant());
checkpoint_params[2] = next_k;
Node* hole_true = nullptr;
......@@ -1263,7 +1263,7 @@ Reduction JSCallReducer::ReduceArrayReduceRight(Handle<JSFunction> function,
receiver, effect, control);
Node* k = graph()->NewNode(simplified()->NumberSubtract(), original_length,
jsgraph()->Constant(1));
jsgraph()->OneConstant());
std::vector<Node*> checkpoint_params({receiver, fncallback, k,
original_length,
......@@ -1303,7 +1303,7 @@ Reduction JSCallReducer::ReduceArrayReduceRight(Handle<JSFunction> function,
cur = SafeLoadElement(kind, receiver, control, &effect, &k, p.feedback());
k = graph()->NewNode(simplified()->NumberSubtract(), k,
jsgraph()->Constant(1));
jsgraph()->OneConstant());
}
// Start the loop.
......@@ -1323,7 +1323,7 @@ Reduction JSCallReducer::ReduceArrayReduceRight(Handle<JSFunction> function,
effect = eloop;
Node* continue_test = graph()->NewNode(simplified()->NumberLessThanOrEqual(),
jsgraph()->Constant(0), k);
jsgraph()->ZeroConstant(), k);
Node* continue_branch = graph()->NewNode(common()->Branch(BranchHint::kTrue),
continue_test, control);
......@@ -1349,7 +1349,7 @@ Reduction JSCallReducer::ReduceArrayReduceRight(Handle<JSFunction> function,
SafeLoadElement(kind, receiver, control, &effect, &k, p.feedback());
Node* next_k = graph()->NewNode(simplified()->NumberSubtract(), k,
jsgraph()->Constant(1));
jsgraph()->OneConstant());
checkpoint_params[2] = next_k;
Node* hole_true = nullptr;
......@@ -1981,7 +1981,7 @@ Reduction JSCallReducer::ReduceArrayFind(ArrayFindVariant variant,
// Increment k for the next iteration.
Node* next_k = checkpoint_params[3] =
graph()->NewNode(simplified()->NumberAdd(), k, jsgraph()->Constant(1));
graph()->NewNode(simplified()->NumberAdd(), k, jsgraph()->OneConstant());
// Replace holes with undefined.
if (IsHoleyElementsKind(kind)) {
......
......@@ -982,9 +982,9 @@ Reduction JSCreateLowering::ReduceJSCreateKeyValueArray(Node* node) {
AllocationBuilder aa(jsgraph(), effect, graph()->start());
aa.AllocateArray(2, factory()->fixed_array_map());
aa.Store(AccessBuilder::ForFixedArrayElement(PACKED_ELEMENTS),
jsgraph()->Constant(0), key);
jsgraph()->ZeroConstant(), key);
aa.Store(AccessBuilder::ForFixedArrayElement(PACKED_ELEMENTS),
jsgraph()->Constant(1), value);
jsgraph()->OneConstant(), value);
Node* elements = aa.Finish();
AllocationBuilder a(jsgraph(), elements, graph()->start());
......
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