mesh: read a back-edge branch offset as LLVM 15 prints it #2277

Merged
NiiRoZz merged 1 commit from upstream-pr/2285 into main 2026-11-25 10:17:37 +00:00
NiiRoZz commented 2026-11-25 10:07:04 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by NiiRoZz on 2026-11-25T10:07:04Z.


Change

LLVM 15 prints a negative branch SIMM16 unsigned: s_branch 65535 is a branch
to itself, s_cbranch_scc1 65533 jumps three words back. Wave.exec_range in
tools/mesh_entry_aot.py added the operand as a positive word count, so a
decoded back-edge raised KeyError from the jump table instead of the named
refusal "Expected a forward mesh branch". The existing refusal test spells the
back-edge s_branch -1, which the disassembler never prints.

The three places that read a branch operand (the main loop, the descriptor
join and the s_branch that ends its first arm) now go through one helper that
sign-extends the 16-bit operand. Both spellings give the same named refusal.
Nothing new is lowered: a back-edge is still refused.

Part of #1998 (item I, found while preparing the loop census).

Verification

Branch fix/mesh-backedge-offset-sign, one commit on main 19509ee4.

python -B tests/mesh_dynamic_aot_check.py
python -B tests/mesh_scc_any_lane_check.py
python -B tests/mesh_dynamic_geometry_check.py
python -B tests/mesh_join_descriptor_check.py
python -B tests/mesh_heap_sampler_check.py
python -B tests/mesh_lane_spill_check.py
python -B tests/mesh_entry_check.py skipped

All seven exit 0. With tools/mesh_entry_aot.py from main 19509ee4 and the new
test line in place, tests/mesh_dynamic_aot_check.py fails with
KeyError: 262192 at target = jumps[offset + 4 + 4 * int(tail)].

The unsigned spelling was observed with LLVM 15 llvm-mc --disassemble -arch=amdgcn -mcpu=gfx1013 on two hand-assembled branches:
0xfe 0xff 0x85 0xbf prints s_cbranch_scc1 65534 and 0xfd 0xff 0x82 0xbf
prints s_branch 65533.

Not run: the binary modes that load the LLVM C library (no libLLVM on this
machine), the D3D12 draw tests and CMake/ctest.

Evidence and follow-up

  • The new test line edits the decoded text of the existing source-built
    runtime-geometry fixture; no new bytes.
  • Assumption: the LLVM C library disassembler, which the lowerers call, prints
    the same spelling as llvm-mc. Both use the same instruction printer; only
    llvm-mc was run here.
  • Not covered: a latch that is s_cbranch_execnz or s_cbranch_vccz is not in
    the branch table of exec_range and still raises KeyError instead of a
    named refusal. A branch target off an instruction boundary also raises
    KeyError. Both are separate behaviors and can be picked up by anyone.

Checklist

  • This pull request covers one reviewable behavior.
  • I included the exact command and result for every check I ran.
  • I considered a negative control or failure case for a new fixture.
  • I updated README/docs when a capability or build requirement changed. (No capability or build requirement changes.)
  • I did not include game files, dumps, distribution links or secrets.

AI-assisted (Claude Code).

🤖 Generated with Claude Code

