Repository navigation
Fix strict aliasing in SSE packed vector stores - #356
Merged
Chuck Walbourn (walbourn) merged 2 commits intoOct 16, 2026
Merged
Chuck Walbourn (walbourn) merged 2 commits into
Chuck Walbourn (walbourn) merged 2 commits into
Conversation
The SSE paths of XMStoreColor, XMStoreHalf2 (F16C), XMStoreShortN2, XMStoreShort2 and the 32-bit DEC/BYTE packed stores wrote integer storage through a float* with _mm_store_ss. With strict aliasing (GCC -O2) the compiler may assume that store does not modify the integer member, so a later read of .c or .v can return the previous value. Assign the low 32-bit lane via _mm_cvtsi128_si32 instead, as XMVectorGetIntX already does. This still compiles to a single movd store.
Contributor
Author
|
@microsoft-github-policy-service agree company="Donmakino LLC" |
Collaborator
|
We should confirm MSVC does the optimal thing here. Alternatively, we should use the old pattern guarded with |
MSVC tolerates this type pun, so keep the existing _mm_store_ss store under #ifdef _MSC_VER and use the _mm_cvtsi128_si32 assignment only for other compilers. The MSVC code path is now unchanged from main.
Contributor
Author
|
We went with your second option: the old — ChipLab |
Chuck Walbourn (walbourn)
approved these changes
Oct 16, 2026
Chuck Walbourn (walbourn)
left a comment
Collaborator
There was a problem hiding this comment.
I don't see this issue with MinGW/GCC 16.1, but I'm fine with this change.
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.
The SSE packed stores wrote integer members through a
float*, so GCC at -O2 could return stale values on later reads. Following your review, MSVC keeps the old_mm_store_ssunder#ifdef _MSC_VERand other compilers assign the low lane with_mm_cvtsi128_si32. We couldn't reach MSVC or Compiler Explorer, so MSVC codegen isn't checked, but its path is now identical to main. A new typed-read test fails before and passes after on GCC 12/13 at -O2/-O3.Fixes #355
— ChipLab