Closed Bug 1980613 Opened 1 year ago Closed 1 year ago

Scalar replace subarray instructions

Categories

(Core :: JavaScript Engine: JIT, enhancement, P2)

enhancement

Tracking

()

RESOLVED FIXED
143 Branch
Tracking Status
firefox143 --- fixed

People

(Reporter: anba, Assigned: anba)

References

(Blocks 1 open bug)

Details

Attachments

(12 external files)

Support scalar replacement of subarray for the following instructions:

  • Simple array buffer view instructions (MArrayBufferViewByteOffset, MArrayBufferViewLength, MTypedArrayElementSize).
  • MTypedArrayFill to support the pattern ta.subarray(...).fill(value). (Used in JetStream3 "bigint-noble-secp256k1", "bigint-noble-ed25519", and "tfjs-wasm".)
  • MTypedArraySet to support the patterns ta.subarray(...).set(src) (used in JetStream3 "8bitbench-wasm") and ta.set(src.subarray(...), ...) (used in JetStream3 "pdfjs", "mandreel", "sqlite3-wasm", "bigint-noble-secp256k1", "bigint-noble-ed25519", "tfjs-wasm", "tsf-wasm", "zlib-wasm", "gcc-loops-wasm")
  • MTypedArraySubarray to support chained subarray calls. (Used for example in sanitizeGlyph in pdfjs.)

NOTE: Code patterns mentioned above were found through grep and don't reflect actually executed code. See table below for actual calls to subarray in JetStream 3.


Calls to inlined subarray from JetStream3 benchmarks, recording every 250th call:

Name subarray from Baseline subarray from Ion (no EA) subarray from Ion (with EA)
8bitbench-wasm 1250 0 0
bigint-noble-ed25519 500 5000 0
bigint-noble-secp256k1 7750 51500 3750
pdfjs 750 3750 3750
tfjs-wasm 11500 1750 0
tfjs-wasm-simd 11500 1750 0
tsf-wasm 2750 13500 0
zlib-wasm 500 1750 0

Notes:

  • Remaining subarray in bigint-noble-secp256k1 escape when calling bytesToNumber from fromCompressedHex, fromUncompressedHex, and parseDERInt.
  • I haven't investigated why tfjs-wasm(-simd) has a high number of `subarray calls from Baseline.

Make MTypedArraySubarray recoverable in preparation for scalar replacement
support.

Recovering is almost trivial except for the special case when the underlying
buffer was detached after the subarray call. In that case the recover code
has to create a TypedArray with a detached ArrayBuffer, which is normally not
an allowed operation.

Add MToIntegerIndex which computes the result of js::ToIntegerIndex.

Used in the next part.

Using the actual start index and length simplifies scalar replacement in the
next parts.

Add a template object to replace shape guards during scalar replacement.

New instruction to represent MArrayBufferViewElements with an offset applied.

Used in the next part.

Handle MGuardShape and MUnbox which are both replaced with the
MTypedArraySubarray instruction itself.

MGuardHasAttachedArrayBuffer is replaced with a guard on subarray->object().

Add scalar replacement support for:

  • MArrayBufferViewByteOffset
  • MArrayBufferViewLength
  • MTypedArrayElementSize

Replacing MGuardHasAttachedArrayBuffer with a guard on the subarray's object
(see part 7) means we can no longer just compare the current instruction's operand
with SubarrayReplacer::subarray_, but instead also have to check for new
MGuardHasAttachedArrayBuffer instructions.

Example: ta.subarray(0, 2).fill(0)

SSA graph:

27 TypedArraySubarray GuardHasAttachedArrayBuffer#19 ToIntegerIndex#23 Sub#26
...
38 GuardShape TypedArraySubarray#27
39 GuardHasAttachedArrayBuffer GuardShape#38
...
41 Constant 0x0
42 ArrayBufferViewLength GuardHasAttachedArrayBuffer#39
43 TypedArrayFill GuardHasAttachedArrayBuffer#39 TruncateToInt32#40 Constant#41 ArrayBufferViewLength#42

GuardHasAttachedArrayBuffer#39 is replaced with a new guard on the subarray's
object, so when we replace ArrayBufferViewLength#42, we have to account for
the replaced guard.

Add a five operands instruction class.

Used in the next part.

TypedArray.prototype.fill has start and end parameters, but unfortunately
JetStream 3 benchmarks instead use ta.subarray(start).fill(0)!

There are three cases to consider:

  1. subarray is the target object in set: ta.subarray(...).set(...)

