Skip to content

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

@EgorBo

Description

@EgorBo

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
; ============================================================

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions