Repository navigation
shader: preserve one-path SGPRs and uniform loop counters for v_readfirstlane_b32 - #2309
Merged
R0Y00 merged 2 commits intoNov 25, 2026
Merged
Conversation
tedin7
reviewed
Nov 25, 2026
tedin7
left a comment
Collaborator
There was a problem hiding this comment.
Review of head b0c83b064dcf0c401abc065e1155e108388d98b6 (Linux-only; no Windows run, CI for Windows was still pending).
Commands run locally in a worktree of this head:
git diff --stat origin/main...HEAD: 6 files, +589/-69python3 tests/startup_compute_readfirstlane_check.py: passed ("one-path, loop-counter and refusal checks passed")python3 tests/startup_gfx2hlsl_readfirstlane_recompute_check.py: "0 failed"python3 tests/docs_links_check.py: passed (448 links)python3 tests/bidi_controls_check.py: passedgit diff --check origin/main...HEAD: clean- Mutation: in
gfx2hlsl.pyreplacedforce_unproven.update(new_bad)withpass(the feedback of loop-written SGPRs into the next pass). The new check did not report a failure: the fixpoint loop never converged and the run hung until I stopped it. So the mutation is detected, but only as a hang, not as an assertion. Reverted afterwards.
Findings
- P1: none.
- P2: none.
- Nit 1 (
tools/startup/gfx2hlsl.py:1120-1121):join_writes = self.join_writes(branches)is assigned twice in a row. Drop one. - Nit 2 (
tools/startup/gfx2hlsl.py, thewhile Truepass loop that ends near line 1257): it ends becauseforce_unprovenandforce_atonly grow, and the mutation above shows a hang if that growth is lost. A small pass cap that raisesUnsupportedwould turn a future regression into a clear refusal rather than a stuck translation. - Nit 3: the new
hasattr(self, 'defined_uniform_s')/'_uniform_written'/'bad_sgprs'guards inset_sand the write path suggest these fields are only sometimes present. Initializing them inStage.__init__would remove the guards.
Clean-room, neutral title, MIT-only content, mergeable: all fine. The new test is wired into CMake and the Windows workflow. Windows WARP/D3D12 coverage comes from the added --dispatch CTest entries; I did not run those here.
AI-assisted; commands listed were executed locally.
Contributor
Author
|
Addressed all three nits in
Re-ran locally after
|
stan495
force-pushed
the
startup/gfx2hlsl-readfirstlane-loop-proof
branch
from
November 25, 2026 11:57
0395dd9 to
beba849
Compare
Contributor
Author
|
Rebased onto current
Re-verified locally at
|
stan495
force-pushed
the
startup/gfx2hlsl-readfirstlane-loop-proof
branch
from
November 25, 2026 12:03
beba849 to
e319842
Compare
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.
Refs #2274 (Part A:
v_readfirstlaneproof across joins and loops).Summary
Preserve proven uniform SGPRs across branch joins for
v_readfirstlane_b32in two CFG-verified cases:tthat are not written on any non-dominating path reachingtor any path reachingtat/aftert.SCCbranch conditions (cond_uniform = cond in ('scc0', 'scc1') and self.scc_uniform), validated via a fixed-point pass inStage.translate()against non-uniform scalar writes (bad_sgprs) and divergents_cbranch_*regions (div_targetsover dominators and post-dominators). Constants (const) are still cleared at clobbered joins so loop counters emit dynamic HLSL scalar reads.What remains refused (
v_readfirstlane_b32 requires a proven uniform source):s_cbranch_*back-edges (e.g.s_cbranch_vccnz), divergent forward branch arms writing the candidate scalar before reconvergence (e.g.else-arm write unders_cbranch_vccz), lane-mask writes (s_mov_b32 sN, vcc_lo), unmodelled SGPR destinations (v_add_co_u32_e64,s_movreld,s_cselecton stalescc), and joins overwriting the scalar insidetentative_keptwhen later invalidated.Also fixes
Stage.one()/Stage.forget_writes()ordering so in-place uniform scalar updates (e.g.s_add_u32 s3, s3, 1) inspects3's prior uniformity mark before unmodelled-write invalidation.Sources and semantics
v_readfirstlane_b32,SOPPs_cbranch_scc0/s_cbranch_scc1/s_cbranch_vccz/s_cbranch_vccnz,SOPC,SOP1,SOP2,VOP1,VOP2) and LLVM 15 AMDGPU gfx1013 wave64 semantics (all lanes executeUniformscalar/branch decisions identically, while divergentvcc/execbranches split active lane masks until immediate post-dominator reconvergence).Verification
Branch commit:
b0c83b06(rebased ontod8b345cb).Environment: Windows 11 25H2 (build
26200.9974), MSVC 19.44.35228.0, D3D12 debug layer enabled (debug_errors=0 debug_warnings=0).CTest (
devpreset)Result: 6 / 6 passed (
100% tests passed, 0 tests failed out of 6):startup_compute_readfirstlane(controls, machine-code refusals, lowering check): passedstartup_gfx2hlsl_loop_constants: passed (PASS)startup_gfx2hlsl_readfirstlane_uniform: passed (0 failed)startup_gfx2hlsl_readfirstlane_recompute: passed (0 failed; covers one-path scalars, uniform loop counters inside/after loops, and divergent/mask refusals)startup_compute_readfirstlane_hardware(adapter=AMD Radeon RX 7900 XTX,vendor=1002 device=744c,driver=32.0.32029.2010,debug_layer=enabled): passed (compared_words=320 mismatches=0 debug_errors=0 debug_warnings=0)dropped-one-path:word=0 expected=0000008b actual=00000019dropped-loop-read:word=0 expected=0000008b actual=0000007fdropped-post-loop:word=0 expected=0000008b actual=00000087startup_compute_readfirstlane_warp(adapter=Microsoft Basic Render Driver,vendor=1414 device=008c,driver=10.0.26100.9818,debug_layer=enabled): passed (compared_words=320 mismatches=0 debug_errors=0 debug_warnings=0, same 3 pinned negative controls rejected)Pure-Python & repo checks
tests/startup_gfx2hlsl_compute_check.py,tests/startup_translator_check.py,tests/docs_links_check.py(18 files, 448 links),tests/bidi_controls_check.py(1600 files),tests/form_coverage_check.py,git diff --check: all passed.python3 -B tests/startup_compute_readfirstlane_check.py --llvm-mc llvm-mc-15(and all other gfx1013 checks).