Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix vectorized min/max/minmax_element for 64-bit types on x86 #2821

Merged
merged 5 commits into from
Jun 25, 2022

Conversation

StephanTLavavej
Copy link
Member

This fixes a regression caused by #2447 that was specific to 64-bit types on x86, reported by internal VSO-1558536 "[RWC][prod/fe][Regression][x86] LLVM one test 'Profile/c-counter-overflows.c' failed".

Thanks to @AlexGuteniev for finding the root cause and providing the fix. The problem is that _mm_extract_epi32 and _mm_cvtsi128_si32 both return int. By directly casting to _Unsigned_t, i.e. uint64_t in _Minmax_traits_8, high-bit values were being sign-extended, but the desired behavior was zero-extension. Adding initial casts of static_cast<uint32_t> fixes this.

Then, I'm enhancing the test coverage:

  • Adding a few specific test cases that failed.
  • Truly randomizing the test, so that every run provides unique coverage.
  • Using wider distributions of values for the min/max testing, since the limited [1, 20] range concealed this bug. Now, integers use the full range, while floating-point values use a large range centered around 0. (Unfortunately, uniform_real_distribution requires b - a <= max, so we can't generate a full range without extra work. As floating-point is not yet vectorized, I felt that this was sufficient for now.)

Fortunately, this regression has not yet shipped in a Preview.

@StephanTLavavej StephanTLavavej added bug Something isn't working high priority Important! labels Jun 24, 2022
@StephanTLavavej StephanTLavavej requested a review from a team as a code owner June 24, 2022 05:37
@StephanTLavavej StephanTLavavej added this to Final Review in Code Reviews Jun 24, 2022
@CaseyCarter CaseyCarter moved this from Final Review to Ready To Merge in Code Reviews Jun 24, 2022
Copy link
Contributor

@miscco miscco left a comment

Choose a reason for hiding this comment

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

I want to reaffirm my opinion that @AlexGuteniev is a wizard

@StephanTLavavej StephanTLavavej self-assigned this Jun 25, 2022
@StephanTLavavej
Copy link
Member Author

I'm mirroring this to the MSVC-internal repo - please notify me if any further changes are pushed.

@StephanTLavavej StephanTLavavej merged commit 62276be into microsoft:main Jun 25, 2022
Code Reviews automation moved this from Ready To Merge to Done Jun 25, 2022
@StephanTLavavej StephanTLavavej deleted the fix-max-element branch June 25, 2022 23:00
fsb4000 pushed a commit to fsb4000/STL that referenced this pull request Aug 13, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working high priority Important!
Projects
No open projects
Development

Successfully merging this pull request may close these issues.

None yet

6 participants