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

EqualityComparer<string>.Default.Equals is never inlined #88021

Closed
EgorBo opened this issue Jun 25, 2023 · 1 comment · Fixed by #88025
Closed

EqualityComparer<string>.Default.Equals is never inlined #88021

EgorBo opened this issue Jun 25, 2023 · 1 comment · Fixed by #88025
Labels
area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI
Milestone

Comments

@EgorBo
Copy link
Member

EgorBo commented Jun 25, 2023

I was 100% sure I already filed an issue for this but I can't find it so filing again:

bool Test() => EqualityComparer<string>.Default.Equals("str", "str");

Codegen:

; Method Prog:Foo():bool:this
G_M44901_IG01:  ;; offset=0000H
       sub      rsp, 40
       mov      rdx, 0x21700209268      ; 'str'
       mov      rcx, 0x21700209268      ; 'str'
       mov      r11, 0x7FF933EB0330
       call     [r11]System.IEquatable`1[System.__Canon]:Equals(System.__Canon):bool:this
       nop      
       add      rsp, 40
       ret      
; Total bytes of code: 43

Expected codegen:

; Method Prog:Foo():bool:this
       mov      eax, 1
       ret      
; Total bytes of code: 6

Even PGO doesn't help. In fact, it can be simulated as:

public interface IFoo
{
    Type Test();
}

public class Foo<T> : IFoo
{
    public static IFoo Default = new Foo<T>();

    public Type Test() => typeof(T);
}

Type Test() => Foo<string>.Default.Test();

codegen for Test with Dynamic PGO in tier1:

; Assembly listing for method Test():System.Type
       sub      rsp, 40
       mov      rcx, 0x1D0E5C01E30      ; data for Foo`1[System.String]:Default
       mov      rcx, gword ptr [rcx]
       mov      rax, 0x7FF934B30000      ; Foo`1[System.String]
       cmp      qword ptr [rcx], rax
       jne      SHORT G_M16733_IG06
       call     [Foo`1[System.__Canon]:Test():System.Type:this]
G_M16733_IG04:  ;; offset=0026H
       nop      
       add      rsp, 40
       ret      
G_M16733_IG06:  ;; offset=002CH
       mov      r11, 0x7FF933E90480
       call     [r11]IFoo:Test():System.Type:this
       jmp      SHORT G_M16733_IG04
						;; size=15 bbWeight=0 PerfScore 0.00

; Total bytes of code 59
; ============================================================
@ghost ghost added the untriaged New issue has not been triaged by the area owner label Jun 25, 2023
@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 Jun 25, 2023
@ghost
Copy link

ghost commented Jun 25, 2023

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

Issue Details

I was 100% sure I already filed an issue for this but I can't find it so filing again:

bool Test() => EqualityComparer<string>.Default.Equals("str", "str");

Codegen:

; Method Prog:Foo():bool:this
G_M44901_IG01:  ;; offset=0000H
       sub      rsp, 40
       mov      rdx, 0x21700209268      ; 'str'
       mov      rcx, 0x21700209268      ; 'str'
       mov      r11, 0x7FF933EB0330
       call     [r11]System.IEquatable`1[System.__Canon]:Equals(System.__Canon):bool:this
       nop      
       add      rsp, 40
       ret      
; Total bytes of code: 43

Expected codegen:

; Method Prog:Foo():bool:this
       mov      eax, 1
       ret      
; Total bytes of code: 6

PGO doesn't help. In fact, it can be simulated as:

public interface IFoo
{
    Type Test();
}

public class Foo<T> : IFoo
{
    public static IFoo Default = new Foo<T>();

    public Type Test() => typeof(T);
}

Type Test() => Foo<string>.Default.Test();

codegen for Test with Dynamic PGO in tier1:

; Assembly listing for method Test():System.Type
       sub      rsp, 40
       mov      rcx, 0x1D0E5C01E30      ; data for Foo`1[System.String]:Default
       mov      rcx, gword ptr [rcx]
       mov      rax, 0x7FF934B30000      ; Foo`1[System.String]
       cmp      qword ptr [rcx], rax
       jne      SHORT G_M16733_IG06
       call     [Foo`1[System.__Canon]:Test():System.Type:this]
G_M16733_IG04:  ;; offset=0026H
       nop      
       add      rsp, 40
       ret      
G_M16733_IG06:  ;; offset=002CH
       mov      r11, 0x7FF933E90480
       call     [r11]IFoo:Test():System.Type:this
       jmp      SHORT G_M16733_IG04
						;; size=15 bbWeight=0 PerfScore 0.00

; Total bytes of code 59
; ============================================================
Author: EgorBo
Assignees: -
Labels:

area-CodeGen-coreclr, untriaged

Milestone: -

@EgorBo EgorBo removed the untriaged New issue has not been triaged by the area owner label Jun 25, 2023
@EgorBo EgorBo added this to the Future milestone Jun 25, 2023
@ghost ghost added the in-pr There is an active PR which will close this issue when it is merged label Jun 25, 2023
@ghost ghost removed the in-pr There is an active PR which will close this issue when it is merged label Jul 3, 2023
@ghost ghost locked as resolved and limited conversation to collaborators Aug 3, 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 a pull request may close this issue.

1 participant