Repository navigation
Conversation
…ess of block order
|
Tested d95b02e merged with main 1d21030 on Linux/Python 3.12.16: pass Merge into main was clean (tools/spirv_opt.py, tests/test_spirv_opt_nested_accesschain.py). Commands run in the merged worktree:
Negative control: Diff read: the pending list is only populated for chains whose base is not yet in ptr_root, the fixed-point loop stops when a pass resolves nothing (so unresolved chains cannot loop), and the added escape in the OpAccessChain branch only fires for a chain that stayed unresolved over a function variable, which is the conservative direction. |
|
Tested d95b02e on Windows 11 (NTFS), Python 3.12.10 (CPU only, no GPU, no game files): pass The earlier review ran the tests and the negative control. I checked whether the result is really independent of block order: the same functions in many text orders, compared with the program-order result. What I ran:
Note, not blocking: the new escape check in the Overlap: #7060 ( Not run: AI-assisted (Claude Code). |
|
Tested d95b02e on Windows 11, Python 3.15.2, NVIDIA RTX 4060 Ti (driver 621.24; CPU-only checks, no game files, no GPU/llvm-mc/MSVC used): pass. Ran the test files this PR adds or changes, from a clean checkout of the PR head: AI-assisted (Claude Code). |
Claim
Problem
In
tools/spirv_opt.py(_optimize_function, Step 1 pointer/slot discovery),ptr_rootandptr_slotwere populated in a single linear pass over module text order, andelif op == "OpAccessChain"in the escape scan only checked index operands (args[2:]), not the base pointer (args[1]).In valid SPIR-V, only the entry block must come first in a function; a dominated block containing
%p2 = OpAccessChain ... %p1 ...may appear earlier in module text order than the dominating block defining%p1 = OpAccessChain ... %arr .... Because Step 1 scanned linearly:%p2was visited before%p1was inptr_root, so%p2was never added toptr_rootorptr_slot.%p2did not invalidate cachedslot_valentries for%arr, silently forwarding stale values on subsequent aliasedOpLoads (e.g., outputting99after%p2overwrote the slot with42).%p2were omitted fromloaded_slots, allowing whole-function dead-store elimination to delete live stores to aliased direct pointers.%p2did not mark the root variable indyn_indexed, and mixed-depth accesses through%p2were omitted fromslot_depths.OpAccessChainchains on readonly globals (PushConstant/Input) missedptr_rootregistration and load CSE.Fix
tools/spirv_opt.py:OpAccessChaininstructions during the initial scan and resolveptr_root,ptr_slot, anddyn_indexedin a bounded fixed-point loop until no new pointer roots are discovered (handling arbitrary chain depth and arbitrary basic-block text order for bothFunctionvariables and readonly globals).elif op == "OpAccessChain"so anyOpAccessChainwhose base points to aFunctionvariable and still failed resolution marks that root variable escaped.tests/test_spirv_opt_nested_accesschain.py(new file, disjoint from BUILD-1578: Preserve vector shape and signedness in SPIR-V folds #5150, spirv_opt: enforce strict dominance for OpPhi folding and track OpDec… #6557, spirv_opt: gate rules by opcode and scan in bulk, about 28% less CPU, byte-identical output #7060):PushConstantnested load CSE, assembling both input and optimized SPIR-V withtools/spirv_asm.py.Validation
Environment: Windows 11, portable Python 3.12.10 (stdlib only,
python -I), synthetic SPIR-V modules only.tools/spirv_opt.pyatd90444f21):python -I tests/test_spirv_opt_nested_accesschain.py -v-> FAILED (failures=6) (all 6 tests failed).d90444f21):python -I tests/test_spirv_opt_nested_accesschain.py -v-> 6 tests OKpython -I tests/test_spirv_opt.py -v-> 9 tests OKpython -I tests/test_resource_hygiene.py-> 2 tests OKpython -m compileall -q tools/spirv_opt.py tests/test_spirv_opt_nested_accesschain.py-> exit 0Limitations
tools/spirv_asm.pybinary assembly and structural/value assertions on synthetic SPIR-V modules; externalspirv-valand GPU execution were not run in this environment.AI Assistance