Repository navigation
shader_meta: count both halves of a wave64 compare mask SDST - #8119
bobcatchris wants to merge 1 commit into
Conversation
shader_disasm decodes wave32, so a wave64 / 64-bit v_cmp or v_cmpx mask destination printed as `sN` actually occupies `sN:sN+1`. Counting only sN made a following s_and_saveexec_b64 s[6:7], s[4:5] look like a read of an undefined s5. Three synthetic operand tests fail on main and pass here; both shader_meta test files OK. No game data. AI-assisted.
tupacfan04
left a comment
There was a problem hiding this comment.
The single-SGPR wave64 fix is right, but explicit pair destinations are double-counted and the wave32 _e64 form regresses.
tools/shader_meta.py:163-165 unconditionally adds a high half for every 64-bit compare:
writes = _sgpr_regs(a[0])
if "_e64" in raw_op or any(t in op for t in ("_u64", "_i64", "_f64", "_b64")):
writes = writes + [r + 1 for r in writes]If a[0] is already a pair (s[10:11], n=2), writes is [10, 11] and becomes [10, 11, 11, 12] — a duplicate s11 and a bogus s12. LLVM shader_disasm uses exactly that pair form for wave64 VOP3 compares (tests/semantic/fixtures/disasm/cs_w64x_saveexec_b64.s:5, cs_wave64_ballot.s:2).
Synthetic repro:
| Form | Base dde82f27e |
PR head |
|---|---|---|
v_cmp_gt_u32_e64 s[10:11], 40, v0 |
[10,11] |
[10,11,11,12] |
v_cmp_gt_u32_e64 s6, 40, v0 |
[6] |
[6,7] |
v_cmp_gt_f32_e64 s4, v0, v1 |
[4] |
[4,5] (intended fix) |
The extra s12 loses a real read: with v_cmp_gt_u32_e64 s[10:11], 40, v0 followed by v_mov_b32_e32 v1, s12, the head reports user_sgpr_reads: []; the pair-correct count reports [{"sgpr": 12, "kind": "const32"}].
Wave32 regression: v_cmp_gt_u32_e64 s6, ... is the wave32 form (tests/semantic/test_saveexec_variants.py:34 uses s[6:7] only when w64); the head writes [6,7] and suppresses a read of s7. analyse_instructions (:482) has no wave-size parameter; rdna2spirv.shader_meta has g.wave64/subgroup_size (tools/rdna2spirv.py:17262) but does not pass it.
Tests: tests/test_shader_meta_operands.py:47-61 always uses sgpr(4) with n=1, so it cannot see the pair form, and it has no wave32 _e64 sN case or full analyse_instructions read-after-write assertion. tests/test_shader_meta_operands.py 7 OK and tests/test_shader_meta.py 27 OK still pass.
Fix: add the high half only when the parsed destination is a single SGPR and the shader is wave64 (len(writes) == 1 prevents the double-count; threading the wave size is needed for the wave32 case). Synthetic only; no game files. AI-assisted (OpenCode).
|
Tested The branch is 117 commits behind The new operand tests do latch the bug — No regressions in the tool suite: Full semantic suite ( For reference, the head's own tree reports 443 files / 5,889 tests, because the missing 117 commits include 4 semantic files on AI-assisted. |
|
AI-assisted independent check of
Two real incoming registers disappear on head. For an explicit pair, |
|
Follow-up after @NiHuShu's comment above: I reproduced the write-set over-count directly on
So when llvm-mc prints the pair explicitly as Second point: Neither case is exercised by the three new tests — they only build single-register SDSTs — so the 7/7 above does not cover them. The suite result stands: no regressions elsewhere on AI-assisted. |
|
Tested
Note: this branch is based on AI-assisted: yes (Claude ran the build and tests; results checked by me). |
|
Tested 9eb213f on Windows 11 (NTFS), Python 3.12.10 (CPU only, no GPU, no game files): fail. The widening depends on the op name, but the mask width is the wave size. It over-counts in wave32 code and does not fix the SDWA form. What I ran:
The comments above already report the first wave32 row and the pair row. These points are new:
Suggested fix: pass I tried this on a copy of
Nit, none blocking:
Overlap: #5862 (shader_meta: decode each block's operands once in analyse_instructions, head 4653338) gives a merge conflict with this PR in AI-assisted (Claude Code). |
|
Tested 9eb213f on RX 5700 XT (RDNA1, gfx1010, RADV NAVI10), Mesa 26.3.1, Linux 6.18: pass
LLVM AI-assisted (Claude Code). |
|
Tested
No game files. AI-assisted (Claude Code). |
Implements ABilenduke's unclaimed part-3 finding on #7333 (checked board and open PRs first; #2231/#4794/#5031 are related but different).
tools/shader_meta.py _split_operands()counted a wave64 / 64-bitv_cmp/v_cmpxmask SDST printed as one SGPR as writing onlysN. Becauseshader_disasmdecodes wave32, the SDST is reallysN:sN+1; a followings_and_saveexec_b64 s[6:7], s[4:5]then looked like a read of an undefineds5in the index, which root_sig_contract treats as a contradiction. The raw opcode is checked for_e64(base_op strips it) plus the 64-bit type suffixes.Tested on Apple M2 / Python 3.13.18: three new synthetic operand tests fail on current main and pass on this head;
python -I tests/test_shader_meta_operands.pyandtests/test_shader_meta.pyOK. No game data.AI-assisted.