rdna2spirv: v_writelane_b32 keeps its destination's other lanes in read_before_write_vgprs (OLD-9910, SHADER-768) #658
No reviewers
Labels
No labels
accessibility
bug
documentation
duplicate
enhancement
good first issue
help wanted
invalid
missing claim
needs rebase
question
wontfix
No milestone
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
github/ubiquitarianism--leonida!658
Loading…
Reference in a new issue
No description provided.
Delete branch "gh-pr/658/head"
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?
@LouisRiverstone on GitHub · 2026-11-24 11:10 UTC · original
LouisRiverstone:carry-old-9910→main· +112 −12 · 2 files · 1 commits · merged 2026-11-24 15:50 UTCClaimed in the coordination issue as: OLD-9910 (#14)
Replaces the carried-over draft #175. I'm the original author of old upstream PR 9910.
What and why
SHADER-768:
read_before_write_vgprsintools/rdna2spirv.pytreatedv_writelane_b32as a full write of its destination.v_writelane_b32 vD, sSRC, sLANEwrites one lane ofvDand leaves the other lanes as they were. The translator's own emission already loads the oldvDand selects per lane. So when a shader's first touch of a VGPR is a writelane and it reads that register later, the value from shader entry is read in the lanes that weren't written.Treating every writelane destination as a read goes too far the other way. On the old PR, shdann showed a VS that spills an SGPR into one lane of
v40around the fetch call and reads it back withv_readlane; that VS would be rejected withfetch mapping. So the kept lanes are now carried: they count as a read only when something other thanv_readlane_b32reads the register before a full write.reg_reads_writes(per slice) counts the destination as read.DST_ALSO_READholds the accumulating ops that both functions used to list separately.Known approximation, also written in the docstring: a
v_readlaneof a lane the writelane didn't write reads the entry value, and that read isn't counted.Diff: the old branch's final tree diff applied on current
main(21625bca8), one commit. It applied cleanly.main'sv_swap_b32entry and the d16formatexclusion are kept.Tested
python -I tests/semantic/test_writelane_read_before_write.py: 9 tests OK (carried vs used lanes, the readlane spill, a full write ending the carry, shdann's VS spill and PSv0barycentric cases translated end to end).python -I scripts/run_semantic_tests.py tests/semantic: 466 files, 6117 tests, 0 files failed (Linux, Python 3.14.4).python -m compileall -q make_game.py tools tests: OK.GPUs tested: n/a (CPU-only change, no GPU fixture)
AI-assisted: yes (Claude Code)
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed. (n/a: this fixes a register-use analysis, not a translation rule)@GeorgiyDemo on GitHub · 2026-11-24 11:25 UTC · original
Checked
f05bc538on Apple M5 Pro (16-core GPU), macOS 26.7.3 (25G342), againstmaind42773d07:tests/semantic/test_writelane_read_before_write.py: 9 tests OK at this head; the same file againstmain's translator fails 4 of 9 (AssertionError: Items in the second set but not the first), so the new assertions do catch the gap.LEONIDA_W64_EMULATE=1, MoltenVK 1.4.2 (subgroup 4..32), binaries frommain:cs_w64x_writelanePASS, words4660 77 99 2748 0 0 4660 99; same onmainon the same filter, so no regression.llvm-mc 23.1.6, SPIRV-Tools v2026.4. Synthetic fixtures only, no game data. AI-assisted.
@qhukz13 on GitHub · 2026-11-24 11:40 UTC · original · reviewed
Reviewed on head
f05bc5386(Linux, no GPU: CPU only).Checked:
v_readlane_b32turns it into a read-before-write; the DST_ALSO_READ ops and d16 loads on a carried register still count as reads. The otherreg_reads_writesuser (the computed I/J pair check, ~line 16914) is unaffected: a writelane of the p1 register between the ops was already refused throughww.test_writelane_read_before_write.py(9),test_store_liveins.py,test_wave64_halves.py,test_wave64_cross_half.py,test_wave32_lane_select.py,test_sdwa_dst_mask.py,tests/test_vs_input_survey_rbw.py,tests/test_lane_masks.py,tests/test_crosslane_fuzz.py.tools/semantic_mutants.pygives 0 mutants for these lines (it mutates SPIR-V ops and constants, not Python analysis), so I ran six hand-written logic mutations against the new test file:v_readlaneexemption; treating writelane as a full write again; dropping writelane fromreg_reads_writes.carried.difference_update(dst), and carrying a writelane destination even after a full write.r in writtenis checked first, so once a register is written itscarriedmembership never matters; both lines could go, or stay as documentation.lane_readalso matchv_readfirstlane_b32. Treating readfirstlane as a real read is the safe choice (the first active lane need not be the one written), but nothing pins it; one case likerbw("v_writelane_b32 v5, s1, 3", "v_readfirstlane_b32 s6, v5") == {5}would.A possible refinement for the documented approximation, not needed here: when both lane operands are immediates, a
v_readlaneof a different lane than the writelane wrote reads the entry value and could count as a read; the spill pattern always reads back the same lane.Looks good to me.