Repository navigation
shader: lower a mesh CMPX region inside a SAVEEXEC then arm (Part of #3703) - #3782
Conversation
Inside a SAVEEXEC then arm the compiler often copies EXEC, runs some vector work, narrows EXEC with one CMPX, skips with EXECZ and restores the copy. Each lane runs the work and then the skipped instructions only if the compare holds: the same if-only region s_and_saveexec_b64 would open on the compare. The then-arm scan now registers it as a child region and the mesh frontend lowers it as a nested diamond on the shared compare, through the existing nested SAVEEXEC join and restore. The region needs its own restore of the copied register inside the arm; anything else stays an EXEC read of the then arm. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
The compiler also narrows the rest of an if-only SAVEEXEC then arm with a CMPX whose EXECZ skips to the arm's end, leaving the EXEC copy unrestored. The rest of the arm is then the region, and the SAVEEXEC restore ends both. Accept that form when the enclosing arm has no else arm (its inverse would read the narrowed EXEC), and visit the join address again after the region closes so the enclosing arm ends there too. Regions chain the same way. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
|
Pushed It is accepted only without an else arm, since the inverse would otherwise read the narrowed EXEC. The description has the tests and mutations. Census on the stack: 975 of 1,569 (was 924 at AI-assisted. |
lukaslw-lab
left a comment
There was a problem hiding this comment.
Reviewed d1c76a61 by reading the diff; not built or run.
Verdict: approve. The region reuses the nested SAVEEXEC diamond: the copy is lowered by the existing s_mov_b64 sX, exec path, the CMPX checks that the copy is still the arm's EXEC (saved_exec.at(start), same lane), and the branch and lane mask (arm AND compare) match the nested s_and_saveexec_b64 case. No MUST.
- SHOULD No case reads a scalar written inside the region after its join. SALU in the region runs once for the whole wave whenever any lane passes the compare. In DXIL it runs only for the lanes that pass. So the
then_writesloop and the SCC entry inscalar_clobbers(gfx1013_direct_mesh.inl:1816,:1818) are what keep this correct. Dropping either one passes every new case, because the regions write onlyv1. Two refusals would pin them:s_mov_b32 s30, 1in the region, then a read ofs30after the restore;- an
s_cmpin the region, thens_cselect_b32after the restore.
- NIT #3797 edits the same then-arm scan and conflicts textually with this head. Whichever lands second needs a rebase. The two shapes don't overlap: an EXEC copy plus CMPX here, a VCC branch there.
- Checked, no finding:
- The chain form needs an arm with no else arm (
!shape.else_begin), so the inverse never reads the narrowed EXEC. The second visit of the join address is backed by theoutlives its enclosing armrefusal. - Prefix and region writes to the copy are refused, in the prefix by
writes_savedand in the region at the arm close. A nested SAVEEXEC in the prefix fails the match and stays atdepends on EXEC. - The copy registers join the parent's
then_writes, so after the outer join a chain copy that was never restored reads as unbound, not as a stale lane mask. - It merges cleanly with main, #3707, #3712 and #3770.
- The chain form needs an arm with no else arm (
Tests: the 14 new native_direct_mesh cases check the IR order. The branch takes the compare, the region's select uses arm AND compare, and both joins come in order for the region and the chain forms. The refusals cover each match condition. These are IR checks only; no draw runs a region. CI ran native_direct_mesh in the pr preset at this head, green.
Part of #3703. Covers 158 of the 215 programs the wall
mesh SAVEEXEC then arm depends on EXECstops in my census on the current stack.Shape
Inside a SAVEEXEC then arm, the compiler often narrows EXEC once more with a CMPX:
Each lane runs the work, then the region only if the compare holds. That is the if-only region
s_and_saveexec_b64 sX, cmpwould open, except that a CMPX leaves SCC alone. The then-arm scan refused the EXEC copy.Chain form (second commit): in an if-only SAVEEXEC arm the EXECZ may instead skip to the arm's end, leaving the copy unrestored. The rest of the arm is then the region, and the SAVEEXEC restore ends both. Regions chain the same way.
Change (
gfx1013_direct_mesh.inl)match_cmpx_childrecognizes the shape inside a then arm. The work between the copy and the CMPX must leave EXEC, the copied register and control flow alone. The EXECZ must land ons_mov_b64 exec, sXwith the same register, inside the arm.contains_child, so its lane masks are exact, as for a nesteds_and_saveexec_b64.comparison(), so every 32-bit VOPC compare is supported. The region's lane mask is the arm's lane mask AND the compare. It joins and restores through the existing nested SAVEEXEC path. SCC is clobbered after the join, as it is for a nested SAVEEXEC.Tests (
tests/native_direct_mesh_check.py)saveexec-cmpx-regionand-prefixcheck the whole chain:icmp ugt i32 3;then arm depends on EXEC): another restore register, no EXECZ, a prefix that writes the copy, a prefix branch, a VOPC without EXEC, and an EXECZ past the restore.v_cmpx_gt_u16is refused as unsupported.saveexec-cmpx-chainchecks the branch on the compare, the region's select and join, and that the join leaves the arm.-twicechecks a second copy andv_cmpx_ne_u32inside the region, with both joins in order at the arm's end.-elsekeeps the chain refused under an arm with an else arm.Validation (Windows 11, MSVC, Windows SDK 10.0.26100)
ctest --test-dir out/build/dev -R "native_direct_mesh|mesh": 210/210 (the twomesh_two_exitshardware tests skip as usual).s_bitset1_b32, then stop at a scalar loop #3703) onmain+ shader: lower s_not_b32, s_brev_b32 and s_bfe_i32 in the mesh frontend #3708 + shader: lower v_rcp_iflag_f32 and v_ashrrev_i32 in the mesh frontend #3709 + shader: keep a mesh lane limit across a nested CMPX skip that closes at the same restore (Part of #3703) #3710 + shader: lower v_cmpx_lg_f32, v_cmpx_gt_f32 and per-lane v_cmpx_gt_u32 in the mesh frontend (Part of #3703) #3729 + shader: carry exact mesh lanes through nested CMPX skips to an EXEC restore (Part of #3703) #3760 + shader: merge mesh writes under one CMPX inside a lane skip and restore the guard (Part of #3703) #3765 + shader, runtime: lower and bind mesh format loads from a descriptor-table V# (Part of #3703) #3770 + this: 975 of 1,569 translate, up from 845. 130 gained, none lost. Of the 215:unproven mesh mask operand(a mask built withs_cselect_b64 sN, exec, 0);v_min_f32;v_cvt_f16_f32;mesh scalar branch crosses a nested SAVEEXEC region;s_and_b64 vcc, exec, sN+s_cbranch_vccnzuniform branches, not in scope here.AI-assisted.
🤖 Generated with Claude Code