Skip to content

Add DebugBuildIdentifier to the live worklist during initialization#6626

Open
jkwak-work wants to merge 2 commits intoKhronosGroup:mainfrom
jkwak-work:fix/dbi-for-aggressive-dce
Open

Add DebugBuildIdentifier to the live worklist during initialization#6626
jkwak-work wants to merge 2 commits intoKhronosGroup:mainfrom
jkwak-work:fix/dbi-for-aggressive-dce

Conversation

@jkwak-work
Copy link
Copy Markdown

DebugBuildIdentifier was missing from the set of NonSemantic debug instructions added to the worklist in InitializeModuleScopeLiveInstructions. Instead it was handled in ProcessGlobalValues (after the worklist is exhausted) using live_insts_.Set() on its direct operands.

live_insts_.Set() marks an instruction live but does not enqueue it, so transitive operand dependencies are never visited. In shaders where the only use of a type (e.g. OpTypeInt) is through a constant that is itself only referenced by DebugBuildIdentifier's flags argument, the type instruction is not marked live and is incorrectly killed by ADCE.

The surviving constant then references a deleted type, producing invalid SPIR-V. Any subsequent pass that rebuilds the DefUseManager (e.g. CCP) will fail with "Definition is not registered."

Fix: include NonSemanticShaderDebugInfo100DebugBuildIdentifier in the worklist loop alongside the other always-live debug instructions. The worklist's transitive closure correctly marks all operand dependencies live before global-value cleanup runs. The existing special-case code in ProcessGlobalValues becomes unreachable for this opcode (IsLive returns true, so the early continue fires) and is now dead; it is left in placefor safety.

jkwak-work and others added 2 commits April 3, 2026 04:56
DebugBuildIdentifier was missing from the set of NonSemantic debug                                                                             instructions added to the worklist in InitializeModuleScopeLiveInstructions.
Instead it was handled in ProcessGlobalValues (after the worklist is
exhausted) using live_insts_.Set() on its direct operands.

live_insts_.Set() marks an instruction live but does not enqueue it, so
transitive operand dependencies are never visited. In shaders where the
only use of a type (e.g. OpTypeInt) is through a constant that is itself
only referenced by DebugBuildIdentifier's flags argument, the type
instruction is not marked live and is incorrectly killed by ADCE.

The surviving constant then references a deleted type, producing invalid
SPIR-V. Any subsequent pass that rebuilds the DefUseManager (e.g. CCP)
will fail with "Definition is not registered."

Fix: include NonSemanticShaderDebugInfo100DebugBuildIdentifier in the
worklist loop alongside the other always-live debug instructions. The
worklist's transitive closure correctly marks all operand dependencies
live before global-value cleanup runs. The existing special-case code in
ProcessGlobalValues becomes unreachable for this opcode (IsLive returns
true, so the early continue fires) and is now dead; it is left in place
for safety.
Adds AggressiveDCETest.KeepDebugBuildIdentifier to verify that
DebugBuildIdentifier and its transitive operands (OpTypeInt, OpConstant)
are preserved and the output remains valid after ADCE runs.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@jkwak-work
Copy link
Copy Markdown
Author

@SteveUrquhart , can you re-review this PR?
I added the test as you instructed.

@jkwak-work
Copy link
Copy Markdown
Author

Fixes #6619

jkwak-work added a commit to jkwak-work/slang that referenced this pull request Apr 3, 2026
This PR includes the latest SPIRV-Tools and the matching SPIRV-Headers.

This PR also includes a spirv-opt fix that is currently in a review
process:
  KhronosGroup/SPIRV-Tools#6626
github-merge-queue bot pushed a commit to shader-slang/slang that referenced this pull request Apr 3, 2026
This PR includes the latest SPIRV-Tools and the matching SPIRV-Headers.

This PR also includes a spirv-opt fix that is currently in a review
process:
  KhronosGroup/SPIRV-Tools#6626
github-merge-queue bot pushed a commit to shader-slang/slang that referenced this pull request Apr 3, 2026
This PR includes the latest SPIRV-Tools and the matching SPIRV-Headers.

This PR also includes a spirv-opt fix that is currently in a review
process:
  KhronosGroup/SPIRV-Tools#6626
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.

1 participant