← All reports

[JSC] B3 MemoryFill8/16/32/64/128 opcodes

Component: JavaScriptCore B3 | 8d8fd0b

B3 is JSC's mid-level SSA IR, used by the OMG tier for wasm and by FTL for JS. Macro opcodes are expanded in B3LowerMacros before lowering to Air and machine code, and B3ReduceStrength simplifies them first. Wasm memory.fill and GC array.fill write a repeated pattern over a range, and the compilers used to emit that logic themselves or call a C++ helper. This commit adds MemoryFill8/16/32/64/128, mirroring memset_pattern8 and friends, with a GCSafe MemoryFill64 variant. Constant-size fills become spread stores in B3ReduceStrength. Runtime sizes lower to overlapping inline stores for short lengths, a store loop for longer ones, and a slow-path call. OMG's emitMemoryFill and emitArrayFillRange are rebuilt on top of these opcodes, fillArrayElements and repeatedFillByte are deleted, and BBQ's addArrayFill is updated accordingly.

Before:                              After:
OMGIRGenerator                       OMGIRGenerator
  └─► hand-built stores / loop         └─► MemoryFill{8..128}(ptr, pattern, size)
  └─► call fillArrayElements                ├─ ReduceStrength: const size ─► stores
BBQJIT                                      └─ LowerMacros: small ─► overlap stores
  └─► addArrayFill(fillArrayElements)          medium ─► loop, large ─► memset_pattern

Wasm fills in OMG now go through one shared B3 lowering, and the commit says the opcodes will be applied more broadly in follow-ups.

New JIT-emitted memory writes on web-reachable wasm put the risk at the size-class boundaries: overlapping tail stores and loop trip counts at lengths 0, 1 and exact thresholds, plus 128-bit and narrower-width pattern splats. Compare the constant-size B3ReduceStrength path against the runtime-size lowering. Check the new opcodes' effects in Value::effectsSlow so CSE, store sinking, DCE and load forwarding cannot reorder or eliminate across them. Confirm the GCSafe MemoryFill64 keeps GC invariants for reference-typed arrays, and that bounds checks still precede the fill in both OMG and BBQ now that fillArrayElements is gone. The new tests only sweep lengths, so mixed sizes, aliasing and Validate coverage are likely thinner.