这是indexloc提供的服务,不要输入任何密码
Skip to content

Conversation

@nmoinvaz
Copy link
Member

@nmoinvaz nmoinvaz commented Mar 7, 2025

MSVC compiler (VS 17.11.x) incorrectly optimizes the GET_CHUNK_MAG code on older versions. Appears to be resolved in VS 17.13.2. The compiler would optimize the code in such a way that it would cause a decompression failure. It only happens when /Os flag is set.

Summary by CodeRabbit

  • Bug Fixes
    • Addressed a compiler optimization issue affecting builds with older versions of Microsoft Visual Studio, ensuring a more reliable and stable build process without changing the application's functionality.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Mar 7, 2025

Walkthrough

This change adds compiler-specific pragmas around the GET_CHUNK_MAG function in the arch/x86/chunkset_avx512.c file. The pragmas disable optimizations before the function and re-enable them after, but only for MSVC compilers older than version 1943. The modifications address a known compiler bug without altering the function's logic or overall code structure.

Changes

File Path Change Summary
arch/x86/chunkset_avx512.c Added #pragma optimize("", off) before and #pragma optimize("", on) after the GET_CHUNK_MAG function to bypass optimization issues in MSVC.

Possibly related PRs

Suggested reviewers

  • Dead2

📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 50e9ca0 and 665ca3a.

