Change information
Commit message:
[compiler] Don't inline Array.prototype.sort on mixed elements kinds
CanInlineArrayIteratingBuiltin unions the receiver elements kinds, so
polymorphic feedback yields a kind that no single receiver need have:
{PACKED_SMI,PACKED} unions to PACKED_ELEMENTS. That is fine for the
iterating builtins, which only read the receiver, but the inlined sort
snapshots the elements, runs comparefn, and copies the snapshot back
specialized on the union kind.
A comparefn can narrow the live receiver to another kind in the map set
(a.fill(0) turns PACKED_ELEMENTS into PACKED_SMI_ELEMENTS). The
post-callback check accepts that map because it is in the original set,
and the copy-back then stores the snapshotted HeapObjects into a
Smi-elements array. Smi consumers of the resulting array read those
HeapObjects as Smis and move them without write barriers.
Require all receiver maps to agree on their elements kind before
inlining, in both Maglev and Turbofan. Monomorphic feedback is
unaffected, as is polymorphism whose maps share an elements kind; sites
with mixed kinds fall back to the generic builtin.
Fixed: 542403045
Change-Id: I38d9d3efc5942bd0122bbbe48bc26417a080821f
Cr-Commit-Position: refs/heads/main@{#109116}
Files:
- M src/compiler/js-call-reducer.cc
- M src/maglev/maglev-graph-builder.cc
- A test/mjsunit/regress/regress-crbug-542403045.js
Change size: M
Delta: 3 files changed, 111 insertions(+), 0 deletions(-)
Branch: refs/heads/main
Submit Requirements:
Code-Review: +1 by Darius Mercadier