Repository navigation
startup: refuse uniform load proofs across EXEC-changing loops - #2768
Conversation
|
@RavenCurseBurg, the Linux Python job fails at The check expects the graphics and compute revisions to share one number. Moving the graphics key to AI-assisted. |
|
Pushed |
tedin7
left a comment
There was a problem hiding this comment.
Review of head 0b861347 (comment only).
What I checked:
gfx2hlsl.py: for compute programs with a back edge and a uniform load, blocks reachable from an EXEC-writing block through the CFG are collected inloads_after_exec_write. Loads there are no longer eligible for the past-entry reload proof. EXEC writes only after loop exit leave the proof intact. This matches the described failure (second readfirstlane after an empty EXEC).- Cache revision is 21 / 21cs in the translator, the runtime stub and the fixture seeds. The shared-revision re-key test passes.
- No sibling table or callsite left out; no other open or merged PR covers this slice.
Commands run (Linux, exact head):
python3 -B tests/startup_gfx2hlsl_readfirstlane_load_recompute_check.pyrc=0python3 -B tests/startup_gfx2hlsl_compute_check.pyrc=0python3 -B tests/startup_shader_cache_rekey_check.pyrc=0python3 -B tests/startup_shader_cache_key_check.pyrc=0python3 -B tests/startup_compute_readfirstlane_check.pyrc=0python3 tests/docs_links_check.py,python3 tests/bidi_controls_check.py,git diff --check origin/main...HEAD: clean- Mutation: removing the
loads_after_exec_writecondition makesstartup_gfx2hlsl_readfirstlane_load_recompute_check.pyfail (rc=1), so the new test guards the behavior.
Windows results follow in the receipt.
AI-assisted; commands listed were executed locally.
|
@RavenCurseBurg, thanks for AI-assisted. |
|
Windows Server 2025 (MSVC + D3D12 WARP) at
The PR's only change to that test is the Code review and Linux checks are in the earlier review comment. AI-assisted; commands listed were executed locally. |
|
Merged |
|
Update on the release crash: it is not caused by this PR. I ran the same four tests on Windows Server 2025 with this PR's changes reverted (main at So the PR's own tests are green in debug and release. The release crash is a separate problem on main. AI-assisted; commands listed were executed locally. |
MasterDomino
left a comment
There was a problem hiding this comment.
Approving 3341d272. Against 0b861347, which I reviewed in full, the PR's own translator diff differs only in the revision, now x2w-startup-shader-22 / 22cs. It merges cleanly and CI is green.
@tedin7, on the Release segfault: it isn't this PR. startup_resource_retire_title segfaults in Release on main too: all 6 variants at f1a8db63, on WARP and an RX 9070 XT. A bisect puts it at #2719: its parent passes 6/6 in Release, and the merge fails 6/6.
- Cause: a pre-existing ABI heuristic in the shim. For descriptor heap slot 9,
small_resulttreats a live wrapper in the second register as the (return buffer, object) form. Case 9 nests the slot-9 call inside a slot-20 call, so at/O2rdxstill holds the resource wrapper. The shim then writes the handle over the heap object's vtable and returns the heap's address. The RTV lands in an untracked slot, and the heap's nextReleasejumps into data. - Fix: I'll open a PR with a shim fix and a deterministic regression that also fails in Debug.
Why the guard is complete: exec_known is tracked in program order and never comes back after a real EXEC write. So a load placed textually after a writer was already refused; the gap was a writer reaching an earlier load through a back edge, and following CFG successors from every writer block closes it. Through the text harness, each of these now refuses where main accepted:
- the #2757 repro;
s_or_b32/s_andn2_b32/s_cselect_b32intoexec_lo, ands_and_b64 exec;v_cmpx(e32 and e64),v_cmp_e64 exec_loands_andn2_wrexec_b32;- a self-loop closed by
s_cbranch_execnz, and ans_cbranch_execzinside the loop; - a back edge to offset 0;
- an outer loop that narrows EXEC after its inner loop exits.
A writer after loop exit and a loop with no writer still translate.
Non-blocking: a divergent if inside a uniform loop (s_and_saveexec … s_or_b32 exec_lo, exec_lo, sN before the back edge) is now refused. main translated it correctly, because EXEC is the entry mask again at the load on every pass. The refusal is conservative and sound; proving the restore could be a follow-up. The bump is justified: wrong translations are now refused, and some still-translating programs drop a dead ulc_N temporary.
Runs:
- Windows 11 build 26300; AMD Radeon RX 9070 XT (driver 32.0.32029.2010); WARP 10.0.26100.9818; debug layer on, 0 errors.
- At
0b861347,ctest --preset dev --no-tests=error -R '^startup_gfx2hlsl|^startup_compute_readfirstlane|startup_compute_request_offline|startup_shader_cache|startup_indirect_draw_indexed|startup_resource_retire|startup_packed_position_provenance'gave 321 tests, 319 passed, 0 skipped. The two failures also fail onmainon this adapter (#2746):fma_mix_dispatch_hardwareandf16_alu_draw_hardware. join-loadmatches all 320 words on WARP and hardware, andjoin-load-zerois rejected atword=0 expected=8b02a7f1 actual=00000000.- At
3341d272, these all exit 0: the readfirstlane load/uniform/recompute checks,startup_compute_readfirstlane_check.py,startup_compute_request_offline_check.py,startup_gfx2hlsl_compute_check.py(plusbinarywith llvm-mc 15),startup_shader_cache_rekey_check.pyandstartup_shader_cache_key_check.py.
Mutants: four are caught by startup_gfx2hlsl_readfirstlane_load_recompute: dropping the guard, removing the transitive walk, seeding only forward successors, and counting only saveexec as a writer. The new refusals also fail against main's translator.
AI-assisted; commands listed were executed locally.
Fixes #2757.
The first iteration of a compute loop can reach a read-only buffer load with the entry EXEC mask, and the next iteration can reach the same instruction with EXEC empty. The second readfirstlane must then see lane zero's previous register contents. The former translation reloaded memory using the new offset.
For compute programs with a back edge and a candidate load, the translator now follows CFG successors from blocks that write EXEC. Loads in those successor blocks are ineligible for the past-entry reload proof. This includes an EXEC write reached by a detour beyond the back-edge instruction. A write that occurs only after loop exit leaves the proof intact. The graphics and compute cache seeds both advance from main's revision 21 to revision 22. The compute seed
22csinvalidates earlier translations of this case.Verification
Tested commit
0e29f163on Windows 11. The reported loop and the off-range detour both produced unguarded reloads on the original baseline. Both are refused with the patch. The unchanged-EXEC loop still translates.The host suites passed, including the independently framed compute key
90041d02ef75b4e9. All checked-in fixture words matched LLVM's gfx1013 assembler (LLVM 15.0.7, clang-cc1as -show-encoding). The dispatch suite passed 27 baselines and detected four controls on each of WARP, Intel UHD 770 and RTX 4060 with DXC 1.9.2609.5.The new repo-authored gfx1013 fixture takes both arms of a forward branch in separate workgroups. Eight threads per group store the readfirstlane result at individual addresses. The CPU compares all 320 words, including 304 untouched sentinels. Replacing the read with zero fails on each backend at
word=0 expected=8b02a7f1 actual=00000000. The regression at the loop head is tested as an explicit translator refusal. The broader question about predication of arbitrary VGPR writes is separate.Follow-up
0b861347keeps the graphics and compute cache revisions paired. Runningpython -B tests/<name>.pypassed forstartup_shader_cache_rekey_check,startup_shader_cache_key_check,startup_compute_request_offline_check,startup_gfx2hlsl_buffer_store_check,startup_gfx2hlsl_const_copy_join_check,startup_gfx2hlsl_fract_checkandstartup_packed_position_provenance_check. An independent native C++ run of the runtime hash produced graphics keys93a74e652d95daf6and1ff6b039237188d6(without and with the input layout).After #2723 landed at revision 21,
3341d272mergedf1a8db63and advanced both seeds to 22. All seven cache/translation suites listed above and the compute, readfirstlane-uniform and readfirstlane-load controls passed on this head. The native graphics hash returned30009a5d8295d679anddae7d34c534837e5. The independently framed compute key is5159f6a85d77858e. The joined-load GPU fixture and its zero-read mutant were rerun on all three backends.AI-assisted with Codex (GPT-6.2 Astra, xhigh).