Closed stephentoub closed 1 year ago
Tagging subscribers to this area: @JulieLeeMSFT See info in area-owners.md if you want to be subscribed.
Author: | stephentoub |
---|---|
Assignees: | - |
Labels: | `area-CodeGen-coreclr`, `untriaged` |
Milestone: | - |
Not related: we should make CastHelpers inlineable (for really hot paths) e.g. LdelemaRef
From my understanding CORINFO_HELP_LDELEMA_REF can be eliminated if it's followed by dereference (IND)
ldelema
does type check. It can be eliminated if you can reason about the exact type of the array. In this specific example, the JIT needs to take advantage of the fact that C
is sealed and the array type is C[]
and thus the type check is guaranteed to succeed. If C
was not sealed, the type check can fail - for example:
using System;
using System.Threading;
public class C
{
private readonly C[] _array = new D[1];
public C Get1() => Volatile.Read(ref _array[0]);
static void Main() { new C().Get1(); }
}
public class D : C { }
Sure! Good pont. Worth noting that even for the following case we currently also end up with an ldelema helper:
public sealed class C
{
private readonly C[] _array;
public C Get2()
{
ref C c = ref _array[0];
return c;
}
}
it also forward-substituted to IND(CORINFO_HELP_LDELEMA_REF)
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