Repository navigation
Do not fuse scalar operations in vector_ops when a scalar operand has another type than the result - #707
Open
greenhat wants to merge 1 commit into
Open
Do not fuse scalar operations in vector_ops when a scalar operand has another type than the result#707greenhat wants to merge 1 commit into
vector_ops when a scalar operand has another type than the result#707greenhat wants to merge 1 commit into
Conversation
…an the result `vector_ops` packs the scalar operands of a fused operation into a vector of the result type. A shift amount can have another signedness than the shifted value (`UVec3 >> 1`, the literal is an `i32`), so the packed `OpCompositeConstruct` was invalid and `spirv-val` rejected the module. Such operations now stay scalar.
greenhat
requested review from
Firestar99,
LegNeato and
eddyb
as code owners
November 16, 2026 15:51
Firestar99
reviewed
Nov 16, 2026
Firestar99
left a comment
Member
There was a problem hiding this comment.
I will need some extra time to properly resolve this, I'm unsure:
- why spirv-val if failing here, cause they define themselves that signed and unsigned doesn't actually matter, what matters is the operands themselves.
- if the current fix doesn't affect other stuff
- if we're better off just abandoning signed integers and only emit unsigned. Tried this, but need some other fixups first that will probably ripple through the entire codebase...
This branch has not been deployed
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.
Shifting a
glaminteger vector by an amount of the other signedness does not build.UVec3 >> 1(the literal is ani32) fails inspirv-val:UVec3 >> i32,IVec3 << u32andUVec3 >> IVec3fail the same way.UVec3 >> 1u32builds.The fix and the test were written with an AI coding agent. I reviewed and checked them.
Details
The code emitted for
UVec3 >> 1before the fix:vector_ops(linker/peephole_opts.rs) packs the scalar operands of a fused operation into a vector of the result type. This skips the fusion when a scalar operand has another type than the lane result. These shifts stay scalar: threeOpShiftRightLogical %uintand theOpCompositeConstructof their results, as the pass received them. The fix adds no new instructions, so I did not add a difftest.The new compile test
ui/dis/vector_shift_mixed_signfails without the fix. Its last case (UVec3 >> u32) is still fused into oneOpShiftRightLogical %v3uint, and the expected output of the otherui/distests does not change.Alternatively, we can keep the fused shift and pack the amounts into a vector of their own type (
OpShiftRightLogicalallows it). I did not do it sincevector_opswould have to add anOpTypeVectorto the module when it is missing. Let me know if you want me to implement it.