Repository navigation
wave64_halves: fix soundness gaps in RMW, SCC, movrel, s_bfm_b64, and EXEC tracking - #1982
Conversation
… EXEC tracking Closes several soundness gaps where partition-dependent wave64 VS/PS/GS programs could be classified as Tier A or B instead of Tier C: - RMW destinations & s_pack: track in-place read-modify-write sources (s_addk_i32, s_mulk_i32, s_cmovk_i32, s_cmov_b32/b64, s_bitset*, v_*fmac/mac*, v_dot*c*), remove s_pack from NO_DEST, handle v_swap_b32 rank/base/tag/uniformity swap (conservatively unioning under narrowed/elected exec), and attach implicit vcc (len(srcs) == 2), scc (s_cmovk_i32), and m0 (MOVREL_OPS). - SCC tracking: add SCC-preserving scalar ops (s_mul, s_pack, s_sext, s_flbit, s_ff0/ff1, s_brev, s_bfm, s_bitreplicate, s_get_waveid) to SCC_LESS, stop s_ff1_i32_b64 from marking SCC as a wave vote, and keep s_bcnt0_*/s_bcnt1_i32_b32 SCC taint without creating a vote. - s_bfm_b64 & dynamic register indexing: taint s_bfm_b64 with LANE; propagate VGPR/SGPR taint, mask-SGPR/parked-VGPR-mask usage (MASKD | X), elected-lane taint, uniformity/literal invalidation, and stale SGPR checks across v_movrels_b32, s_movrels_b32/b64, v_movreld_b32, v_movrelsd_b32, v_movrelsd_2_b32, and v_swaprel_b32. - EXEC / mask-half rules: check s_*_saveexec_b32 / s_*_wrexec_b32 via mask-half, handle s_andn1_saveexec_b*/s_andn1_wrexec_b*/s_andn2_wrexec_b64 narrowing and destination tokens accurately, evaluate SAVEEXEC source before overwriting dest, and check EXEC presence/operand order in s_and_b64 / s_or_b64 / s_andn2_b64. - Add synthetic regression classification and 1x64-vs-2x32 wave-interpreter execution tests in tests/semantic/test_wave64_halves_soundness.py. Claim: ItsNotRexed#1745 (comment)
Flyander
left a comment
There was a problem hiding this comment.
I found two remaining soundness issues in the wave64 analysis:
-
Dynamic movrel destination taint is incomplete (
tools/wave64_halves.py:617–645). Forv_movreld_b32and related operations, hardware writes to a VGPR selected bydst_base + M0, but this path invalidates the destination range and then propagateswtonly toT[("v", dst_base)]. WithM0 = 1, a value tainted by lane identity can be written to the next VGPR while that register remains untainted in the analysis. A later export can then avoid the required Tier C classification. Please propagate the taint and RNK/BASE tokens to every possible destination, or conservatively refuse dynamic indexed destinations. The current tests cover the zero-offset case only. RDNA2 ISA §6.6 describes the indexed destination behavior: https://www.amd.com/content/dam/amd/en/documents/radeon-tech-docs/instruction-set-architectures/rdna2-shader-instruction-set-architecture.pdf -
ANDN2 is treated as a narrowing EXEC guard (
tools/wave64_halves.py:899–901).narrows()acceptss_andn2_wrexec_b64, but its ISA operation isEXEC = S0 & ~EXEC; it can re-enable lanes outside the old EXEC mask. Sincevote()relies onnarrows()as proof that a VCC branch is safe, this can suppressunsafe-vote-branchand incorrectly classify partition-dependent code.exec_write()already treats ANDN2 as non-narrowing. Please remove both ANDN2 variants from the narrowing proof and recognize the ANDN1 variants whose result is~S0 & EXEC. The opcode semantics are in RDNA2 ISA §12.3 (same manual linked above).
|
Tested 69bd312 on NVIDIA GeForce GTX 1660 (Turing, TU116, subgroup 32..32), driver 620.73.04 (proprietary, Vulkan 1.4.357), Arch Linux (kernel 6.18): pass, no regression. Native build of runtime/ from this head (Ninja, RelWithDebInfo, clang 23.1.5), llvm-mc 23.1.5, SPIRV-Tools v2026.4.
Not covered here: the corpus census ( AI-assisted run (Claude). Synthetic programs only, no game files involved. |
… from narrows() Address @Flyander's review comments on PR ItsNotRexed#1982: - Propagate wt and rank/base tokens (st['r'], st['b']) across every referenced VGPR >= dst_base on v_movreld_b32/v_movrelsd_b32/v_movrelsd_2_b32/v_swaprel_b32 (and read-side VGPRs >= src_base on v_movrels_b32/relsd/swaprel in step()), so non-zero M0 targets (e.g. M0 = 1) preserve downstream taint into sinks. - Remove s_andn2_saveexec_b64 and s_andn2_wrexec_b64 from narrows(); keep s_andn1_saveexec_b64 and s_andn1_wrexec_b64 excluded as well because ~S0 & EXEC runs all lanes when S0 == 0, which diverges on 1x64 vs 2x32 behind s_cbranch_vccz. - Add regression and 1x64-vs-2x32 divergence tests for non-zero M0 v_movreld_b32 (both tainted and clean control) and ANDN1/ANDN2 in vote branches.
|
Thanks for the review @Flyander — pushed follow-up commit
Verification (commit
|
|
Tested 69bd312 against its base Setup: WSL Ubuntu, Python 3.14.4, llvm-mc 21.1.8, SPIRV-Tools v2026.1;
Not run here: GPU tests ( AI-assisted (Claude Code). |
|
Tested Runtime and test programs built from this head (MSVC 14.51, Ninja, RelWithDebInfo), native Windows
The GPU run only rules out regressions; it doesn't exercise the new rules. All 192 translated modules, native and emulated, are byte-identical to a run of another PR on the same base AI-assisted (Claude Code); I checked the results. |
|
Corpus re-run on the new head 1222fd5 (same setup as my run above, full corpus, default mode): 26,487 translated, 26,487 pass spirv-val, and all 26,487 modules byte-identical to AI-assisted (Claude Code). |
…us GS are tier A with the GS ring rule The census in the row predated the GS ring rule (TEST-251) and ItsNotRexed#1982; re-run over the same 1.0.2.1 corpus: tier A 2,117 (was 1,919), GS 195/0/0 (was 0/0/195). The row's open question (whether the corpus GS were a false tier C) is answered by it. AI-assisted (Claude Code). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…us GS are tier A with the GS ring rule The census in the row predated the GS ring rule (TEST-251) and ItsNotRexed#1982; re-run over the same 1.0.2.1 corpus: tier A 2,117 (was 1,919), GS 195/0/0 (was 0/0/195). The row's open question (whether the corpus GS were a false tier C) is answered by it. AI-assisted (Claude Code). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…us GS are tier A with the GS ring rule The census in the row predated the GS ring rule (TEST-251) and ItsNotRexed#1982; re-run over the same 1.0.2.1 corpus: tier A 2,117 (was 1,919), GS 195/0/0 (was 0/0/195). The row's open question (whether the corpus GS were a false tier C) is answered by it. AI-assisted (Claude Code). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claim: #1745 (comment) (carried over to #1902)
Summary
Closes several soundness gaps in
tools/wave64_halves.pywhere partition-dependent wave64 VS/PS/GS programs could be classified as Tier A or B (or lose a genuine wave vote) instead of Tier C, and adds regression tests in a standalone test moduletests/semantic/test_wave64_halves_soundness.py(leavingtests/semantic/test_wave64_halves.pyand lines ~370–380 oftools/wave64_halves.pyuntouched so this stays conflict-free with #1875 and #1830):In-place RMW destinations,
s_pack,v_swap_b32, and implicit operands (operands,Analysis.step,Analysis.transfer)s_packfromNO_DESTsos_pack_*destinations are written in dataflow and tracked instale_uses().RMW_DEST(s_addk_i32,s_mulk_i32,s_cmovk_i32,s_cmov_b32/b64,s_bitset*,v_*fmac/mac*,v_dot*c*) so existing taint on the read-modify-write destination is preserved insrcs.st["r"]), and base tokens (st["b"]) cleanly forv_swap_b32under full exec, and conservatively union taint/rank/base (clearing uniformity and markingELECTif in an elected region) under narrowed/electedexec."vcc"only viasrcs(len(srcs) == 2, plus"vcc"check insrcsforv_div_fmas_*) so 4-operandv_add_co_ci_u32/v_sub_co_ci_u32/v_subrev_co_ci_u32(whose destinationa[1]isvcc) still read implicitvcc; also attach implicit"scc"ons_cmovk_i32and"m0"onMOVREL_OPS.SCC-preserving ops & non-vote SCC writes (
SCC_LESS,Analysis.transfer)s_mul,s_pack,s_sext,s_flbit,s_ff0,s_ff1,s_brev,s_bfm,s_bitreplicate, ands_get_waveidtoSCC_LESSso they do not clobber a prior wave-vote or taintedscc.sccas a("vote", ...)producer ons_bcnt1_i32_b64(nots_ff1_i32_b64, which does not write SCC); ons_bcnt0_*/s_bcnt1_i32_b32over a mask, taintT["scc"]and clear any priorvotetag.s_bfm_b64and relative register indexing (Analysis.transfer,Analysis.stale_uses)s_bfm_b64withLANE(matchingtools/rdna2spirv.pyper-halfwave_lane()comparison).s_movrels_b32/b64,v_movrels_b32, andv_movreld_b32/v_movrelsd_b32/v_movrelsd_2_b32/v_swaprel_b32: propagate VGPR/SGPR taint (andMASKD | Xwhen SGPR masks or parked/VGPR lane masks exist inself.masks), taint withELECTinside elected regions, invalidate affectedst["u"]/st["l"]/ waterfall tags at/above the base register, and flag stale SGPR reads instale_uses()fors_movrels_*.EXECupdates,_wrexec_,s_andn1_*/s_andn2_*, and_b32mask halves (SAVEEXEC,Analysis.exec_write,Analysis.narrows)(op.startswith("s_") and op.endswith("_b32"))asmask-halfinexec_write.SAVEEXECsource before overwritingdests[0], storesite(newEXEC) as the saved token for_wrexec_vsoldfor_saveexec_, restrictnarrowing/ positive mask tag propagation ons_and*_saveexec_*/s_and*_wrexec_*, and adds_and_wrexec_b64/s_andn2_wrexec_b64tonarrows().EXECwrites, combine taint across allsrcregs, only forwardmgwhenlen(srcregs) == 1, require"exec"amongsrcsfors_or_b64/s_and_b64, and requirelen(srcs) == 2 and _regs(srcs[0]) == ["exec"]withmg=Nonefors_andn2_b64.Regression tests (
tests/semantic/test_wave64_halves_soundness.py)Verification
python -I tests/semantic/test_wave64_halves_soundness.py -v:Ran 27 tests in 1.472s, OKpython -I tests/semantic/test_wave64_halves.py -v:Ran 57 tests in 1.055s, OKpython -m compileall -q make_game.py tools tests: exited0python -m unittest discover -s tests/semantic -v:Ran 1671 tests in 334.490s, OK (skipped=2)\r\ncount = 0) on both files andgit diff --cached --checkclean.Environment & disclosures: Tested on
Windows 11, Python 3.11.3, NVIDIA GeForce RTX 3070 (driver 32.0.16.2124)— CPU/semantic tests only (no GPU execution tests or C++ runtime build run; no game data used). AI-assisted.