Skip to content

spirv-opt: Ignore users outside basic blocks in loop peeling and fusion - #7050

Merged
s-perron merged 1 commit into
KhronosGroup:mainfrom
ilyas-mallah:opt-loop-users-outside-blocks
Dec 3, 2026
Merged

s-perron merged 1 commit into
KhronosGroup:mainfrom
ilyas-mallah:opt-loop-users-outside-blocks

Conversation

@ilyas-mallah

Copy link
Copy Markdown
Contributor

--loop-peeling and --loop-fusion crashed on loops whose values carry RelaxedPrecision, which glslang emits for mediump values. A #version 310 es fragment shader with a mediump loop counter is enough, and -O keeps the decorations.

The def-use manager lists annotations and debug instructions such as OpDecorate and OpName among the users of a value, and they belong to no basic block. Loop::IsLCSSA(), MakeSetClosedSSA() and LoopFusion::UsedInContinueOrConditionBlock() now skip a user without a block, as LoopFission already does. LoopFusion::IsUsedInLoop() now uses Loop::IsInsideLoop(Instruction*), which already handles that case.

The new tests PeelingPassTest.DecoratedLoopValueUsedAfterLoop and FusionPassTest.DecoratedLoopValues crash on main under ASan and UBSan and pass with this change. For glslang output of such a shader, --loop-peeling and --eliminate-local-multi-store --loop-fusion=5 exit 139 with v2025.1 and exit 0 with this change, and spirv-val accepts the output. test_opt and test_opt_loops pass.

@s-perron
s-perron enabled auto-merge (squash) December 3, 2026 15:29
@s-perron
s-perron merged commit 7b8e937 into KhronosGroup:main Dec 3, 2026
25 of 26 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.

3 participants