Shorter math IC double fast paths, emitted before first execution
Component: JSC JIT | a9b6a52
JSTests/stress/baseline-math-ic-unexecuted-binary-op.js
JSC's math ICs (JITMathIC) are inline caches for arithmetic. A generator such as JITAddGenerator emits an inline fast path specialized to the operand types seen in the profile, plus a slow path that records types and may regenerate the IC. On 64-bit, JSValues are NaN-boxed: int32s carry a high tag, and doubles are stored with an offset so they occupy a separate range of the 64-bit space from cells, int32s and other immediates. Unboxing a double means adding NumberTag, so type checks on boxed values depend on exactly where each value class lands.
Add, sub and mul across Baseline, DFG and FTL now get a shorter double-only fast path. After unboxing, a single unsigned compare against NumberTag << 1 rejects int32s and non-numbers together, replacing the separate "is number" and "is not int32" checks. On ARM64 the compare uses the number-tag register shifted left by one, via the new MacroAssemblerARM64::branch64LeftShift and the AssemblyHelpers::unboxDoubleOrBranchIfNotDouble helper. Add gains a double-only path; before, it fell back to the full snippet that tries int32 first. A Baseline binary op with an empty profile now emits the general snippet at compile time, instead of a patchable jump that generated the fast path out of line on first execution.
Double-only operand check:
Before: isNumber(x)? -> isInt32(x)? -> unbox
After: bits = x + NumberTag
bits >=u (NumberTag << 1) --> slow path (int32 or non-number)
else --> bits is a double (NaN included)
Significance
Baseline warm-up in large functions no longer allocates and flushes executable memory on the main thread for first-run binary ops. The hot double path also gets shorter, and the invariants of the code math ICs emit change in all three tiers.
Audit directions
The core question is whether one range compare correctly classifies every JSValue class: int32, cell, undefined/null/bool, BigInt32 and other immediates, the empty value, and doubles with unusual NaN payloads. A false accept would let a non-double be treated as a double. Check the ARM64 encoding of branch64LeftShift against its non-ARM64 equivalents and its register-vs-constant forms. In particular, check whether the tag register is guaranteed to hold the expected value in every JIT context (Baseline, DFG, FTL, LOLJIT). Look at the scratch registers and clobbers of the new unbox helper, and whether the slow path still sees the original operands when the compare fails after unboxing in place. The compile-time snippet for empty-profile ops does not record operand types, so look for stale or missing profile data feeding the DFG, including unary ops, and for repatching interacting with an already-inlined snippet. The deliberate split between Baseline/LOLJIT and DFG/FTL, which stay lazy for binary ICs, deserves a differential look.