Skip to content

spirv-opt: Keep members of struct type operands in dead members - #6916

Merged
s-perron merged 1 commit into
KhronosGroup:mainfrom
apollo-2006:dead-members-type-operands
Oct 6, 2026
Merged

s-perron merged 1 commit into
KhronosGroup:mainfrom
apollo-2006:dead-members-type-operands

Conversation

@apollo-2006

@apollo-2006 apollo-2006 commented Sep 30, 2026 •

Copy link
Copy Markdown
Contributor

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 -O and -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 plus spv.structuredDescriptorHeap.BufferReference and .AccelerationStructure were 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 KeepAbortMessageTypeMembers and KeepUntypedAccessChainBaseTypeMembers to eliminate_dead_member_test.cpp. Both fail without the fix.

@CLAassistant

CLAassistant commented Sep 30, 2026 •

Copy link
Copy Markdown

CLA assistant check
All committers have signed the CLA.

@apollo-2006
apollo-2006 marked this pull request as draft September 30, 2026 17:16
@apollo-2006
apollo-2006 marked this pull request as ready for review September 30, 2026 17:16

@s-perron s-perron left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
s-perron force-pushed the dead-members-type-operands branch from 13b7948 to 014a6a2 Compare October 6, 2026 20:48
@s-perron
s-perron merged commit 6916cf5 into KhronosGroup:main Oct 6, 2026
25 of 27 checks passed
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.

4 participants