Recompiler: a mask a per-lane loop wrote is unknown after the loop (#3440) #3451
Loading…
Reference in a new issue
No description provided.
Delete branch "upstream-pr/3451"
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?
Imported from ivall/xcl. Originally posted by neongatzu on 2026-11-29T18:41:25Z.
Fixes #3440.
lane_masksfollows each lane on its own: a lane that leaves a loop through a per-lane branch stops running the loop. On the console the wave runs on until every lane has left, and every later round writes the loop's masks again (a VALU compare writes 0 for the lanes no longer in EXEC). After the loop such a mask holds the last round's bits, not each lane's own last value, so taking it as the lane's bit dropped guards that were needed (the issue's program:exec = vccafter the loop, thev_movat pc 28 left unguarded).What is in it
Lanes::exit_state: on an edge that leaves one or more loops through a per-lane branch (condkind notUniform), every SGPR mask and the SCC whose function depends on an atom born inside those loops becomes a new atom,Atom::Exit(block, successor, slot). The SCC's kind becomesSccKind::Unknown, so a later read of it is refused as elsewhere.wave_branchesare untouched (their branches areUniform).Bdd::depends: whether a function depends on an atom a predicate names.lane_masks.rs:a_mask_from_a_per_lane_loop_still_guards_what_follows(the issue's program, unchanged; failed onmain0fe06eb0withleft: [], now[28]) anda_mask_saved_before_a_per_lane_loop_is_still_known_after_it(a control:exec = s[0:1] & execafter the same loop adds no guard).Tested
cargo test -p xcl --lib -- lane_masks: 15 passed, 0 failed (13 before + 2 new).cargo test -p xcl --lib -- gpu::recomp: 501 passed, 0 failed, 21 ignored.cargo clippy -p xcl --lib --tests: no finding inlane_masks.rs(the crate's existing clippy errors elsewhere are unchanged).cargo test --workspace.Regression run
Not run: I have no title to run
scripts/smoke.ps1on. The change only affects the per-lane analysis, which is used withXCL_PER_LANE=1(off by default), so the default path should not move; a smoke run from someone with a title is still needed before merge, which is why this is a draft.main: not run
PR: not run
Not tested
ifand read after the join) is not covered by this change.AI use
🤖 Generated with Claude Code
Imported from ivall/xcl. Originally posted by andrewDoing on 2026-11-29T19:19:51Z.
I tested a terminating wave32 version of the #3440 loop on RTX 5070 12 GB (616.92). I changed the add to increment the compared register so lanes could exit on four different iterations. The saved EXEC, loop-carried VCC and post-loop
v_movat pc 28 kept the reported shape. I ran the same fixture on main0fe06eb0and this heade1273c28.0x11111111for staggered exits and0xffffffffwhen all lanes exited together. Native per-lane kernel lowering refused the shape on both revisions with “a value written while some lanes were elsewhere, read after they met again.”compute_withentry. With 31 threads, the per-lane route refused on both revisions and the per-instruction fallback wrote exactly the eight expected lanes, preserving the other lanes and output canaries. With 32 threads, the whole-wave branch route compiled and its native readback agreed with the fallback and the expected eight writes on both revisions.cargo test --offline --locked -p xcl --lib -- post_loop_compare_mask_reaches_rtx_readback lane_masks --test-threads=1 --nocapture: main 14 passed, head 16 passed, zero failures, ignored tests or skips on either. Windows 11 26300.10075, Ryzen 7 5700X3D, Rust 1.100.0, debug. This validates the guard summary and the safe fallback for the bounded wave32 form. The retail workload and wave64 GPU execution remain unmeasured. Codex with GPT-6.2 Sol adapted and ran the fixture.Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T08:46:16Z.
Review (head
e1273c28, diff read, not a merge-check; draft,PR descriptionred, from reading, nothing run):select(read_bit(EXEC), new, old)with the lane's own EXEC bit (lower.rs~564-567). After the issue'ss_and_saveexec_b64 s[2:3], vcc, each lane's EXEC bit is its own last VCC bit, and every lane left the loop with that bit set. So the guard on pc 28 is true in every lane, and thev_movstill runs where the console skips it. The analysis can't give the lowering the last round's wave-wide value. The issue's other option fits better: refuse the program when such a mask is read after the loop, so it stays on the HLSL path. The GPU run of both forms (listed under Not tested) would settle it.exit_state(lane_masks.rs~769-775) makes every mask that depends on an atom born in the loop anExitatom, even when it is already right per lane. The usual compiler loop collects the leaving lanes withs_or_b64 s[0:1], vcc, s[0:1]; s_andn2_b64 exec, exec, s[0:1]; s_cbranch_execnz; s_or_b64 exec, exec, s[0:1]. There each lane's bit ofs[0:1]matches the console, and on main the restored EXEC is every lane. With the PR,s[0:1]is an atom, so everything after such a loop gets a guard it doesn't need. No test covers this form.a_mask_saved_before_...~1143) setss[0:1]to a constant, so it passes on main too. It doesn't check that a mask the loop writes correctly stays known.s_cmpon a loop counter) also becomesSccKind::Unknown, so a later read is refused with a message about a per-lane mask, which is misleading.Fine: exits come from the existing dominator-checked loop bodies, so breaks and nested loops are handled.
Exitatoms are keyed per edge and slot, so the fixpoint stays stable. Keeping EXEC is right, and uniform branches andwave_branchesaren't touched. The issue's test fails on main ([]) and passes here ([28]). OnlyXCL_PER_LANE=1reaches this.AI review: Claude Code (Claude Opus 5.5), posted by Foniass without a human check of each point.
Imported from ivall/xcl. Originally posted by Foniass on 2026-12-01T09:56:07Z.
Triage (#1607) – head
e1273c2No open or merged PR makes the same change for #3440. #1912 and #2117 also edit
lane_masks.rs, but in other places (WREXEC empty-loop exits and null SGPR 125 handling), not the per-lane loop exit state.No problems found in the diff:
Lanes::exit_stateonly turns masks intoAtom::Exiton non-uniform exit edges and when they depend on atoms born inside the loops being left, EXEC excluded, and the issue's test plus a control are included. The failing check is the PR description (no regression run and no full workspace run yet).Recommendation: keep open.
AI review: Claude Code (Claude Opus 5.5), diffs read only, not built or run; not checked by a human.
View command line instructions
Checkout
From your project repository, check out a new branch and test the changes.Merge
Merge the changes and update on Forgejo.Warning: The "Autodetect manual merge" setting is not enabled for this repository, you will have to mark this pull request as manually merged afterwards.