-
Notifications
You must be signed in to change notification settings - Fork 4.7k
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 fails to track exact class handles with ternaries in initializers #55079
Comments
A potential fix: EgorBo@692a597 |
Setting this to .NET 6 for now. If time is not enough, we can move to future. |
Moving to 7.0.0, keeping type info for spilled to stack locals looks tricky. |
using System.Runtime.CompilerServices;
using System.Threading;
public static class Tests
{
static void Main()
{
BFactory factory = new BFactory();
for (int i = 0; i < 100; i++)
{
// Test1 is GDV friendly and has "return 42"
//Test1(factory);
// Test2 is not
Test2(factory);
Thread.Sleep(16);
}
}
[MethodImpl(MethodImplOptions.NoInlining)]
static int Test1(AFactory factory)
{
if (factory != null)
{
A a = factory.GetA();
if (a != null)
{
return a.GetValue();
}
}
return 0;
}
[MethodImpl(MethodImplOptions.NoInlining)]
static int Test2(AFactory factory)
{
return factory?.GetA()?.GetValue() ?? 0;
}
}
public class A
{
public virtual int GetValue() => 41;
}
public class B : A
{
public override int GetValue() => 42;
}
public class AFactory
{
public virtual A GetA() => null;
}
public class BFactory : AFactory
{
private static B b = new B();
public override A GetA() => b;
} A similar issue
|
We don't do GDV during late devirt (which typically kicks in when the object being dispatched on is the result of a call). But we should have observed the class anyways and caught this in early devirt. Looks like there is an early out in |
I'll put up a PR later today. |
Update the early bailout in impDevirtualizeCall that gives up if the object class cannot not be determined to check if we can do GDV (guarded devirtualization) based on profile data. Fixes one of the cases noted in dotnet#55079.
Update the early bailout in impDevirtualizeCall that gives up if the object class cannot not be determined to check if we can do GDV (guarded devirtualization) based on profile data. Fixes one of the cases noted in #55079.
Moving to Future, my snippet was fixed by Andy while the Jakob's one is fixed with PGO - PGO applies GDV for that ToString() call and then later VN/CP eliminates the type check |
We don't manage to devirtualize the
ToString
call here because we fail to track the exact class handle. The IL generated seems a bit unfortunate for us:The code ends up as
Funnily enough, value numbering and constant prop ends up loading the method table chunk as a constant.
cc @dotnet/jit-contrib
category:correctness
theme:zero-init
skill-level:expert
cost:medium
impact:medium
The text was updated successfully, but these errors were encountered: