Skip to content

Preserve distinct incoming loop values after dead-code elimination - #1

Open
MichaelSmithAI wants to merge 3 commits into
wbkepler:shader/dxil-dead-code-eliminationfrom
MichaelSmithAI:preserve-distinct-loop-edges
Open

MichaelSmithAI wants to merge 3 commits into
wbkepler:shader/dxil-dead-code-eliminationfrom
MichaelSmithAI:preserve-distinct-loop-edges

Conversation

@MichaelSmithAI

Copy link
Copy Markdown

A conditional can take two different paths back to the same loop header. After dead-code elimination, both paths can be empty. Folding both into their common predecessor loses the distinction between the values the loop header takes from each path.

This change accounts for an already folded successor when deciding whether to fold the other. The source-built regression starts with incoming values 0, 1 and 2 and verifies that the two backedges remain distinguishable while one empty latch is still folded.

Tested on the branch for Marvisak#697 at 2eea8e2. The graph assertion failed on that commit. With this change the Linux shader library suite passed all 59 tests. Microsoft DXV also accepted a source-built compute shader with the corrected graph. Native rendering and title performance were not measured. AI-assisted.

wbkepler and others added 2 commits November 24, 2026 07:57
- Replace fixed-point phi-only liveness in Module::write with a single-pass backward worklist seeded from side-effecting roots (stores, atomics, barriers, void/non-pure calls) and branch conditions across reachable reverse-postorder blocks.

- Omit dead non-phi instructions, cyclic dead phis, unreachable blocks, and unreferenced dx.op declarations from the emitted DXIL module, fold loop latches left empty by DCE, and reuse one record scratch Vec during FUNCTION_BLOCK serialization.

- Prune instruction-driven ShaderFlags (TYPED_UAV_LOADS, WAVE_OPS, INT64, RESOURCE_HEAP, SAMPLER_HEAP) in Shader::finish to those used by surviving instructions so declared flags and SFI0 always match live module usage.

- Add unit and dxil.dll validation tests covering dead instruction/declaration elimination, latch folding, side-effecting atomic preservation, and post-DCE ShaderFlags pruning.
@wbkepler
wbkepler force-pushed the shader/dxil-dead-code-elimination branch from 2eea8e2 to fa8d084 Compare November 24, 2026 16:17
wbkepler pushed a commit that referenced this pull request Nov 25, 2026
Exercise the descriptor cursor regression on the actual heap capacity
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants