Fix ARM64/ARM64EC minmax_element() family vectorization for unsigned elements#6376
Open
StephanTLavavej wants to merge 2 commits into
Open
Fix ARM64/ARM64EC minmax_element() family vectorization for unsigned elements#6376StephanTLavavej wants to merge 2 commits into
minmax_element() family vectorization for unsigned elements#6376StephanTLavavej wants to merge 2 commits into
Conversation
This comment was marked as resolved.
This comment was marked as resolved.
BillyONeal
reviewed
Jul 22, 2026
BillyONeal
approved these changes
Jul 22, 2026
statementreply
approved these changes
Jul 24, 2026
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.
Fixes #6373, a regression that was introduced by #5949 in the MSVC Build Tools 14.51. Thanks to @statementreply for helping to analyze this bug in the STL Discord. Thanks to randomized testing for finding this.
Our x64/x86 and ARM64/ARM64EC vectorized implementations of the
minmax_element()family share common code, but there's a significant difference: x64/x86 vector instructions are always signed, while ARM64/ARM64EC has signed/unsigned vector instructions. Most of the code correctly handled this, but we weren't properly initializing the values and weren't properly comparing them later. For certain element patterns, this would cause incorrect results to be returned.Disclosure: I used Opus 4.8 to fix this, then cleaned up its work and verified that it matched @statementreply's analysis and my understanding. I wrote the test cases from scratch, where the first one (for
vector<uint8_t>andmin_element()) is directly taken from the original randomized test failure, which is why it looks different.I verified that all of the test cases, including the "extra" one that @statementreply correctly predicted, fail without the fix, except for the
uint64_tcases because we don't vectorize those on ARM64/ARM64EC for performance reasons. (I included the 64-bit elements for completeness, and any possible changes in the future.)The product code isn't heavily commented and generally assumes that the reader has a good understanding of the code. As the existing unsigned-handling code is generally not commented, I felt that it was best to be consistent and not add extra verbose comments for this new stuff, whose purpose is fairly clear in context (and of course enforced by the tests).