-
Notifications
You must be signed in to change notification settings - Fork 4.8k
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
Unnecessary LdelemaRef call not elided with Volatile.Read #65789
Comments
Tagging subscribers to this area: @JulieLeeMSFT Issue DetailsConsider the code: using System;
using System.Threading;
public sealed class C
{
private readonly C[] _array;
public C Get1() => Volatile.Read(ref _array[0]);
public C Get2() => _array[0];
} We shouldn't need a helper to read a value from the array, but even though the
|
Not related: we should make CastHelpers inlineable (for really hot paths) e.g. |
|
Sure! Good pont. public sealed class C
{
private readonly C[] _array;
public C Get2()
{
ref C c = ref _array[0];
return c;
}
} it also forward-substituted to |
Consider the code:
We shouldn't need a helper to read a value from the array, but even though the
Volatile.Read
evaporates on x86/64, we're still left with a non-inlined CastHelpers.LdelemaRef call in Get1:SharpLab
category:cq
theme:volatile
The text was updated successfully, but these errors were encountered: