shader: omit unused ordinary integer temporaries after validation #2471

Merged
chadhyatt merged 2 commits from upstream-pr/2479 into main 2026-11-25 23:01:52 +00:00
chadhyatt commented 2026-11-25 18:00:02 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by chadhyatt on 2026-11-25T18:00:02Z.


AI-assisted backport patch from x2w-microlift.

Omit unused fresh temporaries emitted by four ordinary integer operations (s_xor_b32, s_lshl_b32, v_xor_b32, v_add_nc_u32) after the existing validation gates. Backward liveness retains predicates, masked joins, addresses, exports and their dependencies. The source-built controls distinguish dead and live results and preserve invalid modifier, unbound operand and early wait refusals.

Tested revision: 677927084bcf2091c86d4fc510a716b460d5fced on upstream 1a0e506d30d.

  • python -B tests/pixel_aot_check.py (Apple Silicon macOS, Python 3.15): exit 0, all portable controls passed.
  • git diff --check 1a0e506d30d HEAD: exit 0.
  • On the immediately preceding audited base, the binary lane with LLVM 23 stopped at the unchanged check_f16_round_binary exact encoding assertion for v_ceil_f16_e64 v1, v2 (actual 0100dcd502010102). The documented LLVM15 toolchain is unavailable locally; the supported LLVM15 binary lane and Windows GPU/CI validation remain pending. No fixture or coverage was weakened and no new rendering/benchmark claims are made.