In this case we just need to adjust the set offset parameter to include
the subarray start parameter.

  1. subarray is the source object in set: ta.set(src.subarray(...), ...)`

This case requires a new instruction to pass through the subarray start and
length operands.

  1. subarray is both the target and source object.

This is case is a no-op instruction.

This case just requires adding both start operands.

Attachment #9504543 - Attachment description: Bug 1980613 - Part 6: Add ArrayBufferViewElementsWithOffset. r=jandem! → Bug 1980613 - Part 5: Add ArrayBufferViewElementsWithOffset. r=jandem!
Severity: -- → N/A
Priority: -- → P2
Pushed by andre.bargull@gmail.com: https://github.com/mozilla-firefox/firefox/commit/05d4198a7f78 https://hg.mozilla.org/integration/autoland/rev/9bf1fda6d7db Part 1: Allow to recover MTypedArraySubarray. r=jandem https://github.com/mozilla-firefox/firefox/commit/3eee7926176a https://hg.mozilla.org/integration/autoland/rev/fd2d7f31e427 Part 2: Add MToIntegerIndex. r=jandem https://github.com/mozilla-firefox/firefox/commit/0967d8d1137f https://hg.mozilla.org/integration/autoland/rev/9ed440deab3d Part 3: Compute actual index and length for MTypedArraySubarray. r=jandem https://github.com/mozilla-firefox/firefox/commit/a7cbc44bb81c https://hg.mozilla.org/integration/autoland/rev/6ccc83e94737 Part 4: Add template object to TypedArraySubarray. r=jandem https://github.com/mozilla-firefox/firefox/commit/71779f269ca0 https://hg.mozilla.org/integration/autoland/rev/0e4dbb8f6a0c Part 5: Add ArrayBufferViewElementsWithOffset. r=jandem https://github.com/mozilla-firefox/firefox/commit/8345bfb948a1 https://hg.mozilla.org/integration/autoland/rev/c3d43d2da362 Part 6: Subarray scalar replacement of basic instructions. r=jandem https://github.com/mozilla-firefox/firefox/commit/49bce68ddeb9 https://hg.mozilla.org/integration/autoland/rev/ef14a9273ded Part 7: Scalar replace GuardHasAttachedArrayBuffer. r=jandem https://github.com/mozilla-firefox/firefox/commit/63ba118a5f52 https://hg.mozilla.org/integration/autoland/rev/3ee9f23091be Part 8: Scalar replace simple array buffer view instructions. r=jandem https://github.com/mozilla-firefox/firefox/commit/bf5cff27f156 https://hg.mozilla.org/integration/autoland/rev/d48de393b39c Part 9: Add MQuinaryInstruction. r=jandem https://github.com/mozilla-firefox/firefox/commit/3f1ce5f1a4da https://hg.mozilla.org/integration/autoland/rev/592ccf1285a8 Part 10: Scalar replace MTypedArrayFill. r=jandem https://github.com/mozilla-firefox/firefox/commit/0a0cdc609096 https://hg.mozilla.org/integration/autoland/rev/3b7e448dc9fb Part 11: Scalar replace MTypedArraySet. r=jandem https://github.com/mozilla-firefox/firefox/commit/622cd41444b7 https://hg.mozilla.org/integration/autoland/rev/f0b8ceb7c1b5 Part 12: Scalar replace MTypedArraySubarray. r=jandem
Pushed by chorotan@mozilla.com: https://github.com/mozilla-firefox/firefox/commit/1c034cb43574 https://hg.mozilla.org/integration/autoland/rev/441116576ccc Revert "Bug 1980613 - Part 12: Scalar replace MTypedArraySubarray. r=jandem" for causing pdfpaint failures

Backed out for causing pdfpaint failures

Backout link

Push with failures

Failure log

Flags: needinfo?(andrebargull)

The pdfpaint issue was caused by a bug in part 2.

Flags: needinfo?(andrebargull)
Pushed by andre.bargull@gmail.com: https://github.com/mozilla-firefox/firefox/commit/da943b14a2c5 https://hg.mozilla.org/integration/autoland/rev/dc3600d8005d Part 1: Allow to recover MTypedArraySubarray. r=jandem https://github.com/mozilla-firefox/firefox/commit/f00330e8a5e0 https://hg.mozilla.org/integration/autoland/rev/e85e249f2ded Part 2: Add MToIntegerIndex. r=jandem https://github.com/mozilla-firefox/firefox/commit/a52c5f193330 https://hg.mozilla.org/integration/autoland/rev/834436b34477 Part 3: Compute actual index and length for MTypedArraySubarray. r=jandem https://github.com/mozilla-firefox/firefox/commit/0a2fddc8af9d https://hg.mozilla.org/integration/autoland/rev/3df8edb665bb Part 4: Add template object to TypedArraySubarray. r=jandem https://github.com/mozilla-firefox/firefox/commit/7dda6d0c49c0 https://hg.mozilla.org/integration/autoland/rev/03e311b45ee8 Part 5: Add ArrayBufferViewElementsWithOffset. r=jandem https://github.com/mozilla-firefox/firefox/commit/046023e29634 https://hg.mozilla.org/integration/autoland/rev/ffe53d696cf7 Part 6: Subarray scalar replacement of basic instructions. r=jandem https://github.com/mozilla-firefox/firefox/commit/db5ff72ab74d https://hg.mozilla.org/integration/autoland/rev/d8f5e7f22a92 Part 7: Scalar replace GuardHasAttachedArrayBuffer. r=jandem https://github.com/mozilla-firefox/firefox/commit/0c8a666050a6 https://hg.mozilla.org/integration/autoland/rev/3235237d70a9 Part 8: Scalar replace simple array buffer view instructions. r=jandem https://github.com/mozilla-firefox/firefox/commit/de4d3d418b42 https://hg.mozilla.org/integration/autoland/rev/f4f05dfb4927 Part 9: Add MQuinaryInstruction. r=jandem https://github.com/mozilla-firefox/firefox/commit/c091b54241be https://hg.mozilla.org/integration/autoland/rev/c055a1519ceb Part 10: Scalar replace MTypedArrayFill. r=jandem https://github.com/mozilla-firefox/firefox/commit/6754a7f2bf3e https://hg.mozilla.org/integration/autoland/rev/0d91709aabe9 Part 11: Scalar replace MTypedArraySet. r=jandem https://github.com/mozilla-firefox/firefox/commit/7c3db8d5a2db https://hg.mozilla.org/integration/autoland/rev/021ef054533f Part 12: Scalar replace MTypedArraySubarray. r=jandem
QA Whiteboard: [qa-triage-done-c144/b143]
Blocks: 1874699
Regressions: 1991309
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: