mirror of
https://github.com/ubiquitarianism/leonida.git
synced 2026-11-26 22:25:53 +01:00
[PR #793] [CLOSED] wave64_emulate_opt: flow-sensitive must-be-zero proof in _exec_writes_stay_inactive #830
Labels
No labels
bug
pull-request
No milestone
No project
No assignees
1 participant
Notifications
Due date
No due date set.
Dependencies
No dependencies set
Reference
starred/leonida#830
Loading…
Reference in a new issue
No description provided.
Delete branch "%!s()"
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?
📋 Pull Request Information
Original PR: https://github.com/ubiquitarianism/leonida/pull/793
Author: @SweatierKey
Created: 11/24/2026
Status: ❌ Closed
Base:
main← Head:feat/w64-flow-sensitive-exec-fold📝 Commits (1)
e72218ewave64_emulate_opt: flow-sensitive must-be-zero proof in _exec_writes_stay_inactive📊 Changes
4 files changed (+307 additions, -6 deletions)
View changed files
📝
docs/design.md(+1 -0)📝
tests/semantic/test_wave64_emulate_opt.py(+52 -0)📝
tests/test_wave64_emulate_opt_cfg.py(+92 -0)📝
tools/wave64_emulate_opt.py(+162 -6)📄 Description
Claimed in the coordination issue as: SHADER-W64-FLOW-EXEC-FOLD (https://github.com/ubiquitarianism/leonida/issues/14#issuecomment-7133434431)
What and why
In
--wave64-emulate,find_local_exec_foldsfolds single-entry/single-exits_cbranch_execz/s_cbranch_execnzregions behindif (%active)only when_exec_writes_stay_inactivecan prove that everyEXECwrite inside the region keepsactive == Falsefor lanes that entered withEXEC == 0.Previously,
_exec_writes_stay_inactivewas flow-insensitive per 64-bit SGPR pair: if any instruction anywhere in the region wrote a non-zero-preserving mask intos[r:r+1](for instance, computing a negated inner branch mask withs_or_b64/s_xor_b64 s[r:r+1], ..., -1), the pair was permanently disqualified — even when the very next instruction overwrotes[r:r+1]with oldEXECvias_and_saveexec_b64 s[r:r+1], s[r:r+1]before restorings_mov_b64 exec, s[r:r+1]. On large wave64 compute shaders that reuse scratch SGPR pairs for nestedsaveexecguards, this falsely rejected thousands of outers_cbranch_execzfolds and forced wave votes +OpControlBarrierround cuts.This change replaces the flow-insensitive check (when CFG context
run,succ,active_blocksis supplied fromfind_local_exec_folds) with a sound forward must-be-zero dataflow over 64-bit SGPR pairss[0..126]andvcc:s_*_saveexec_b64,s_andn1/andn2_wrexec_b64,v_cmp_*,s_and/andn2/or/xor/mov/cselect/cmov_b64).(s_bits | (s_bits >> 1))on any partial 32-bit or non-zero-preserving SGPR write (including VOP3B carry-out masks) and killsvccon any partial/non-preserving write._exec_writes_stay_inactiveis called without CFG context.Aggregate impact measured on cached large wave64 compute shaders (counts only):
OpControlBarriercount drops from4,090 -> 595(-85.5%) and4,073 -> 578(-85.8%); across 6 large wave64 compute shaders, totalOpControlBarrierdrops from8,263 -> 1,273(-84.6%), and all translated SPIR-V modules passspirv-val --target-env vulkan1.2.Tested
python3 -I tests/test_wave64_emulate_opt_cfg.py: 33/33 passed (including 7 new positive and negative soundness tests inFlowSensitiveExecInactiveTest: reused scratchsaveexec,v_cmp+s_cselect_b64, unoverwrittens_xor -1, diamond merge with 1 non-zero branch, loop back-edge clobber, partial 32-bit overwrite of pair high half, VOP3B carry-out).LEONIDA_REQUIRE_SPIRV_TOOLS=1 python3 -I tests/semantic/test_wave64_emulate_opt.py: 32/32 passed (including newtest_flow_sensitive_reused_scratch_saveexec_folds_without_barrierson 64-thread and 128-thread workgroups: 1 superblock, 0 wave votes, bit-exact outputs, passesspirv-val).LEONIDA_REQUIRE_SPIRV_TOOLS=1 python3 -I scripts/run_semantic_tests.py tests/semantic: 465 files, 6109 tests, 0 failures.python3 -I tests/test_docs_links.py(16/16),python3 -I tests/test_text_write_line_endings.py(3/3),python3 -I scripts/check_no_game_data.py,python3 -m compileall -q make_game.py tools tests: all passed.vk_compute_test.exewith--wave64-emulateandspirv-valenabled): 30/30 wave64 compute fixtures (cs_w64*,cs_w64x_*,cs_wave64_ballot,cs_wm_*,cs_wqm_w64*,cs_dpp_w64) plus the nested scratch-saveexec shader passed with exact readback outputs.GPUs tested: NVIDIA GeForce RTX 5070 Ti, driver 616.92, Windows 11
AI-assisted: yes
Checklist
mainand merges cleanly (a conflicting pull request is labeledneeds rebase).docs/design.md, with how it was confirmed.🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.