<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6610556070 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2479). Originally posted by [chadhyatt](https://github.com/chadhyatt) on 2026-11-25T18:00:02Z. --- AI-assisted backport patch from x2w-microlift. Omit unused fresh temporaries emitted by four ordinary integer operations (`s_xor_b32`, `s_lshl_b32`, `v_xor_b32`, `v_add_nc_u32`) after the existing validation gates. Backward liveness retains predicates, masked joins, addresses, exports and their dependencies. The source-built controls distinguish dead and live results and preserve invalid modifier, unbound operand and early wait refusals. Tested revision: `677927084bcf2091c86d4fc510a716b460d5fced` on upstream `1a0e506d30d`. - `python -B tests/pixel_aot_check.py` (Apple Silicon macOS, Python 3.15): exit 0, all portable controls passed. - `git diff --check 1a0e506d30d HEAD`: exit 0. - On the immediately preceding audited base, the `binary` lane with LLVM 23 stopped at the unchanged `check_f16_round_binary` exact encoding assertion for `v_ceil_f16_e64 v1, v2` (actual `0100dcd502010102`). The documented LLVM15 toolchain is unavailable locally; the supported LLVM15 binary lane and Windows GPU/CI validation remain pending. No fixture or coverage was weakened and no new rendering/benchmark claims are made.
tedin7 commented 2026-11-25 19:03:58 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T18:58:06Z.

Review: COMMENTED


Review of head 677927084 (comment only, no merge yet).

What I checked (Linux, worktree on this exact head):

  • python3 -B tests/pixel_aot_check.py: exit 0.
  • python3 tests/docs_links_check.py, python3 tests/bidi_controls_check.py, git diff --check origin/main...HEAD: all clean.
  • Mutation 1: skip the discard call (if False and dead_integer_candidates): the new check fails. Good.
  • Mutation 2: drop liveness growth (live.update(...) replaced by pass): fails with the asuint(alu20) assertion. Good.
  • Mutation 3: remove retained.reverse() in discard_dead_integer_temporaries: the whole suite still exits 0. This is a real gap.

Finding (blocks merge until fixed):

  • tests/pixel_aot_check.py check_dead_integer_temporaries uses only presence checks (exists, in source). Nothing checks the order of the kept lines. Without reverse(), the output has uses before declarations, which is an invalid shader. Please assert that each kept salu/alu declaration appears before the first line that uses it (for example compare source.index(decl) with source.index(use) for both live chains). This agrees with the earlier mutation review in this thread.
  • Small hardening: first = next(iter(candidates)) depends on dict insertion order. min(candidates) gives the same value today and is safe if an emitter ever marks out of order.

Also open: the branch is 22 commits behind main (limit is 20), and there is no Win2025 WARP receipt for this head yet. After the test fix I can run update-branch, CI and Win2025 dev+release. The change itself (dead-code removal after validation, liveness rooted at all unmarked lines) looks correct to me.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6063290611 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2479#pullrequestreview-6063290611). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T18:58:06Z. **Review:** COMMENTED --- Review of head 677927084 (comment only, no merge yet). What I checked (Linux, worktree on this exact head): - `python3 -B tests/pixel_aot_check.py`: exit 0. - `python3 tests/docs_links_check.py`, `python3 tests/bidi_controls_check.py`, `git diff --check origin/main...HEAD`: all clean. - Mutation 1: skip the discard call (`if False and dead_integer_candidates`): the new check fails. Good. - Mutation 2: drop liveness growth (`live.update(...)` replaced by `pass`): fails with the `asuint(alu20)` assertion. Good. - Mutation 3: remove `retained.reverse()` in `discard_dead_integer_temporaries`: the whole suite still exits 0. This is a real gap. Finding (blocks merge until fixed): - `tests/pixel_aot_check.py` `check_dead_integer_temporaries` uses only presence checks (`exists`, `in source`). Nothing checks the order of the kept lines. Without `reverse()`, the output has uses before declarations, which is an invalid shader. Please assert that each kept `salu`/`alu` declaration appears before the first line that uses it (for example compare `source.index(decl)` with `source.index(use)` for both live chains). This agrees with the earlier mutation review in this thread. - Small hardening: `first = next(iter(candidates))` depends on dict insertion order. `min(candidates)` gives the same value today and is safe if an emitter ever marks out of order. Also open: the branch is 22 commits behind main (limit is 20), and there is no Win2025 WARP receipt for this head yet. After the test fix I can run update-branch, CI and Win2025 dev+release. The change itself (dead-code removal after validation, liveness rooted at all unmarked lines) looks correct to me. AI-assisted; commands listed were executed locally.
ChazY11 commented 2026-11-25 19:04:12 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by ChazY11 on 2026-11-25T18:18:27Z.


Five mutations: four caught, and the survivor is a real gap the fixture's assertion style cannot see

Baseline: check_dead_integer_temporaries passes, and it is wired into _CONTROL_SUBCHECKS (line 18822), which the controls runner executes — worth saying because I checked rather than assumed; a new subcheck that is defined but never listed would pass by never running.

mutation of discard_dead_integer_temporaries result
liveness never grows (live.update(...) → pass, so every marked line is dropped) caught
the skip is inverted (name not in live → name in live) caught
INTEGER_TEMPORARY stops matching salu (only alu) caught
the backward scan starts at 0 instead of the first candidate caught
retained.reverse() removed survived

The survivor is not equivalent — I checked before saying so

Calling the helper directly on five lines with two dead candidates:

with reverse:      ['decl0 = 1', 'use(decl0)', 'end(decl0)']      order preserved
without reverse:   ['decl0 = 1', 'end(decl0)', 'use(decl0)']      use after the line that used it

So the mutation changes the emitted order — use now precedes nothing it depends on. That is a genuine behavioural change, and the fixture cannot see it because every assertion in the new case is a presence test:

def exists(source, name):
    return any(name in line for line in source.splitlines())
...
assert not exists(source, declaration(dead, instruction, stem))
assert f"salu{live.index(scalar[-1])} != 0u" in source

exists, in source, and source.count(".Sample(") == 1 are all order-insensitive. A one-line fix closes it: after translate_int(live), assert that each retained declaration precedes the first line that mentions it — e.g. compare source.index(name) against source.index(use) for the two retained chains, or assert the emitted salu…/alu… indices are strictly increasing.

This matters more than a typical unasserted detail: the helper rewrites a whole statement list after validation, so a reversed result is not a wrong value but a structurally invalid program — the pure-Python control is the only place that can catch it before a renderer does, and right now it cannot.

What the four caught rows establish

They are the four ways this helper can go wrong in principle: drop too much (liveness never grows), drop exactly the wrong half (skip inverted), miss one naming scheme (salu vs alu — the two emitters at pixel_aot.py:4347 and :5240), and start scanning before the marked region. Each is caught, so the fixture is testing the algorithm and not just the happy path. The two-emitter case is the one I would have expected to slip, since salu and alu come from different call sites.

One note on the docstring

"Remove only emitter-marked, single-assignment locals after validation" is the right contract, but first = next(iter(candidates)) relies on dict insertion order matching emission order — a fact stated only in a comment ("Emit sites mark candidates in line order"). If a future emitter marks out of order, first silently becomes the later index and earlier dead lines are kept. Cheap hardening: first = min(candidates), which is the same value today and no longer depends on insertion order.

AI-assisted; the five mutations and the order probe were run locally on Windows 11 build 26300.9974.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7170728543 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2479#issuecomment-7170728543). Originally posted by [ChazY11](https://github.com/ChazY11) on 2026-11-25T18:18:27Z. --- ## Five mutations: four caught, and the survivor is a real gap the fixture's assertion style cannot see Baseline: `check_dead_integer_temporaries` passes, and it *is* wired into `_CONTROL_SUBCHECKS` (line 18822), which the controls runner executes — worth saying because I checked rather than assumed; a new subcheck that is defined but never listed would pass by never running. | mutation of `discard_dead_integer_temporaries` | result | |---|---| | liveness never grows (`live.update(...)` → `pass`, so every marked line is dropped) | **caught** | | the skip is inverted (`name not in live` → `name in live`) | **caught** | | `INTEGER_TEMPORARY` stops matching `salu` (only `alu`) | **caught** | | the backward scan starts at 0 instead of the first candidate | **caught** | | `retained.reverse()` removed | **survived** | ### The survivor is not equivalent — I checked before saying so Calling the helper directly on five lines with two dead candidates: ```text with reverse: ['decl0 = 1', 'use(decl0)', 'end(decl0)'] order preserved without reverse: ['decl0 = 1', 'end(decl0)', 'use(decl0)'] use after the line that used it ``` So the mutation changes the emitted order — `use` now precedes nothing it depends on. That is a genuine behavioural change, and the fixture cannot see it because every assertion in the new case is a presence test: ```python def exists(source, name): return any(name in line for line in source.splitlines()) ... assert not exists(source, declaration(dead, instruction, stem)) assert f"salu{live.index(scalar[-1])} != 0u" in source ``` `exists`, `in source`, and `source.count(".Sample(") == 1` are all order-insensitive. A one-line fix closes it: after `translate_int(live)`, assert that each retained declaration precedes the first line that mentions it — e.g. compare `source.index(name)` against `source.index(use)` for the two retained chains, or assert the emitted `salu…`/`alu…` indices are strictly increasing. This matters more than a typical unasserted detail: the helper rewrites a whole statement list after validation, so a reversed result is not a wrong value but a **structurally invalid program** — the pure-Python control is the only place that can catch it before a renderer does, and right now it cannot. ### What the four caught rows establish They are the four ways this helper can go wrong in principle: drop too much (liveness never grows), drop exactly the wrong half (skip inverted), miss one naming scheme (`salu` vs `alu` — the two emitters at `pixel_aot.py:4347` and `:5240`), and start scanning before the marked region. Each is caught, so the fixture is testing the algorithm and not just the happy path. The two-emitter case is the one I would have expected to slip, since `salu` and `alu` come from different call sites. ### One note on the docstring "Remove only emitter-marked, single-assignment locals after validation" is the right contract, but `first = next(iter(candidates))` relies on dict insertion order matching emission order — a fact stated only in a comment ("Emit sites mark candidates in line order"). If a future emitter marks out of order, `first` silently becomes the later index and earlier dead lines are kept. Cheap hardening: `first = min(candidates)`, which is the same value today and no longer depends on insertion order. AI-assisted; the five mutations and the order probe were run locally on Windows 11 build 26300.9974.
upstream-sync closed this pull request 2026-11-26 00:00:46 +00:00
Sign in to join this conversation.
No reviewers
No labels
No milestone
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Reference
R0Y00/Xbox2Windows!2471
No description provided.