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

JIT: Assume allocations succeed #82961

Merged
merged 2 commits into from
Mar 6, 2023
Merged

Conversation

jakobbotsch
Copy link
Member

We call a NOMEM function when allocations fail that is already marked as no-return, but at least MSVC is not able to pick up on this fact. The result is that all operator new calls end up with an unnecessary null check. This adds an __assume to allow MSVC to recognize that allocations never fail. For other compilers, it uses the preexisting UNREACHABLE() macro, but MSVC was not able to recognize this either.

There was also a workaround for an old VSW bug that I've removed.

We call a NOMEM function when allocations fail that is already marked as
no-return, but at least MSVC is not able to pick up on this fact. The
result is that all operator new calls end up with an unnecessary null
check. This adds an __assume to allow MSVC to recognize that allocations
never fail. For other compilers, it uses the preexisting UNREACHABLE()
macro, but MSVC was not able to recognize this either.

There was also a workaround for an old VSW bug that I've removed.
@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Mar 3, 2023
@ghost ghost assigned jakobbotsch Mar 3, 2023
@ghost
Copy link

ghost commented Mar 3, 2023

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch, @kunalspathak
See info in area-owners.md if you want to be subscribed.

Issue Details

We call a NOMEM function when allocations fail that is already marked as no-return, but at least MSVC is not able to pick up on this fact. The result is that all operator new calls end up with an unnecessary null check. This adds an __assume to allow MSVC to recognize that allocations never fail. For other compilers, it uses the preexisting UNREACHABLE() macro, but MSVC was not able to recognize this either.

There was also a workaround for an old VSW bug that I've removed.

Author: jakobbotsch
Assignees: jakobbotsch
Labels:

area-CodeGen-coreclr

Milestone: -

@jakobbotsch
Copy link
Member Author

Diffs

cc @dotnet/jit-contrib

Comment on lines 238 to 246
#if defined(_MSC_VER)
// MSVC does not handle the other pattern correctly to recognize this fact.
__assume(p != nullptr);
#elif !defined(DEBUG)
if (p == nullptr)
{
UNREACHABLE();
}
#endif
Copy link
Member

Choose a reason for hiding this comment

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

Should there be a general ASSUME(expr) helper that abstracts this?

Copy link
Member Author

Choose a reason for hiding this comment

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

It turns out there is already a COMPILER_ASSUME next to UNREACHABLE that ends up being __assume with the specified expression on MSVC, so I've switched to that.

Copy link
Member

@BruceForstall BruceForstall left a comment

Choose a reason for hiding this comment

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

The TP diffs are amazingly good.

@jakobbotsch jakobbotsch merged commit c0765d3 into dotnet:main Mar 6, 2023
@jakobbotsch jakobbotsch deleted the jit-alloc-nonnull branch March 6, 2023 14:32
@ghost ghost locked as resolved and limited conversation to collaborators Apr 5, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants