Files
metal2vulkan/docs
Anees Iqbal 39639ef473 Follow struct members in the narrow analysis: mixed-select merges and a read's noted bits
What. Two analyses in lower/arith/narrow.rs looked only at whole values, so a value carried
inside a composite slipped past both:

- `merges_mixed_selects` (now `narrow::merges`) decides whether a module merges a select of a
  widened `half` against a value it does not hold widened with another widened value. Metal's
  compiler answers 2045 of the 2046 `half` NaNs of that merge `0x7E00` (measured on the M3 Max,
  2026-11-03), so a module that does it stays outside `DriverDeviation::MetalNanMoves`. It
  checked only scalar selects at phis and stores, and missed the same merge when a struct (a
  texel read's `{T, i8}`), an array or a vector carried the select and the other value. The new
  module records how each value is made (construct, insert, extract, copy, select, phi) and asks
  member by member, by a path of literal indices, whether a merged value holds a mixed select
  where another merged value holds a widened one. Walks are bounded (256 steps per question, 256
  members per type; past a bound the answer is the conservative one), and the records are charged
  to the meter.
- `known_bits` reused a `half`'s read bits only when the stored value was the read itself. A
  store of the read's value pulled back out of a struct (`{T, i8}` built from the read, then
  `OpCompositeExtract`) encoded the `half` again, which is the device's narrowing and loses a NaN's
  bits. The builder now records each struct construct, insert and extract it emits
  (`ModuleBuilder::structs`, counted in its footprint), and `FunctionBuilder::member_source`
  walks an extract back to the value that supplies the member wholly. A later insert into part
  of the path, a struct the builder did not make, a load or a phi gives no source. `known_bits`
  follows it before looking up noted bits.

Both decide from IR structure only (types, composite paths, operands), never from names.

Why. The coordinator's bug: `narrow::merges_mixed_selects` misses struct-wrapped merges, and a
store of a read's value does not see noted bits through the `{T, i8}` extract.

Docs: driver_facts.rs (the MetalNanMoves measurement) and docs/API.md's native-nan-encoding
entry now say the merge is followed member by member, and that a `half` moved unchanged from its
read keeps its bits through a struct's member too. The member-by-member reading is not measured
through a composite; the code and the docs say so.

SEMANTICS_VERSION 1968 -> 1969: translations change. The golden table moves 30 cells, all
`engine/rfs_imageblock_cover{.ll,.air.ll} | cover_two_word`, on every one of the 15 profiles.
That kernel's `as_type<half>` result is now stored from its noted bits through the struct
member instead of being encoded again. The table is re-blessed on development, not here.

Verified on the M3 Max (potluck, debug):
- New tests:
  - `lower::arith::tests::narrow::narrow_members_move_as_bits_through_structs`: every
    pattern of every narrow form, through a construct, inserts, a nested struct, and a
    replaced member, compared exactly.
  - `lower::arith::tests::narrow::a_merge_of_a_select_is_followed_through_struct_members`:
    builder-made `OpPhi`s of a plain select and of structs carrying it by construct, insert
    and extract are merges; a struct holding the select apart from the other value's member,
    and a merge with a constant, are not.
  - `tests::engine_arith::half_moves_are_metals_only_where_the_device_folds_them` gains
    kernel `member_kept`: a `half` read, inserted into `{half, i8}` and extracted keeps its
    bits (0xFE01) and widens nothing.
  All three, plus engine_cross_class and engine_float_call_notes, pass: 15/15, job
  m3-max-1192.
- Negative controls, with the translator sources of fd1029d6c9 under these tests (job
  m3-max-1195): all three fail.
  - The merge test fails at `Struct` (false, want true).
  - The members test fails "Form { held: Float(Half), lanes: 1 } through a struct
    (construct): 2045 of 65536 cases differ".
  - `member_kept` widens on lavapipe (true, want false).
- Note sets: a census of every public fixture's entries (2914 rows per stem) on moltenvk-m3 and
  lavapipe. It recorded each row's precision notes and whether it requires MetalNanMoves, before
  (fd1029d6c9's sources) and after. The two files are byte-identical (job m3-max-1195), so no
  fixture gains or loses a note on either device.
- Full metal2vulkan suite at an earlier stage of this change: 3335 passed. The 2 failures were a
  since-corrected test expectation and the golden table above (job m3-max-1190).

(cherry picked from commit a4c235fb867a6a32098b77e39387c43a97a28862)
2026-11-05 07:39:33 -08:00
..