mesh: read a back-edge branch offset as LLVM 15 prints it #2277
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/2285"
Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?
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 65535is a branchto itself,
s_cbranch_scc1 65533jumps three words back.Wave.exec_rangeintools/mesh_entry_aot.pyadded the operand as a positive word count, so adecoded back-edge raised
KeyErrorfrom the jump table instead of the namedrefusal "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_branchthat ends its first arm) now go through one helper thatsign-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 onmain19509ee4.All seven exit 0. With
tools/mesh_entry_aot.pyfrommain19509ee4and the newtest line in place,
tests/mesh_dynamic_aot_check.pyfails withKeyError: 262192attarget = jumps[offset + 4 + 4 * int(tail)].The unsigned spelling was observed with LLVM 15
llvm-mc --disassemble -arch=amdgcn -mcpu=gfx1013on two hand-assembled branches:0xfe 0xff 0x85 0xbfprintss_cbranch_scc1 65534and0xfd 0xff 0x82 0xbfprints
s_branch 65533.Not run: the
binarymodes that load the LLVM C library (no libLLVM on thismachine), the D3D12 draw tests and CMake/ctest.
Evidence and follow-up
runtime-geometry fixture; no new bytes.
the same spelling as
llvm-mc. Both use the same instruction printer; onlyllvm-mcwas run here.s_cbranch_execnzors_cbranch_vcczis not inthe branch table of
exec_rangeand still raisesKeyErrorinstead of anamed refusal. A branch target off an instruction boundary also raises
KeyError. Both are separate behaviors and can be picked up by anyone.Checklist
AI-assisted (Claude Code).
🤖 Generated with Claude Code
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) - 0x8000maps 65535 to -1 and 65533 to -3, and leaves forward offsets unchanged. All three operand reads now go throughbranch_target.Commands executed locally
Mutations (each reverted afterwards)
branch_target(plainint(operand)): killed,KeyError: 262192.jumps[offset + 4 + 4 * int(tail)]): killed, sameKeyError.join_armscall site (s_cbranch_scc0operand): SURVIVED, the check still passes.s_branchread injoin_arms(thejoin_offsetline): SURVIVED, the check still passes.Findings
tests/mesh_dynamic_aot_check.py:141-143rewrites thes_cbranch_scc0itself intos_branch 65535, so only the main-loop read is exercised. The other two call sites changed here (join_armscall withs_cbranch_scc0 <unsigned>, and the arm-endings_branch <unsigned>that givesjoin_offset) have no unsigned-spelling coverage, and the mutations above show they can be reverted unnoticed. Suggest two more variants: ans_cbranch_scc0 65533-style back-edge, and the arm-endings_branchrewritten to a negative unsigned operand. Each should expect "Expected a forward mesh branch".branch_targetis 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.
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.