Skip to content
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: Clean up redundant type checks after GDV #55124

Closed
wants to merge 20 commits into from

Conversation

EgorBo
Copy link
Member

@EgorBo EgorBo commented Jul 3, 2021

Closes #52370

Repro (DOTNET_TieredPGO=1):

using System.Runtime.CompilerServices;
using System.Threading;

public class Program
{
    public static void Main()
    {
        // Promote Test to tier1 and collect some profile data
        for (int i = 0; i < 100; i++)
        {
            Test();
            Thread.Sleep(16);
        }
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    static B GetB() => new B(); // not inlineable, but returns sealed type

    static A GetA() => GetB();

    [MethodImpl(MethodImplOptions.NoInlining)]
    static int Test()
    {
        return GetA().GetValue();
    }

}

public class A
{
    public virtual int GetValue() => 1;
}

public sealed class B : A
{
    public override int GetValue() => 3;
}

Codegen for Test:

G_M58954_IG01:              ;; offset=0000H
       4883EC28             sub      rsp, 40
						;; bbWeight=1    PerfScore 0.25
G_M58954_IG02:              ;; offset=0004H
       E8C783FEFF           call     Program:GetB():B
       488BC8               mov      rcx, rax
       48B880941DE8F97F0000 mov      rax, 0x7FF9E81D9480
       483901               cmp      qword ptr [rcx], rax
       750A                 jne      SHORT G_M58954_IG04
       B803000000           mov      eax, 3
						;; bbWeight=1    PerfScore 4.75
G_M58954_IG03:              ;; offset=0020H
       4883C428             add      rsp, 40
       C3                   ret      
						;; bbWeight=1    PerfScore 1.25
G_M58954_IG04:              ;; offset=0025H
       FF15B5E83A00         call     [B:GetValue():int:this]
       EBF3                 jmp      SHORT G_M58954_IG03
						;; bbWeight=0    PerfScore 0.00
; Total bytes of code 45

New codegen for Test:

G_M58954_IG01:              ;; offset=0000H
       4883EC28             sub      rsp, 40
						;; bbWeight=1    PerfScore 0.25
G_M58954_IG02:              ;; offset=0004H
       E8C782FEFF           call     Program:GetB():B
       3900                 cmp      dword ptr [rax], eax
       B803000000           mov      eax, 3
						;; bbWeight=1    PerfScore 3.25
G_M58954_IG03:              ;; offset=0010H
       4883C428             add      rsp, 40
       C3                   ret      
						;; bbWeight=1    PerfScore 1.25
; Total bytes of code 21

The fix basically folds trees like:

[000004] -ACXG+------              *  ASG       ref   
[000003] D----+-N----              +--*  LCL_VAR   ref    V01 tmp1         
[000026] --CXG+------              \--*  CALL      ref    Program.GetB


[000013] ---X-+------              *  JTRUE     void  
[000012] J--X-+-N----              \--*  NE        int   
[000011] H----+------                 +--*  CNS_INT(h) long   0x7ff9e8e89480 class
[000010] #--X-+------                 \--*  IND       long  
[000009] -----+------                    \--*  LCL_VAR   ref    V01 tmp1         

where tmp1 is known to be of 0x7ff9e8e89480 class

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Jul 3, 2021
@EgorBo EgorBo marked this pull request as draft July 3, 2021 10:16
@EgorBo EgorBo closed this Jul 28, 2021
@ghost ghost locked as resolved and limited conversation to collaborators Aug 27, 2021
@EgorBo EgorBo reopened this Mar 13, 2022
@EgorBo EgorBo force-pushed the cleanup-gdv-checks branch from 244b3eb to 3c00aa8 Compare March 13, 2022 20:28
@EgorBo EgorBo closed this Mar 16, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Projects
None yet
Development

Successfully merging this pull request may close these issues.

JIT: Fold type checks with GDV
1 participant