Repository navigation
startup: lower v_swap_b32 in gfx2hlsl - #1995
Conversation
One of the refusals in the R0Y00#1723 census (2 pairs). Both VGPRs take the other's old value: the swap reads both sources before writing either, through a temporary, and keeps the uniform flag with the moved value. The RDNA 2 ISA (VOP1 opcode 101) lists no input or output modifiers and no DPP or SDWA form for it; LLVM 15 rejects those spellings, and the translator refuses them. New device-free check startup_gfx2hlsl_swap. AI-assisted (Claude Code). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Ran it and broke the swap four ways — all caughtWindows 11 build 26300.9974, device-free: out/pe-env/Scripts/python.exe -B tests/startup_gfx2hlsl_swap_check.py
control: "write before read" fails the fixtures (6 of 7): ok
control: "one destination" fails the fixtures (6 of 7): ok
v_swap_b32 checks: 0 failed exit 0
The first two are the same mistakes the fixture already names as its own controls, which is a good sign: your controls and my mutations agree on what On the uniformity rule
What the guard costs
Scope
VerdictReviewed. Four independent breakages, four failures, and the uniformity rule travels with the values as intended. Notes
|
Your commit
|
AI-assisted (Claude Code). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Correction: my previous comment was wrong — your commit is not already in
|
Merge matrix for the 16 open PRs that touch
|
| pair | overlap | what it is |
|---|---|---|
| #2007 vs #2003 | 923–955 | both add op_s_bfm_b64 |
| #2006 vs #2005 | 87–88 | both extend FETCH_FORMATS (10-10-10-2 UNORM vs 16-16 SNORM) |
But line overlap is only half the story
I merged the overlapping pairs, and then a pair that does not overlap:
#2006 + #2005 conflict: CMakeLists.txt
#2003 + #2007 conflict: AGENTS.md, tests/startup_gfx2hlsl_bfm_b64_check.py (AA), tools/startup/gfx2hlsl.py
#2012 + #1995 order-dependent:
merge 2012 then 1995 -> conflict only in CMakeLists.txt, gfx2hlsl.py merges to ONE op_v_swap_b32
merge 1995 then 2012 -> conflicts in CMakeLists.txt, tests/..._swap_check.py (AA), gfx2hlsl.py
and then BOTH implementations are present in that file
#2012 and #1995 add the same method at lines 1272 and 1304 — far apart, so nothing overlaps, yet they are the same feature. In one merge order
git silently keeps a single definition (one author's behaviour is lost with no marker); in the other it keeps both. Neither outcome is a rebase of
the other, and the reviewer would have to notice by reading the file.
So: line-overlap predicts textual conflicts, not duplicate additions. For a file where 16 people are each adding one handler, the dangerous
case is the one this matrix does not flag, and the two duplicate pairs above (#1995/#2012 on v_swap_b32, #2003/#2007 on s_bfm_b64) are
exactly that.
What I would do with this
- Land one of each duplicate pair first, and tell the other author to rebase onto it (I have already reviewed startup: lower s_bfm_b64 in gfx2hlsl #2007 at behaviour level and startup: lower v_swap_b32 in gfx2hlsl #1995
the same way, so both are safe choices). - For
#2006/#2005, whichever goes second needs a one-line rebase of two adjacent dict entries — trivial, but it will be a conflict rather
than a merge. - Everything else in the table is disjoint: any order among the remaining 12 lands without touching another PR's lines.
The script is 40 lines (merge-base, git diff -U0, range intersection) if you want it as a CI job — but a cheaper version is just "search the
open PR titles for the mnemonic", which would have caught both duplicates before either branch existed.
Notes
- AI-assisted analysis, computed on
main7f149ac9.
Refs #1723
Change
tools/startup/gfx2hlsl.pynow lowersv_swap_b32. It is one of the refusals in the #1723 census (2 pairs).op_v_swap_b32emits{ uint t = vA; vA = vB; vB = t; }, so both sources are read before either one is written. Whenexecis unknown, the swap is guarded withif (exec & 1), as the neighbouring lane ops are.used_vis updated. A uniform flag moves with its value and is dropped whenexecis unknown.V_SWAP_B32among the instructions that cannot use DPP or SDWA. The edge cases follow thepixel_aotlowering from shader: lower v_swap_b32 in pixel_aot #771.v_swap_b32 v1, v2as02 cb 02 7e, the self-swapv3, v3andv255, v0for gfx1013. It rejects_e64,_dpp,_sdwa,clamp, negation, SGPR and constant sources, and pairs.omod,op_seland the VOP3A form, which the decoder already marks unsupported.Test
New device-free check
tests/startup_gfx2hlsl_swap_check.py, registered asstartup_gfx2hlsl_swapand listed in the pure-Python job andAGENTS.md. A short note is added todocs/experiments.md.v255, v0. The emitted text is evaluated and compared with a reference list swap.Unsupportedcases.main'sgfx2hlsl.pyit fails withUnsupported: v_swap_b32.Results:
e63721f9, alltests/startup_gfx2hlsl_*_check.py,tests/startup_translator_check.pyandtests/docs_links_check.pypass.verify.pyon the base1d825c18:form_coverage,rdna2_tools,pso_readiness,docs_linksand the LLVM 15 binary round trip passed;startup_view_heap_hardware(shortcut logged -1 times, expected 1). It fails the same way onmainat1d825c18without this change and passed at387bdaf5, on an RTX 3080 (32.0.16.2124, Windows 11 build 26200). I'm narrowing it down separately.The check evaluates the emitted HLSL in Python. It does not compile it or draw with it.
AI-assisted (Claude Code).
🤖 Generated with Claude Code