Repository navigation
Conversation
|
Tested 1b9434c merged with main 042c5f3 on Linux/Python 3.12.16: pass Merge was clean (tools/spirv_opt.py, tests/test_spirv_opt.py).
Diff read: a trivial |
|
Tested 1b9434c on Windows 11 (NTFS), Python 3.12.10 (CPU only, no GPU, no game files): pass What I ran:
Strict compared with non-strict dominance, with a hand-written case. Case A is a one-block loop where the only non-self value is defined in the phi's own block: Case B is a valid loop where
The new check handles case A correctly. But the PR's test also passes when Points, none blocking:
Overlap with other open PRs on
AI-assisted (Claude Code). |
…orateId/String/GroupDecorate Fixes two soundness bugs in tools/spirv_opt.py: 1. Trivial OpPhi simplification replaced %p with its sole non-self operand without checking that the operand strictly dominates the OpPhi's block. When the operand came from an unreachable predecessor or a non-dominating loop latch, this emitted invalid SSA (e.g. self-referential '%x = OpIAdd %uint %x %c1' and uses of non-dominating definitions). Record per-block SSA definitions and only fold an OpPhi to a function-local definition whose defining block strictly dominates the OpPhi's block. 2. Decoration scanning only inspected OpDecorate, missing OpDecorateId, OpGroupDecorate, and quoted OpDecorateString / OpDecorateStringGOOGLE lines (skipped by _parse_line). Live decorated instructions could be folded away, and DCE'd ones left dangling OpDecorateId / OpDecorateString / OpGroupDecorate references in the module header. Track all four decoration forms in decorated_ids and clean up or prune targets for deleted IDs during reassembly. Adds regression tests in tests/test_spirv_opt.py (both fail against unpatched main and pass with the fix).
1b9434c to
61dbeec
Compare
shayderrr
left a comment
There was a problem hiding this comment.
Summary
tools/spirv_opt.py now builds a definition-to-block map and requires a trivial OpPhi candidate's sole value to strictly dominate the phi's block before folding it. It also tracks OpDecorateString, OpDecorateStringGOOGLE, OpDecorateId, and OpGroupDecorate targets as decorated IDs, and prunes dangling decoration lines or group members when their targets are deleted. Tests cover loop headers with non-dominating phis and live/dead decorated ops.
Why merge
Folding a phi whose value came from an unreachable or loop-latch predecessor produced use-before-def violations, while DCE left decorations pointing at removed IDs. Both fixes keep optimized SPIR-V valid and preserve decorated semantics.
Verdict: Approve
Summary
Why mergeFolding a phi whose value came from an unreachable or loop-latch predecessor produced use-before-def violations, while DCE left decorations pointing at removed IDs. Both fixes keep optimized SPIR-V valid and preserve decorated semantics. Verdict: Approve |
Claimed in the coordination issue as:
tools/spirv_opt.py(_optimize_functiontrivialOpPhistrict dominance +OpDecorateId/OpDecorateString/OpGroupDecoratetracking and cleanup in #6414)What and why
Fixes two soundness issues in
tools/spirv_opt.py:OpPhi:OpPhisimplification previously replaced%pwith its sole non-self operandcandin any reachable block without checking whethercand's defining block strictly dominates theOpPhi's block.%entryfirst enters a reachable block from a predecessor not dominated by the block, so the sole non-self operand already strictly dominates the block and valid folds (such as a loop phi after identityOpIAdd %uint %p %c0simplification) are unchanged. For malformed or non-SSA input (e.g. a non-self value coming from an unreachable predecessor, a non-dominating loop latch, or defined later in theOpPhi's own blockcand_blk == b), requiringcand_blk is None or strictly_dominates(cand_blk, b)prevents emitting invalid/self-referential instructions (%s = OpIAdd %uint %s %c1).OpDecorateId,OpDecorateString,OpDecorateStringGOOGLE, andOpGroupDecorate(including tab-separated lines):OpDecorate, missingOpDecorateId,OpGroupDecorate, and quotedOpDecorateString/OpDecorateStringGOOGLElines (which_parse_line()skips). Live instructions decorated via those opcodes could be folded away, and DCE'd instructions left dangling references in the module header.decorated_idsand drop or prune deleted target IDs from space- or tab-separated decoration/name lines during reassembly.Tested
tests/test_spirv_opt.pyon Linux x86_64 (Python 3.13.5, CPU-only, no game data):Ran 11 tests in 0.144s — OK(including the one-block self-definition strict-dominance checkcand_blk == band tab-separated decoration lines suggested by@AsgerCode).AI-assisted: yes
Checklist
docs/design.md, with how it was confirmed.