<!-- greyfinch-sync:R0Y00/Xbox2Windows:issue:6602012124 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2285). Originally posted by [NiiRoZz](https://github.com/NiiRoZz) on 2026-11-25T10:07:04Z. --- ## Change LLVM 15 prints a negative branch SIMM16 unsigned: `s_branch 65535` is a branch to itself, `s_cbranch_scc1 65533` jumps three words back. `Wave.exec_range` in `tools/mesh_entry_aot.py` added the operand as a positive word count, so a decoded back-edge raised `KeyError` from the jump table instead of the named refusal "Expected a forward mesh branch". The existing refusal test spells the back-edge `s_branch -1`, which the disassembler never prints. The three places that read a branch operand (the main loop, the descriptor join and the `s_branch` that ends its first arm) now go through one helper that sign-extends the 16-bit operand. Both spellings give the same named refusal. Nothing new is lowered: a back-edge is still refused. Part of #1998 (item I, found while preparing the loop census). ## Verification Branch `fix/mesh-backedge-offset-sign`, one commit on `main` 19509ee4. ```text python -B tests/mesh_dynamic_aot_check.py python -B tests/mesh_scc_any_lane_check.py python -B tests/mesh_dynamic_geometry_check.py python -B tests/mesh_join_descriptor_check.py python -B tests/mesh_heap_sampler_check.py python -B tests/mesh_lane_spill_check.py python -B tests/mesh_entry_check.py skipped ``` All seven exit 0. With `tools/mesh_entry_aot.py` from `main` 19509ee4 and the new test line in place, `tests/mesh_dynamic_aot_check.py` fails with `KeyError: 262192` at `target = jumps[offset + 4 + 4 * int(tail)]`. The unsigned spelling was observed with LLVM 15 `llvm-mc --disassemble -arch=amdgcn -mcpu=gfx1013` on two hand-assembled branches: `0xfe 0xff 0x85 0xbf` prints `s_cbranch_scc1 65534` and `0xfd 0xff 0x82 0xbf` prints `s_branch 65533`. Not run: the `binary` modes that load the LLVM C library (no libLLVM on this machine), the D3D12 draw tests and CMake/ctest. ## Evidence and follow-up - The new test line edits the decoded text of the existing source-built runtime-geometry fixture; no new bytes. - Assumption: the LLVM C library disassembler, which the lowerers call, prints the same spelling as `llvm-mc`. Both use the same instruction printer; only `llvm-mc` was run here. - Not covered: a latch that is `s_cbranch_execnz` or `s_cbranch_vccz` is not in the branch table of `exec_range` and still raises `KeyError` instead of a named refusal. A branch target off an instruction boundary also raises `KeyError`. Both are separate behaviors and can be picked up by anyone. ## Checklist - [x] This pull request covers one reviewable behavior. - [x] I included the exact command and result for every check I ran. - [x] I considered a negative control or failure case for a new fixture. - [ ] I updated README/docs when a capability or build requirement changed. (No capability or build requirement changes.) - [x] I did not include game files, dumps, distribution links or secrets. AI-assisted (Claude Code). 🤖 Generated with [Claude Code](https://claude.com/claude-code)
upstream-sync closed this pull request 2026-11-25 11:02:19 +00:00
tedin7 commented 2026-11-25 11:02:19 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by tedin7 on 2026-11-25T10:11:01Z.

Review: COMMENTED


Review of head deb8643a11f48647365c25c1d5da152316576d44 (2 files, +11/-3). CI green (Linux checks, gfx1013 fixtures, Windows build); mergeable; title neutral; no clean-room concerns.

The sign extension is correct: ((x & 0xFFFF) ^ 0x8000) - 0x8000 maps 65535 to -1 and 65533 to -3, and leaves forward offsets unchanged. All three operand reads now go through branch_target.

Commands executed locally

python3 -B tests/mesh_dynamic_aot_check.py        exit 0
python3 -B tests/mesh_scc_any_lane_check.py       exit 0
python3 -B tests/mesh_dynamic_geometry_check.py   exit 0
python3 -B tests/mesh_join_descriptor_check.py    exit 0
python3 -B tests/mesh_heap_sampler_check.py       exit 0
python3 -B tests/mesh_lane_spill_check.py         exit 0
python3 tests/docs_links_check.py                 exit 0 (435 links)
python3 tests/bidi_controls_check.py              exit 0
git diff --check origin/main...HEAD               clean

Mutations (each reverted afterwards)

  • Remove the sign extension in branch_target (plain int(operand)): killed, KeyError: 262192.
  • Revert the main-loop call (jumps[offset + 4 + 4 * int(tail)]): killed, same KeyError.
  • Revert the join_arms call site (s_cbranch_scc0 operand): SURVIVED, the check still passes.
  • Revert the join s_branch read in join_arms (the join_offset line): SURVIVED, the check still passes.

Findings

  • P1: none.
  • P2 (test gap): tests/mesh_dynamic_aot_check.py:141-143 rewrites the s_cbranch_scc0 itself into s_branch 65535, so only the main-loop read is exercised. The other two call sites changed here (join_arms call with s_cbranch_scc0 <unsigned>, and the arm-ending s_branch <unsigned> that gives join_offset) have no unsigned-spelling coverage, and the mutations above show they can be reverted unnoticed. Suggest two more variants: an s_cbranch_scc0 65533-style back-edge, and the arm-ending s_branch rewritten to a negative unsigned operand. Each should expect "Expected a forward mesh branch".
  • nit: branch_target is the only place that knows the 16-bit wrap, which is good. A one-line note that an operand outside 0..65535 is masked (not rejected) would help a future reader. Not blocking.

AI-assisted; commands listed were executed locally.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:review:6055595321 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2285#pullrequestreview-6055595321). Originally posted by [tedin7](https://github.com/tedin7) on 2026-11-25T10:11:01Z. **Review:** COMMENTED --- Review of head `deb8643a11f48647365c25c1d5da152316576d44` (2 files, +11/-3). CI green (Linux checks, gfx1013 fixtures, Windows build); mergeable; title neutral; no clean-room concerns. The sign extension is correct: `((x & 0xFFFF) ^ 0x8000) - 0x8000` maps 65535 to -1 and 65533 to -3, and leaves forward offsets unchanged. All three operand reads now go through `branch_target`. **Commands executed locally** ```text python3 -B tests/mesh_dynamic_aot_check.py exit 0 python3 -B tests/mesh_scc_any_lane_check.py exit 0 python3 -B tests/mesh_dynamic_geometry_check.py exit 0 python3 -B tests/mesh_join_descriptor_check.py exit 0 python3 -B tests/mesh_heap_sampler_check.py exit 0 python3 -B tests/mesh_lane_spill_check.py exit 0 python3 tests/docs_links_check.py exit 0 (435 links) python3 tests/bidi_controls_check.py exit 0 git diff --check origin/main...HEAD clean ``` **Mutations (each reverted afterwards)** - Remove the sign extension in `branch_target` (plain `int(operand)`): killed, `KeyError: 262192`. - Revert the main-loop call (`jumps[offset + 4 + 4 * int(tail)]`): killed, same `KeyError`. - Revert the `join_arms` call site (`s_cbranch_scc0` operand): SURVIVED, the check still passes. - Revert the join `s_branch` read in `join_arms` (the `join_offset` line): SURVIVED, the check still passes. **Findings** - P1: none. - P2 (test gap): `tests/mesh_dynamic_aot_check.py:141-143` rewrites the `s_cbranch_scc0` itself into `s_branch 65535`, so only the main-loop read is exercised. The other two call sites changed here (`join_arms` call with `s_cbranch_scc0 <unsigned>`, and the arm-ending `s_branch <unsigned>` that gives `join_offset`) have no unsigned-spelling coverage, and the mutations above show they can be reverted unnoticed. Suggest two more variants: an `s_cbranch_scc0 65533`-style back-edge, and the arm-ending `s_branch` rewritten to a negative unsigned operand. Each should expect "Expected a forward mesh branch". - nit: `branch_target` is the only place that knows the 16-bit wrap, which is good. A one-line note that an operand outside 0..65535 is masked (not rejected) would help a future reader. Not blocking. AI-assisted; commands listed were executed locally.
RavenCurseBurg commented 2026-11-25 11:02:29 +00:00 (Migrated from github.com)

Imported from R0Y00/Xbox2Windows. Originally posted by RavenCurseBurg on 2026-11-25T10:21:02Z.


I'll take the two descriptor-join regression tests called out in the review, as a test-only follow-up to #2285. I'll use the existing mesh descriptor fixture with its dynamic SCC and exercise both the conditional split and the branch ending the first arm. For the latter, the wrong unsigned target normally misses the jump table and yields the same refusal as a backward branch. I'll test a case where the wrong target exists, then revert each use of the signed helper separately to verify the tests distinguish them.

<!-- greyfinch-sync:R0Y00/Xbox2Windows:comment:7159574129 --> Imported from [R0Y00/Xbox2Windows](https://github.com/R0Y00/Xbox2Windows/pull/2285#issuecomment-7159574129). Originally posted by [RavenCurseBurg](https://github.com/RavenCurseBurg) on 2026-11-25T10:21:02Z. --- I'll take the two descriptor-join regression tests called out in the review, as a test-only follow-up to #2285. I'll use the existing mesh descriptor fixture with its dynamic SCC and exercise both the conditional split and the branch ending the first arm. For the latter, the wrong unsigned target normally misses the jump table and yields the same refusal as a backward branch. I'll test a case where the wrong target exists, then revert each use of the signed helper separately to verify the tests distinguish them.
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!2277
No description provided.