📒 Files selected for processing (1)
  • arch/x86/chunkset_avx512.c (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (200)
  • GitHub Check: macOS Clang ASAN (ARM64)
  • GitHub Check: macOS Clang ASAN
  • GitHub Check: Windows MSVC 2019 v141 Win32
  • GitHub Check: macOS GCC UBSAN
  • GitHub Check: macOS Clang Native Instructions (ARM64)
  • GitHub Check: Windows GCC Native Instructions (AVX)
  • GitHub Check: Windows MSVC 2019 v140 Win64
  • GitHub Check: Windows GCC Compat No Opt
  • GitHub Check: Ubuntu GCC SPARC64
  • GitHub Check: Ubuntu 20.04 Clang 6
  • GitHub Check: Ubuntu GCC AARCH64 ASAN
  • GitHub Check: Ubuntu GCC AARCH64 Compat No Opt UBSAN
  • GitHub Check: Ubuntu GCC AARCH64 No ARMv8 UBSAN
  • GitHub Check: Ubuntu GCC PPC64LE
  • GitHub Check: Ubuntu GCC SSE4.2 UBSAN
  • GitHub Check: Ubuntu GCC AARCH64 No NEON UBSAN
  • GitHub Check: Ubuntu GCC Native Instructions (AVX)
  • GitHub Check: Ubuntu GCC ASAN
  • GitHub Check: Ubuntu 20.04 GCC
  • GitHub Check: Fuzzing
  • GitHub Check: macOS Clang ASAN (ARM64)
  • GitHub Check: macOS Clang ASAN
  • GitHub Check: Windows MSVC 2019 v141 Win32
  • GitHub Check: macOS GCC UBSAN
  • GitHub Check: macOS Clang Native Instructions (ARM64)
  • GitHub Check: Windows GCC Native Instructions (AVX)
  • GitHub Check: Windows MSVC 2019 v140 Win64
  • GitHub Check: Windows GCC Compat No Opt
  • GitHub Check: Ubuntu GCC SPARC64
  • GitHub Check: Ubuntu 20.04 Clang 6
  • GitHub Check: Ubuntu GCC AARCH64 ASAN
  • GitHub Check: Ubuntu GCC AARCH64 Compat No Opt UBSAN
  • GitHub Check: Ubuntu GCC AARCH64 No ARMv8 UBSAN
  • GitHub Check: Ubuntu GCC PPC64LE
  • GitHub Check: Ubuntu GCC SSE4.2 UBSAN
  • GitHub Check: Ubuntu GCC AARCH64 No NEON UBSAN
  • GitHub Check: Ubuntu GCC Native Instructions (AVX)
  • GitHub Check: Ubuntu GCC ASAN
  • GitHub Check: Ubuntu 20.04 GCC
  • GitHub Check: Fuzzing
  • GitHub Check: macOS Clang ASAN (ARM64)
  • GitHub Check: macOS Clang ASAN
  • GitHub Check: Windows MSVC 2019 v141 Win32
  • GitHub Check: macOS GCC UBSAN
  • GitHub Check: macOS Clang Native Instructions (ARM64)
  • GitHub Check: Windows GCC Native Instructions (AVX)
  • GitHub Check: Windows MSVC 2019 v140 Win64
  • GitHub Check: Windows GCC Compat No Opt
  • GitHub Check: Ubuntu GCC SPARC64
  • GitHub Check: Ubuntu 20.04 Clang 6
  • GitHub Check: Ubuntu GCC AARCH64 ASAN
  • GitHub Check: Ubuntu GCC AARCH64 Compat No Opt UBSAN
  • GitHub Check: Ubuntu GCC AARCH64 No ARMv8 UBSAN
  • GitHub Check: Ubuntu GCC PPC64LE
  • GitHub Check: Ubuntu GCC SSE4.2 UBSAN
  • GitHub Check: Ubuntu GCC AARCH64 No NEON UBSAN
  • GitHub Check: Ubuntu GCC Native Instructions (AVX)
  • GitHub Check: Ubuntu GCC ASAN
  • GitHub Check: Ubuntu 20.04 GCC
  • GitHub Check: Fuzzing
  • GitHub Check: macOS Clang ASAN (ARM64)
  • GitHub Check: macOS Clang ASAN
  • GitHub Check: Windows MSVC 2019 v141 Win32
  • GitHub Check: macOS GCC UBSAN
  • GitHub Check: macOS Clang Native Instructions (ARM64)
  • GitHub Check: Windows GCC Native Instructions (AVX)
  • GitHub Check: Windows MSVC 2019 v140 Win64
  • GitHub Check: Windows GCC Compat No Opt
  • GitHub Check: Ubuntu GCC SPARC64
  • GitHub Check: Ubuntu 20.04 Clang 6
  • GitHub Check: Ubuntu GCC AARCH64 ASAN
  • GitHub Check: Ubuntu GCC AARCH64 Compat No Opt UBSAN
  • GitHub Check: Ubuntu GCC AARCH64 No ARMv8 UBSAN
  • GitHub Check: Ubuntu GCC PPC64LE
  • GitHub Check: Ubuntu GCC SSE4.2 UBSAN
  • GitHub Check: Ubuntu GCC AARCH64 No NEON UBSAN
  • GitHub Check: Ubuntu GCC Native Instructions (AVX)
  • GitHub Check: Ubuntu GCC ASAN
  • GitHub Check: Ubuntu 20.04 GCC
  • GitHub Check: Fuzzing
  • GitHub Check: macOS Clang ASAN (ARM64)
  • GitHub Check: macOS Clang ASAN
  • GitHub Check: Windows MSVC 2019 v141 Win32
  • GitHub Check: macOS GCC UBSAN
  • GitHub Check: macOS Clang Native Instructions (ARM64)
  • GitHub Check: Windows GCC Native Instructions (AVX)
  • GitHub Check: Windows MSVC 2019 v140 Win64
  • GitHub Check: Windows GCC Compat No Opt
  • GitHub Check: Ubuntu GCC SPARC64
  • GitHub Check: Ubuntu 20.04 Clang 6
  • GitHub Check: Ubuntu GCC AARCH64 ASAN
  • GitHub Check: Ubuntu GCC AARCH64 Compat No Opt UBSAN
  • GitHub Check: Ubuntu GCC AARCH64 No ARMv8 UBSAN
  • GitHub Check: Ubuntu GCC PPC64LE
  • GitHub Check: Ubuntu GCC SSE4.2 UBSAN
  • GitHub Check: Ubuntu GCC AARCH64 No NEON UBSAN
  • GitHub Check: Ubuntu GCC Native Instructions (AVX)
  • GitHub Check: Ubuntu GCC ASAN
  • GitHub Check: Ubuntu 20.04 GCC
  • GitHub Check: Fuzzing
  • GitHub Check: macOS Clang ASAN (ARM64)
  • GitHub Check: macOS Clang ASAN
  • GitHub Check: Windows MSVC 2019 v141 Win32
  • GitHub Check: macOS GCC UBSAN
  • GitHub Check: macOS Clang Native Instructions (ARM64)
  • GitHub Check: Windows GCC Native Instructions (AVX)
  • GitHub Check: Windows MSVC 2019 v140 Win64
  • GitHub Check: Windows GCC Compat No Opt
  • GitHub Check: Ubuntu GCC SPARC64
  • GitHub Check: Ubuntu 20.04 Clang 6
  • GitHub Check: Ubuntu GCC AARCH64 ASAN
  • GitHub Check: Ubuntu GCC AARCH64 Compat No Opt UBSAN
  • GitHub Check: Ubuntu GCC AARCH64 No ARMv8 UBSAN
  • GitHub Check: Ubuntu GCC PPC64LE
  • GitHub Check: Ubuntu GCC SSE4.2 UBSAN
  • GitHub Check: Ubuntu GCC AARCH64 No NEON UBSAN
  • GitHub Check: Ubuntu GCC Native Instructions (AVX)
  • GitHub Check: Ubuntu GCC ASAN
  • GitHub Check: Ubuntu 20.04 GCC
  • GitHub Check: Fuzzing
  • GitHub Check: macOS Clang ASAN (ARM64)
  • GitHub Check: macOS Clang ASAN
  • GitHub Check: Windows MSVC 2019 v141 Win32
  • GitHub Check: macOS GCC UBSAN
  • GitHub Check: macOS Clang Native Instructions (ARM64)
  • GitHub Check: Windows GCC Native Instructions (AVX)
  • GitHub Check: Windows MSVC 2019 v140 Win64
  • GitHub Check: Windows GCC Compat No Opt
  • GitHub Check: Ubuntu GCC SPARC64
  • GitHub Check: Ubuntu 20.04 Clang 6
  • GitHub Check: Ubuntu GCC AARCH64 ASAN
  • GitHub Check: Ubuntu GCC AARCH64 Compat No Opt UBSAN
  • GitHub Check: Ubuntu GCC AARCH64 No ARMv8 UBSAN
  • GitHub Check: Ubuntu GCC PPC64LE
  • GitHub Check: Ubuntu GCC SSE4.2 UBSAN
  • GitHub Check: Ubuntu GCC AARCH64 No NEON UBSAN
  • GitHub Check: Ubuntu GCC Native Instructions (AVX)
  • GitHub Check: Ubuntu GCC ASAN
  • GitHub Check: Ubuntu 20.04 GCC
  • GitHub Check: Fuzzing
  • GitHub Check: macOS Clang ASAN (ARM64)
  • GitHub Check: macOS Clang ASAN
  • GitHub Check: Windows MSVC 2019 v141 Win32
  • GitHub Check: macOS GCC UBSAN
  • GitHub Check: macOS Clang Native Instructions (ARM64)
  • GitHub Check: Windows GCC Native Instructions (AVX)
  • GitHub Check: Windows MSVC 2019 v140 Win64
  • GitHub Check: Windows GCC Compat No Opt
  • GitHub Check: Ubuntu GCC SPARC64
  • GitHub Check: Ubuntu 20.04 Clang 6
  • GitHub Check: Ubuntu GCC AARCH64 ASAN
  • GitHub Check: Ubuntu GCC AARCH64 Compat No Opt UBSAN
  • GitHub Check: Ubuntu GCC AARCH64 No ARMv8 UBSAN
  • GitHub Check: Ubuntu GCC PPC64LE
  • GitHub Check: Ubuntu GCC SSE4.2 UBSAN
  • GitHub Check: Ubuntu GCC AARCH64 No NEON UBSAN
  • GitHub Check: Ubuntu GCC Native Instructions (AVX)
  • GitHub Check: Ubuntu GCC ASAN
  • GitHub Check: Ubuntu 20.04 GCC
  • GitHub Check: Fuzzing
  • GitHub Check: macOS Clang ASAN (ARM64)
  • GitHub Check: macOS Clang ASAN
  • GitHub Check: Windows MSVC 2019 v141 Win32
  • GitHub Check: macOS GCC UBSAN
  • GitHub Check: macOS Clang Native Instructions (ARM64)
  • GitHub Check: Windows GCC Native Instructions (AVX)
  • GitHub Check: Windows MSVC 2019 v140 Win64
  • GitHub Check: Windows GCC Compat No Opt
  • GitHub Check: Ubuntu GCC SPARC64
  • GitHub Check: Ubuntu 20.04 Clang 6
  • GitHub Check: Ubuntu GCC AARCH64 ASAN
  • GitHub Check: Ubuntu GCC AARCH64 Compat No Opt UBSAN
  • GitHub Check: Ubuntu GCC AARCH64 No ARMv8 UBSAN
  • GitHub Check: Ubuntu GCC PPC64LE
  • GitHub Check: Ubuntu GCC SSE4.2 UBSAN
  • GitHub Check: Ubuntu GCC AARCH64 No NEON UBSAN
  • GitHub Check: Ubuntu GCC Native Instructions (AVX)
  • GitHub Check: Ubuntu GCC ASAN
  • GitHub Check: Ubuntu 20.04 GCC
  • GitHub Check: Fuzzing
  • GitHub Check: macOS Clang ASAN (ARM64)
  • GitHub Check: macOS Clang ASAN
  • GitHub Check: Windows MSVC 2019 v141 Win32
  • GitHub Check: macOS GCC UBSAN
  • GitHub Check: macOS Clang Native Instructions (ARM64)
  • GitHub Check: Windows GCC Native Instructions (AVX)
  • GitHub Check: Windows MSVC 2019 v140 Win64
  • GitHub Check: Windows GCC Compat No Opt
  • GitHub Check: Ubuntu GCC SPARC64
  • GitHub Check: Ubuntu 20.04 Clang 6
  • GitHub Check: Ubuntu GCC AARCH64 ASAN
  • GitHub Check: Ubuntu GCC AARCH64 Compat No Opt UBSAN
  • GitHub Check: Ubuntu GCC AARCH64 No ARMv8 UBSAN
  • GitHub Check: Ubuntu GCC PPC64LE
  • GitHub Check: Ubuntu GCC SSE4.2 UBSAN
  • GitHub Check: Ubuntu GCC AARCH64 No NEON UBSAN
  • GitHub Check: Ubuntu GCC Native Instructions (AVX)
  • GitHub Check: Ubuntu GCC ASAN
  • GitHub Check: Ubuntu 20.04 GCC
  • GitHub Check: Fuzzing
🔇 Additional comments (1)
arch/x86/chunkset_avx512.c (1)

101-104: Pragmas correctly address the MSVC compiler optimization bug

The added compiler-specific pragmas appropriately disable optimizations for the GET_CHUNK_MAG function in MSVC versions prior to 17.13 (represented by _MSC_VER 1943), which aligns perfectly with the PR objective. This is a well-targeted fix for the reported decompression failures in older compiler versions without altering any functional code.

Also applies to: 135-137

✨ Finishing Touches
  • 📝 Generate Docstrings

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@nmoinvaz nmoinvaz requested a review from KungFuJesus March 7, 2025 03:03
@nmoinvaz nmoinvaz changed the title Disable MSVC optimizations for AVX512 GET_CHUNK_MAG #1883 Disable MSVC optimizations for AVX512 GET_CHUNK_MAG Mar 7, 2025
MSVC compiler (VS 17.11.x) incorrectly optimizes the GET_CHUNK_MAG code on
older versions. Appears to be resolved in VS 17.13.2. The compiler would
optimize the code in such a way that it would cause a decompression failure.
It only happens when /Os flag is set.
@codecov
Copy link

codecov bot commented Mar 7, 2025

Codecov Report

All modified and coverable lines are covered by tests ✅

Project coverage is 82.52%. Comparing base (50e9ca0) to head (665ca3a).
Report is 4 commits behind head on develop.

Additional details and impacted files
@@             Coverage Diff              @@
##           develop    #1884       +/-   ##
============================================
+ Coverage    42.10%   82.52%   +40.41%     
============================================
  Files           71      141       +70     
  Lines         7353    12672     +5319     
  Branches      1265     2909     +1644     
============================================
+ Hits          3096    10457     +7361     
+ Misses        4035     1243     -2792     
- Partials       222      972      +750     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.


/* MSVC compiler decompression bug when optimizing for size */
#if defined(_MSC_VER) && _MSC_VER < 1943
# pragma optimize("", off)
Copy link
Collaborator

Choose a reason for hiding this comment

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

Does it still work if the first parameter is "t", as it would not disable optimizations when /Ot is enabled.

Copy link
Member Author

Choose a reason for hiding this comment

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

I tried it but it does not work right.

Copy link
Collaborator

Choose a reason for hiding this comment

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

/Ot optimizes for speed, so the comment is then kind of inaccurate...

Copy link
Member Author

Choose a reason for hiding this comment

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

Don't quite understand your last comment. That optimization string argument only works if you are starting from enabling optimization, not starting from disabling optimization.

Copy link
Collaborator

@mtl1979 mtl1979 Mar 7, 2025

Choose a reason for hiding this comment

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

/Ot and /Os are mutually exclusive, however both also enable for example /Og (common sub-expression elimination). With current patch, it will disable all optimizations and thus degrade performance even if optimizing for speed.

Basically what I was saying was, that disable /Os and enable /Ot instead... might need two pragma lines to do that...

Something like:

#  pragma optimize("s", off)
#  pragma optimize("t", on)

@KungFuJesus
Copy link
Contributor

I'm wondering if we could find a lower bound for the bug, too. It'd be great to bookend this check between versions.

@nmoinvaz
Copy link
Member Author

nmoinvaz commented Mar 7, 2025

That is a lot of work. There is no easy way to switch back to an older version of MSVC like there is with Linux packages.

@mtl1979
Copy link
Collaborator

mtl1979 commented Mar 7, 2025

That is a lot of work. There is no easy way to switch back to an older version of MSVC like there is with Linux packages.

We could try to clamp it to specific toolchain. As said reverting to older build of same toolchain version is too much hassle. If both v142 and v143 have the bug then we don't need to worry about v141 or older as those are out of support too. Not sure which toolchain introduced AVX512 support as my CPU does not support it.

Visual Studio Installer can install multiple builds of same toolchain but I don't know how CMake can switch between them.

@phprus
Copy link
Contributor

phprus commented Mar 7, 2025

Specify the toolset version:

cmake ... -T "v142,version=14.29.30133"

https://cmake.org/cmake/help/v3.25/variable/CMAKE_GENERATOR_TOOLSET.html

@mtl1979
Copy link
Collaborator

mtl1979 commented Mar 7, 2025

Specify the toolset version:

cmake ... -T "v142,version=14.29.30133"

https://cmake.org/cmake/help/v3.25/variable/CMAKE_GENERATOR_TOOLSET.html

That works once per build directory... Need to use different directory or remove the cache and generated files before switching to another toolchain version/build...

@nmoinvaz
Copy link
Member Author

https://x.com/i/grok/share/XwMErXewB6EjJK3X2owak0A6U

I don't really have plans to check older versions as this change is limited to one tiny function. If somebody else wants to do it, I would appreciate it, but I don't think it's really necessary.

@Dead2 Dead2 merged commit d065242 into zlib-ng:develop Mar 26, 2025
229 of 236 checks passed
@pps83
Copy link
Contributor

pps83 commented Apr 22, 2025

@nmoinvaz I've seen ms compiler fail in in similar cases with heavy intrisic use. When I tried to debug them, I noticed that by placing some printf's such issues often evaporated. After careful "optimization" of such "fix", it looks like often placing a __nop(); somewhere in the middle of the function for affected versions of ms compiler is enough. Here's one such fix: abseil/abseil-cpp@25fb731

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Architecture Architecture specific bug Build Env

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants