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

Improve profiled casts #2 #90735

Merged
merged 3 commits into from
Aug 17, 2023
Merged

Improve profiled casts #2 #90735

merged 3 commits into from
Aug 17, 2023

Conversation

EgorBo
Copy link
Member

@EgorBo EgorBo commented Aug 17, 2023

Small clean up + adds new patterns to recognize, e.g.:

class Prog
{
    static void Main()
    {
        for (int i = 0; i < 200; i++)
        {
            Test1<int>(new int[10]);
            Test2(new uint[10]);
            Thread.Sleep(16);
        }
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    // NOTE: won't kick in for shared T
    static bool Test1<T>(object o) => o is IEnumerable<T>;

    [MethodImpl(MethodImplOptions.NoInlining)]
    static bool Test2(object o) => o is int[];
}

Old codegen:

; Assembly listing for method Prog:Test1
       sub      rsp, 40
       mov      rdx, rcx
       mov      rcx, 0x7FF955C08F70      ; IEnumerable`1[int]
       call     [CORINFO_HELP_ISINSTANCEOFANY]
       test     rax, rax
       setne    al
       movzx    rax, al
       add      rsp, 40
       ret      
; Total bytes of code 37


; Assembly listing for method Prog:Test2
       sub      rsp, 40
       mov      rdx, rcx
       mov      rcx, 0x7FF955718230      ; int[]
       call     [CORINFO_HELP_ISINSTANCEOFARRAY]
       test     rax, rax
       setne    al
       movzx    rax, al
       add      rsp, 40
       ret      
; Total bytes of code 37

New codegen:

; Assembly listing for method Prog:Test1
       sub      rsp, 40
       mov      rax, rcx
       test     rax, rax
       je       SHORT G_M13683_IG05
       mov      rdx, 0x7FF955728230      ; int[]
       cmp      qword ptr [rax], rdx
       je       SHORT G_M13683_IG05
       mov      rdx, rcx
       mov      rcx, 0x7FF955BBAAD0      ; IEnumerable`1[int]
       call     CORINFO_HELP_ISINSTANCEOFANY
G_M13683_IG05:
       test     rax, rax
       setne    al
       movzx    rax, al
       add      rsp, 40
       ret      
; Total bytes of code 59


; Assembly listing for method Prog:Test2
       sub      rsp, 40
       mov      rax, rcx
       test     rax, rax
       je       SHORT G_M19173_IG05
       mov      rdx, 0x7FF955DC59E0      ; uint[]
       cmp      qword ptr [rax], rdx
       je       SHORT G_M19173_IG05
       mov      rdx, rcx
       mov      rcx, 0x7FF955748230      ; int[]
       call     CORINFO_HELP_ISINSTANCEOFARRAY
G_M19173_IG05:
       test     rax, rax
       setne    al
       movzx    rax, al
       add      rsp, 40
       ret      
; Total bytes of code 59

castclass is also improved.

@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 Aug 17, 2023
@ghost ghost assigned EgorBo Aug 17, 2023
@ghost
Copy link

ghost commented Aug 17, 2023

Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch
See info in area-owners.md if you want to be subscribed.

Issue Details

Small clean up + adds new patterns to recognize, e.g.:

class Prog
{
    static void Main()
    {
        for (int i = 0; i < 200; i++)
        {
            Test1<int>(new int[10]);
            Test2(new uint[10]);
            Thread.Sleep(16);
        }
    }

    [MethodImpl(MethodImplOptions.NoInlining)]
    // NOTE: won't kick in for shared T
    static bool Test1<T>(object o) => o is IEnumerable<T>;

    [MethodImpl(MethodImplOptions.NoInlining)]
    static bool Test2(object o) => o is int[];
}

Old codegen:

; Assembly listing for method Prog:Test1
       sub      rsp, 40
       mov      rdx, rcx
       mov      rcx, 0x7FF955C08F70      ; IEnumerable`1[int]
       call     [CORINFO_HELP_ISINSTANCEOFANY]
       test     rax, rax
       setne    al
       movzx    rax, al
       add      rsp, 40
       ret      
; Total bytes of code 37


; Assembly listing for method Prog:Test2
       sub      rsp, 40
       mov      rdx, rcx
       mov      rcx, 0x7FF955718230      ; int[]
       call     [CORINFO_HELP_ISINSTANCEOFARRAY]
       test     rax, rax
       setne    al
       movzx    rax, al
       add      rsp, 40
       ret      
; Total bytes of code 37

New codegen:

; Assembly listing for method Prog:Test1
       sub      rsp, 40
       mov      rax, rcx
       test     rax, rax
       je       SHORT G_M13683_IG05
       mov      rdx, 0x7FF955728230      ; int[]
       cmp      qword ptr [rax], rdx
       je       SHORT G_M13683_IG05
       mov      rdx, rcx
       mov      rcx, 0x7FF955BBAAD0      ; IEnumerable`1[int]
       call     CORINFO_HELP_ISINSTANCEOFANY
G_M13683_IG05:
       test     rax, rax
       setne    al
       movzx    rax, al
       add      rsp, 40
       ret      
; Total bytes of code 59


; Assembly listing for method Prog:Test2
       sub      rsp, 40
       mov      rax, rcx
       test     rax, rax
       je       SHORT G_M19173_IG05
       mov      rdx, 0x7FF955DC59E0      ; uint[]
       cmp      qword ptr [rax], rdx
       je       SHORT G_M19173_IG05
       mov      rdx, rcx
       mov      rcx, 0x7FF955748230      ; int[]
       call     CORINFO_HELP_ISINSTANCEOFARRAY
G_M19173_IG05:
       test     rax, rax
       setne    al
       movzx    rax, al
       add      rsp, 40
       ret      
; Total bytes of code 59
Author: EgorBo
Assignees: EgorBo
Labels:

area-CodeGen-coreclr

Milestone: -

@EgorBo
Copy link
Member Author

EgorBo commented Aug 17, 2023

/azp run runtime-coreclr pgo, runtime-coreclr libraries-pgo, runtime-coreclr pgostress

@azure-pipelines
Copy link

Azure Pipelines successfully started running 3 pipeline(s).

@EgorBo
Copy link
Member Author

EgorBo commented Aug 17, 2023

PTAL @AndyAyersMS, I'm going to kick off a perf run with DOTNET_JitProfileCasts=1

@EgorBo
Copy link
Member Author

EgorBo commented Aug 17, 2023

Failure is #90593

@EgorBo EgorBo merged commit 64243bb into dotnet:main Aug 17, 2023
196 of 202 checks passed
@EgorBo EgorBo deleted the improve-profiled-casts branch August 17, 2023 20:56
@ghost ghost locked as resolved and limited conversation to collaborators Sep 17, 2023
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.

2 participants