Repository navigation
rdna2spirv, lane_masks: handle special/mask destinations in s_cmov_b32, s_cmovk_i32, and s_movk_i32 (SHADER-CMOV32-MASK-AND-DST) - #2011
Conversation
…s_cmov_b32, s_cmovk_i32, and s_movk_i32
xel1uz
left a comment
There was a problem hiding this comment.
Approving 8fbcc22b. I verified it on main 747809e (merged cleanly).
- Reading:
s_cmov_b32/s_cmovk_i32now go through the existing 32-bit mask helpers (_mask_b32_dst_half,_mask_b32_src,_store_b32_mask_dst) instead of refusing every non-SGPR destination.nullis a no-op, andlane_masks.stepgains the matching rules, includingEITHERfors_movk_i32of 0 / 0xffff. The sign extension ofs_cmovk_i32's immediate moved into animmoperand, andtests/semantic/test_salu_cmov.py(negative immediates included) still passes in the suite. - Own tests:
tests/semantic/test_cmov32_mask_and_dst.pyis OK. - Bite check: with
main'stools/rdna2spirv.pyandtools/lane_masks.pyit fails (8 failures, 2 errors). - Whole translator suite: 492 files, 6,316 tests, 0 files failed. This includes
test_salu_b32_lane_masks.pyandtest_wave64_vcc_half_write.py.
Ubuntu 26.04, Python 3.14, LLVM 21.1.8, SPIRV-Tools 2026.1.
AI-assisted review, CPU only.
|
#2011 | head 8fbcc22 (merged cleanly with main 039870e) | Audited |
|
Physical RADV gfx906 (Mesa 26.0.8, fixed subgroup 64), with synchronization validation enabled. I used the same nine synthetic shaders, two input patterns and both SCC values against main Main translated five shaders: 8/20 dispatches matched an independent integer oracle; the other 12 completed but returned 2,560 wrong words. The four remaining shaders were refused before dispatch (VCC, EXEC, and M0/null conditional destinations), not GPU failures. The merge translated all nine and passed 36/36 readbacks with no wrong words, guard writes, or validation errors. The data failures on main included a correct selected SGPR mask followed by a wrong population count, and AI-assisted. |
Claimed in #1608 as
SHADER-CMOV32-MASK-AND-DST.What and why
s_cmov_b32ands_cmovk_i32(D = SCC ? S0 : D, SCC read and not written) intools/rdna2spirv.pypreviously restricted the destination to plain SGPRs (if a[0]["k"] != "sgpr": raise Unsupported(...)), rejectingexec_lo,exec_hi,vcc_lo,vcc_hi,m0, andnulleven though all are valid 32-bitSDSTencodings in RDNA2 SOP1/SOPK.tools/lane_masks.pyalso had no rules fors_cmov_b32,s_cmovk_i32, ors_movk_i32:s_cmov_b32/s_cmovk_i32targeting a lane-mask SGPR (from another mask or0/-1) cleared its lane-mask tag, causing later whole-wave readers likes_bcnt1_i32_b32to read a per-lane bool (0xFFFFFFFF/0) as scalar data (32or0) instead of the wave's popcount.s_movk_i32writing0or-1(0xffff) did not recordEITHER, so:s_movk_i32 vcc_lo, 0/-1failedvcc_half_keeps_mask()and overwrote the whole%vcc(wipingvcc_hi), whiles_movk_i32 vcc_hi, 0/-1only stored%vcc_hiwithout updating lanes32..63of%vcc.s_movk_i32 sN, 0/-1on one path and a lane mask on the other droppedsNfrom the lane-mask state.s_cmov_b32ands_cmovk_i32through the existing 32-bit mask helpers (_mask_b32_dst_half/_mask_b32_src/_store_b32_mask_dst) and modelings_movk_i32/s_cmov_b32/s_cmovk_i32inlane_masks.stepfixes all four cases cleanly.Scalar select and packcontract row indocs/design.md.Testing
tests/semantic/test_cmov32_mask_and_dst.py— testss_cmov_b32/s_cmovk_i32intoexec_lo/exec_hi(wave32 and wave64, cross-halfexec_lo <- vcc_hi, untouched-half preservation),vcc_lo/vcc_hi,m0,null, lane-mask SGPRs (withs_bcnt1_i32_b32), ands_movk_i32wave64vcc_lo/vcc_hihalf-writes + CFG merge.origin/main:tests/semantic/test_cmov32_mask_and_dst.pyfails withFAILED (failures=8, errors=2)(provingUnsupportedonexec/vcc/m0/null, brokens_bcnt1returning32/0afters_cmov_b32/s_cmovk_i32on mask SGPRs, and broken wave64s_movk_i32 vcc_lo/vcc_hihalf-writes + CFG merge).python -I tests/semantic/test_cmov32_mask_and_dst.py -v(4/4 OK)python -m unittest discover -s tests/semantic -p test_salu_cmov.py(5/5 OK)python -m unittest discover -s tests/semantic -p test_salu_b32_lane_masks.py(9 ran, OK, 1 skipped)python -m unittest discover -s tests/semantic -p test_wave64_vcc_half_write.py(7/7 OK)python -m unittest discover -s tests/semantic -p test_scalar_alu_imm_bitset.py(17/17 OK)python -m unittest discover -s tests -p "test_docs_*.py"(50/50 OK)python -I tests/test_text_write_line_endings.py(3/3 OK)python -m compileall -q tools/rdna2spirv.py tools/lane_masks.py tests/semantic/test_cmov32_mask_and_dst.pypython -I scripts/check_no_game_data.py tools/rdna2spirv.py tools/lane_masks.py docs/design.md tests/semantic/test_cmov32_mask_and_dst.pygit diff --check