Closed
Description
fgLateDevirtualization
may be able to optimize type compares in cases where type information arrives late. For example a better type can be exposed by inlining or from a readonly static. For example:
class X
{
static object S() => "s";
[MethodImpl(MethodImplOptions.NoInlining)]
static bool IsString()
{
// This should be a jit-time constant
return(S().GetType() == typeof(string));
}
public static int Main()
{
var b = IsString();
return b ? 100 : -1;
}
}
and once dotnet/coreclr#20886 is in place,
class X
{
static readonly object S;
static X()
{
S = "s";
}
[MethodImpl(MethodImplOptions.NoInlining)]
static bool IsString()
{
// This should be a jit-time constant
return(S.GetType() == typeof(string));
}
public static int Main()
{
var p = S;
var b = IsString();
return b ? 100 : -1;
}
}
category:cq
theme:devirtualization
skill-level:intermediate
cost:medium
impact:small