Repository navigation
Conversation
…e (SHADER-821) A compiler's break loop ORs a v_cmp result into an SGPR pair and narrows EXEC with it. stale_uses() treated the pair as a scalar, so the loop was tier C tainted-exec although each bit belongs to one lane. A def that ORs (or AND-NOTs) a same-block v_cmp result into the pair leaves the off lanes' bits alone; a read that only uses the pair as a lane mask (an EXEC write, or the next such def) is no longer stale. Scalar uses (s_bcnt1, s_cmp) still are. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Claim: SHADER-821 (#4571 (comment)), from @shdann's finding.
What and why
stale_uses()treats a 64-bit lane mask in an SGPR pair as a scalar. In a compiler'sbreakloop, the pair collects the lanes that left:The pair's in-loop def is control dependent on the loop's EXEC vote, so its reads were stale and the two EXEC writes
tainted-exec: tier C. Each bit belongs to one lane, though. Av_cmpwrites 0 for the lanes that are off, so OR-ing it in can't change an off lane's bit. A half that leaves the loop early therefore has the same bits for its lanes as the wave.The rule (narrow on purpose)
Analysis.lane_local_defs):s_or_b64 D, M, D(either order) ors_andn2_b64 D, D, M, where D is an SGPR pair and M is VCC or a pair that av_cmp(notv_cmpx) wrote earlier in the same block, with no EXEC write in between.stale_uses(), a read of D is not stale when every vote-dependent def that reaches it is lane-local and the read only uses D as a lane mask, either as an EXEC write or as the next lane-local def.s_bcnt1,s_cmp, data) are still stale. So is an OR with anything that isn't a freshv_cmpresult.Tests (
tests/semantic/test_wave64_halves.py)test_a_break_loop_lane_mask: the loop above as a PS is tier A (tier Ctainted-execonmain).test_a_break_loop_lane_mask_runs_the_same: as a VS through the CPU wave interpreter, one 64-lane wave and two 32-lane waves write the same outputs (trip counts 1 to 4 per lane), and the tier is A.test_c_break_loop_mask_read_as_scalar:s_bcnt1_i32_b64of the pair is exported.test_c_break_loop_or_with_a_non_compare_mask: OR-ing a copy of EXEC instead of av_cmpresult.Corpus census (asked for by the item)
On my own 1.0.2.1 copy I translated the whole corpus at
main(d0835dd) and with this change, then ranwave64_halves.py --census. Counts only.maintainted-exec/stale-scalarNo shader changes tier. The shape doesn't occur in this corpus: none of the 25,734 listings narrows EXEC with
s_andn2_b64 exec, …. The game's compiler narrows withs_and_b64 exec, exec, s[pair](15,971 times) and loops withs_andn2_wrexec_b64waterfalls. So this PR fixes the classifier for the LLVM-style loop in the finding, but it has no effect on 1.0.2.1's tiers. I'm reporting that plainly so the maintainer can decide whether the rule is worth keeping. If not, the census still answers the item's open question, and I'm happy to close this.Tested
tests/semantic/test_wave64_halves.py+test_wave64_halves_soundness.py: 107 run, OK.python -m unittest discover -s tests/semantic: 7460 run. Its 7 failures and 2 errors are exactly main's known set at d0835dd by test name (test_cmp_class_f64,test_mutations,test_loop_ballot_barrier; fixes open in fix(rdna2spirv): route v_cmp(x)_class_f64 to cmp_class_f64 so malformed forms are rejected #3885/rdna2spirv: reject a modified class mask and a non-EXEC v_cmpx destination (TEST-853) #3948, tests/semantic: re-anchor the v_mul_legacy_f32 mutation after the flush change #3883, tests: test_loop_ballot_barrier follows #2089's structured wave64 emulation (main red since 1cc7497b) #3995).Touches
tools/wave64_halves.pyalongside #4619/#4620 (SHADER-819/820), but instale_uses()and a new helper, not input()/narrows.AI-assisted (Claude Code).
🤖 Generated with Claude Code