-
Notifications
You must be signed in to change notification settings - Fork 3.8k
[llvm] Propagate nonnull attribute through LLVM IR #13697
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
Conversation
ada64db to
01082a7
Compare
mono/mini/aot-compiler.c
Outdated
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.
Maybe check the namespace, too. "Reflected" might be a pretty common name for attributes.
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.
Why not to use existing System.Runtime.CompilerServices.MethodImpl attribute with NoOptimization flag instead which this logic should honour anyway?
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.
Interesting. We don't seem to actually use that attribute at all right now outside of monodis.
https://gist.github.com/alexanderkyte/357ac0e85b37b078b17c511da154c473
I guess my concern was that by adding this attribute to a method, we would disable other optimizations.
I can definitely re-use it if that's the case though.
daa5533 to
e5a2efc
Compare
|
Wow Github really mis-orders commits |
e5a2efc to
62f7ed4
Compare
|
Added support to the linker to remove the attribute, so we don't bloat binary sizes. https://gist.github.com/alexanderkyte/84be1514a9c86c5223cd3ff3a2be265f |
|
Waiting on dotnet/linker#506 to bump this |
2c00bb6 to
9b0eb57
Compare
2f670f5 to
9291c99
Compare
Due to issues discussed here, this pass needs to be disabled for the change to be incorporated in the bump. dotnet/linker#541
9291c99 to
c5a60d9
Compare
|
@monojenkins commit csproj |
Summary
This change allows LLVM to identify unnecessary null checks. We mark GOT accesses (including those made by LDSTR) and new object calls as nonnull.
Since LLVM won't propagate this, we propagate from definition to usage, across casts, and from usage to definition (conditionally).
This enables it to remove a significant portion of some benchmarks.
In real-world code, we can expect to see this remove the unnecessary null checks made by private methods.
Example
C#:
Note that the constant strings are trivially non-null. This PR spots and propagates that.
Before:
After:
Note: safepoint in below code is added by backend, not part of this change
Dependencies
This depends on dotnet/linker#528.
TODO: