-
Notifications
You must be signed in to change notification settings - Fork 5.2k
disable optimizations for PopCount #99796
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -3436,6 +3436,11 @@ uint32_t BitOperations::Log2(uint64_t value) | |
| // Return Value: | ||
| // The population count (number of bits set) of value | ||
| // | ||
| #if defined(_MSC_VER) | ||
| // Disable optimizations for PopCount to avoid the compiler from generating intrinsics | ||
| // not supported on all platforms. | ||
| #pragma optimize("", off) | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Have we root caused and found a minimal repro for this? Given popcnt is not a x64 baseline instruction, it should not be getting generated without explicit opt in (meaning either we have a cmake/config issue on our end or MSVC has a bug) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it's an MSVC issue, we should ensure an appropriate issue is filed against the compiler to track them fixing this. Alternatively, if Windows has changed requirements at all, we should ensure it's documented and appropriately take advantage of these requirements (I vaguely remember seeing some change where Windows 11 may require SSE4.2 instructions) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
IIRC next update of Windows 11 requires There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should be able to build a repro. I have verified within the debugger that the compiler does generate popcnt, and as Egor points out above looks like a fix has been made recently. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. If it has been fixed already, you should be able to put the workaround under There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yeah checking if we can just pickup the tool update.
Correct Win11 24H2 is expected to require it, but yeah that is a separate discussion. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
makes sense, but we will need to check the exact versions which had the issue (since it affected both 17.8 and 17.9). There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. According to the links I shared:
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. since this is a temporary change, not worth special casing versions in case we get the numbers wrong. The toolset update is going to be in the next few weeks and I can create a revert PR. |
||
| #endif // _MSC_VER | ||
| uint32_t BitOperations::PopCount(uint32_t value) | ||
| { | ||
| #if defined(_MSC_VER) | ||
|
|
@@ -3488,6 +3493,9 @@ uint32_t BitOperations::PopCount(uint64_t value) | |
| return static_cast<uint32_t>(result); | ||
| #endif | ||
| } | ||
| #if defined(_MSC_VER) | ||
| #pragma optimize("", on) | ||
| #endif // _MSC_VER | ||
|
|
||
| //------------------------------------------------------------------------ | ||
| // BitOperations::ReverseBits: Reverses the bits in an integer value | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
note that this disables inlining of these methods too, so we might need to disable the specific optimization if this is perf critical.