heap_index_census: fix s_lshlK_add, SMEM offset:, x16/back-branch roles, and JSON I/O (HEAP-INDEX-CENSUS-DATAFLOW-AND-IO) #1551

Merged
leonida/mandy
quietfold merged 1 commit from fix/heap-index-census-dataflow-io into main 2026-11-28 10:46:21 +00:00

Pull request successfully merged and closed

quietfold commented 2026-11-25 04:18:09 +00:00

What

Fix four dataflow/role-classification bugs and harden index/JSON I/O in tools/heap_index_census.py:

  1. s_lshlK_add_u32 misclassified heap bases and shifted indices (step):
    • In s_lshlK_add_u32 d, idx, base, a[1] (idx) is shifted left by K bits and is always a scaled index, while only a[2] (base) can be a base pointer.
    • Because LSHL_ADD_SHIFT shared the ADDS branch, s_lshl4_add_u32 s2, s5, s8 (dynamic input index s5 + input heap base s8) saw _pointerish(ty) == True and dropped s2 to unknown (losing both user s8 and dynamic), while s_lshl4_add_u32 s2, s5, 0x20 misclassified the shifted index s5 as a base pointer with a static offset.
    • Handle LSHL_ADD_SHIFT separately (matching shader_meta.py): fold when both operands are constant, else propagate ("off", tbase, cidx is None) whenever a[2] is pointerish, and never promote the shifted index a[1] to a base pointer.
  2. SMEM inline offset:N modifiers were ignored (step):
    • Dual-offset SMEM loads such as s_load_dwordx8 s[20:27], s[8:9], null offset:0x24 carry the byte offset in ins["mods"] (offset:0x24), so ignoring it recorded static offset 0 (aligned32, max: 0) instead of 0x24 (other, max: 0x24).
    • Parse offset:N from ins["mods"] and add it to constant soffset operands (marking malformed offset: modifiers dynamic).
  3. Sub-descriptor slices and backward-branch consumers dropped load roles (analyse):
    • on_use checked tag[2] == 0, dropping roles for 4-dword-aligned sub-descriptors loaded at dwords 4/8/12 of s_load_dwordx8/s_load_dwordx16 (e.g. a T# at s[16:23] + S# at s[24:27] from one s_load_dwordx16). Check tag[2] % 4 == 0.
    • on_use checked tag[1] in loads during a single PC-order pass over blocks, dropping roles whenever a consumer block lay at a lower PC than its s_load_dwordx* block (backward branch / loop). Collect uses in a defaultdict(set) and attach them to loads after scanning all blocks.
  4. Input validation and atomic JSON output (stage_index, census, main):
    • Decode index.json with utf-8-sig and validate its list/row schema (file ending in .dxbc, non-empty stage).
    • Filter .s entries to regular files and count unreadable/malformed .s listings under skipped["unreadable listing"] instead of aborting the run.
    • Reject empty/whitespace/directory --json paths upfront before scanning, and write --json atomically via a sibling temp file (newline="\n", file_mode.published_mode, replace_retry.replace, allow_nan=False).

Claimed in the coordination issue as

HEAP-INDEX-CENSUS-DATAFLOW-AND-IO — verified 0 open PRs and 0 prior claims; unable to post a comment on #14 because GitHub disabled commenting once #14 reached its 2,500-comment cap (and no successor "Coordinating who works on what" issue is open yet).

Testing

  • python3 -I -W error tests/test_heap_index_census.py -v: 17/17 OK (including 4 new regression tests).

  • python3 -I tests/test_text_write_line_endings.py: 3/3 OK.

  • python3 -I scripts/check_no_game_data.py tools/heap_index_census.py tests/test_heap_index_census.py: clean.

  • python3 -m compileall -q tools/heap_index_census.py tests/test_heap_index_census.py: clean.

  • Mutation check against unpatched main:tools/heap_index_census.py: all 4 new tests fail on main (FAILED (failures=3, errors=1)).

  • AI-assisted: yes

  • GPUs tested: none (CPU-only static shader census tests on macOS; no GPU or game files needed)

## What Fix four dataflow/role-classification bugs and harden index/JSON I/O in `tools/heap_index_census.py`: 1. **`s_lshlK_add_u32` misclassified heap bases and shifted indices (`step`)**: - In `s_lshlK_add_u32 d, idx, base`, `a[1]` (`idx`) is shifted left by `K` bits and is always a scaled index, while only `a[2]` (`base`) can be a base pointer. - Because `LSHL_ADD_SHIFT` shared the `ADDS` branch, `s_lshl4_add_u32 s2, s5, s8` (dynamic input index `s5` + input heap base `s8`) saw `_pointerish(ty) == True` and dropped `s2` to `unknown` (losing both `user s8` and `dynamic`), while `s_lshl4_add_u32 s2, s5, 0x20` misclassified the shifted index `s5` as a base pointer with a static offset. - Handle `LSHL_ADD_SHIFT` separately (matching `shader_meta.py`): fold when both operands are constant, else propagate `("off", tbase, cidx is None)` whenever `a[2]` is pointerish, and never promote the shifted index `a[1]` to a base pointer. 2. **SMEM inline `offset:N` modifiers were ignored (`step`)**: - Dual-offset SMEM loads such as `s_load_dwordx8 s[20:27], s[8:9], null offset:0x24` carry the byte offset in `ins["mods"]` (`offset:0x24`), so ignoring it recorded static offset `0` (`aligned32`, `max: 0`) instead of `0x24` (`other`, `max: 0x24`). - Parse `offset:N` from `ins["mods"]` and add it to constant `soffset` operands (marking malformed `offset:` modifiers dynamic). 3. **Sub-descriptor slices and backward-branch consumers dropped load roles (`analyse`)**: - `on_use` checked `tag[2] == 0`, dropping roles for 4-dword-aligned sub-descriptors loaded at dwords 4/8/12 of `s_load_dwordx8`/`s_load_dwordx16` (e.g. a `T#` at `s[16:23]` + `S#` at `s[24:27]` from one `s_load_dwordx16`). Check `tag[2] % 4 == 0`. - `on_use` checked `tag[1] in loads` during a single PC-order pass over blocks, dropping roles whenever a consumer block lay at a lower PC than its `s_load_dwordx*` block (backward branch / loop). Collect `uses` in a `defaultdict(set)` and attach them to `loads` after scanning all blocks. 4. **Input validation and atomic JSON output (`stage_index`, `census`, `main`)**: - Decode `index.json` with `utf-8-sig` and validate its list/row schema (`file` ending in `.dxbc`, non-empty `stage`). - Filter `.s` entries to regular files and count unreadable/malformed `.s` listings under `skipped["unreadable listing"]` instead of aborting the run. - Reject empty/whitespace/directory `--json` paths upfront before scanning, and write `--json` atomically via a sibling temp file (`newline="\n"`, `file_mode.published_mode`, `replace_retry.replace`, `allow_nan=False`). ## Claimed in the coordination issue as `HEAP-INDEX-CENSUS-DATAFLOW-AND-IO` — verified 0 open PRs and 0 prior claims; unable to post a comment on `#14` because GitHub disabled commenting once `#14` reached its 2,500-comment cap (and no successor `"Coordinating who works on what"` issue is open yet). ## Testing - `python3 -I -W error tests/test_heap_index_census.py -v`: **17/17 OK** (including 4 new regression tests). - `python3 -I tests/test_text_write_line_endings.py`: **3/3 OK**. - `python3 -I scripts/check_no_game_data.py tools/heap_index_census.py tests/test_heap_index_census.py`: clean. - `python3 -m compileall -q tools/heap_index_census.py tests/test_heap_index_census.py`: clean. - Mutation check against unpatched `main:tools/heap_index_census.py`: all 4 new tests fail on `main` (`FAILED (failures=3, errors=1)`). - AI-assisted: yes - GPUs tested: none (CPU-only static shader census tests on macOS; no GPU or game files needed)
copilot-pull-request-reviewer[bot] reviewed 2026-11-25 04:18:18 +00:00
copilot-pull-request-reviewer[bot] left a comment
No description provided.
Copilot was unable to review this pull request because the user who requested the review has insufficient remaining quota. Try requesting a review at a lower effort level.
MoonEyes commented 2026-11-28 10:46:17 +00:00

Red/green: the PR's tests fail on main and pass with this PR (Linux, Python 3.13.18).
Targeted batch of 19 PRs (their tests, the tests importing the changed modules, the docs tests) on main 3ca0707: no new failure, Linux / Python 3.13.
AI-assisted (Claude Code, Claude Opus 5.5)

Red/green: the PR's tests fail on main and pass with this PR (Linux, Python 3.13.18). Targeted batch of 19 PRs (their tests, the tests importing the changed modules, the docs tests) on main 3ca0707: no new failure, Linux / Python 3.13. AI-assisted (Claude Code, Claude Opus 5.5)
Sign in to join this conversation.
No description provided.