[turbofan] Remove unnecessary MaybeGrowFastElements operations.

When we detect during SimplifiedLowering that the index for the
MaybeGrowFastElements operation is less than the length of the
array, which are both passed as explicit parameters to the
operation, we can just drop the operation from the graph completely
and go with the existing elements. This happens for example when
code creates a new Array and immediately stores to it, i.e. like
in the case of

```js
const array = new Array();
array.push(something);
```

where the `new Array()` already creates a backing store of 4 elements,
so the check for growing in `Array#push()` is redundant here.

Change-Id: I548049b2c7b60c5f189f8ffdcb20b3a6ff1b0555
Reviewed-on: https://chromium-review.googlesource.com/1238655
Reviewed-by: Sigurd Schneider <sigurds@chromium.org>
Commit-Queue: Benedikt Meurer <bmeurer@chromium.org>
Cr-Commit-Position: refs/heads/master@{#56153}
This commit is contained in:
Benedikt Meurer 2018-09-21 16:11:34 +02:00 committed by Commit Bot
parent cc4bd49117
commit 4bfa074bd4

View File

@ -3088,12 +3088,25 @@ class RepresentationSelector {
return VisitBinop(node, UseInfo::AnyTagged(),
MachineRepresentation::kTaggedPointer);
case IrOpcode::kMaybeGrowFastElements: {
Type const index_type = TypeOf(node->InputAt(2));
Type const length_type = TypeOf(node->InputAt(3));
ProcessInput(node, 0, UseInfo::AnyTagged()); // object
ProcessInput(node, 1, UseInfo::AnyTagged()); // elements
ProcessInput(node, 2, UseInfo::TruncatingWord32()); // index
ProcessInput(node, 3, UseInfo::TruncatingWord32()); // length
ProcessRemainingInputs(node, 4);
SetOutput(node, MachineRepresentation::kTaggedPointer);
if (lower()) {
// If the index is known to be less than the length (or if
// we're in dead code), we know that we don't need to grow
// the elements, so we can just remove this operation all
// together and replace it with the elements that we have
// on the inputs.
if (index_type.IsNone() || length_type.IsNone() ||
index_type.Max() < length_type.Min()) {
DeferReplacement(node, node->InputAt(1));
}
}
return;
}