Repository navigation
spirv-opt: Keep members of struct type operands in dead members - #6916
Merged
s-perron merged 1 commit intoOct 6, 2026
Merged
Conversation
apollo-2006
marked this pull request as draft
September 30, 2026 17:16
apollo-2006
marked this pull request as ready for review
September 30, 2026 17:16
s-perron
approved these changes
Oct 1, 2026
s-perron
left a comment
Collaborator
There was a problem hiding this comment.
No need for the follow up unless we notice that many member are kept bloating the code size.
EliminateDeadMembersPass marks a struct as used when an instruction it does not handle takes a value of that struct type. It did not look at operands that are types themselves, such as the Message Type of OpAbortKHR or the Base Type of OpUntypedAccessChainKHR. The pass then removed their members, which left an OpAbortKHR whose Message Type no longer matched the Message and an untyped access chain indexing past the end of the struct. Mark type operands as fully used as well.
s-perron
force-pushed
the
dead-members-type-operands
branch
from
October 6, 2026 20:48
13b7948 to
014a6a2
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
I ran into this while running spirv-opt's recipes over glslang's test shaders and validating the output.
--eliminate-dead-members(also part of-Oand-Os) marks a struct as used when an unhandled instruction takes a value of that type, but it never looks at operands that are types themselves. So those structs get their members stripped even though they're still needed.I hit it in two places:
OpAbortKHR: the Message Type struct loses its members, and validation fails ("Type of Message operand does not logically match the type of the Message Type operand").OpUntypedAccessChainKHR: the Base Type struct loses its members, so the access chain ends up indexing out of bounds.The fix marks type operands as fully used in the same fallback that already handles value operands.
On the glslang corpus, all 28
spv.shader.abort*shaders plusspv.structuredDescriptorHeap.BufferReferenceand.AccelerationStructurewere coming out invalid at-Os. With this change all 30 validate, and nothing else changed across 564 shaders × 12 pass sets.One trade-off, for untyped access chains this keeps the whole struct rather than just the indexed members. Tracking the indexed members like the typed access chains do could be a follow-up, and I'm happy to take that on if it's wanted.
Tests: added
KeepAbortMessageTypeMembersandKeepUntypedAccessChainBaseTypeMemberstoeliminate_dead_member_test.cpp. Both fail without the fix.