-
Notifications
You must be signed in to change notification settings - Fork 5.3k
Open
Labels
area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMICLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIneeds-author-actionAn issue or pull request that requires more info or actions from the author.An issue or pull request that requires more info or actions from the author.tenet-performancePerformance related issuePerformance related issueuntriagedNew issue has not been triaged by the area ownerNew issue has not been triaged by the area owner
Description
Currently devirtualization kicks in after a cast to a type for which the method is sealed. Additionally if any type assertions are available (e.g. the a.GetType() == typeof(Exact) branch) the cast itself gets elided too.
However both seem to be required for the code to devirtualize. Instead, I would like to see the following work as well:
using System;
using System.Runtime.CompilerServices;
class C {
public int M(A a)
{
if (a.GetType() == typeof(B))
return a.Do();
return 2;
}
}
abstract class A
{
public abstract int Do();
}
sealed class B : A
{
public override int Do() => 1;
}In this case a.Do(); does not get devirtualized, as we are missing the explicit cast to B.
En3Tho, PaulusParssinen, colejohnson66, omariom and dmitry-azaraev
Metadata
Metadata
Assignees
Labels
area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMICLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIneeds-author-actionAn issue or pull request that requires more info or actions from the author.An issue or pull request that requires more info or actions from the author.tenet-performancePerformance related issuePerformance related issueuntriagedNew issue has not been triaged by the area ownerNew issue has not been triaged by the area owner