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

Open
opened 2026-11-26 20:21:44 +01:00 by 4ld0 · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/ubiquitarianism/leonida/pull/1551
Author: @IlyassRS3
Created: 11/25/2026
Status: 🔄 Open

Base: main ← Head: fix/heap-index-census-dataflow-io


📝 Commits (1)

  • 581283e heap_index_census: fix s_lshlK_add, SMEM offset:, x16/back-branch roles, and JSON I/O

📊 Changes

2 files changed (+178 additions, -25 deletions)

View changed files

📝 tests/test_heap_index_census.py (+86 -0)
📝 tools/heap_index_census.py (+92 -25)

📄 Description

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)


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/ubiquitarianism/leonida/pull/1551 **Author:** [@IlyassRS3](https://github.com/IlyassRS3) **Created:** 11/25/2026 **Status:** 🔄 Open **Base:** `main` ← **Head:** `fix/heap-index-census-dataflow-io` --- ### 📝 Commits (1) - [`581283e`](https://github.com/ubiquitarianism/leonida/commit/581283eed048a2133d413b459b08b3f4d1eb6ea8) heap_index_census: fix s_lshlK_add, SMEM offset:, x16/back-branch roles, and JSON I/O ### 📊 Changes **2 files changed** (+178 additions, -25 deletions) <details> <summary>View changed files</summary> 📝 `tests/test_heap_index_census.py` (+86 -0) 📝 `tools/heap_index_census.py` (+92 -25) </details> ### 📄 Description ## 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) --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
Sign in to join this conversation.
No labels
bug
pull-request
No milestone
No project
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.

Dependencies

No dependencies set

Reference
starred/leonida#1579
No description provided.