Skip to content

IEqualityComparer<T> is not devirtualized with PGO #116055

Open
@EgorBo

Description

@EgorBo

The following code snippet is expected to devirtualize the Equals call with the help of PGO, but it currently does not.

using System.Collections.Generic;
using System.Runtime.CompilerServices;
using System.Threading;

for (int i = 0; i < 300; i++)
{
    Wrapper(EqualityComparer<string>.Default, "11", "12");
    Thread.Sleep(15);
}

[MethodImpl(MethodImplOptions.NoInlining)]
static bool Wrapper<T>(IEqualityComparer<T> comparer, T t1, T t2) 
    => comparer.Equals(t1, t2);

We don't even instrument it, as it's indirect:

------------ BB01 [0000] [000..009) (return), preds={} succs={}

***** BB01 [0000]
STMT00000 ( 0x000[E-] ... 0x008 )
               [000006] DAC-G------                         *  STORE_LCL_VAR long   V05 tmp1         
               [000005] --C-G------                         \--*  CALL help long   CORINFO_HELP_RUNTIMEHANDLE_METHOD
               [000003] !---------- arg0                       +--*  LCL_VAR   long   V00 TypeCtx      
               [000004] H------N--- arg1                       \--*  CNS_INT(h) long   0x7ff9a2addd28 global ptr

***** BB01 [0000]
STMT00001 ( ??? ... ??? )
               [000008] DA---------                         *  STORE_LCL_VAR long   V06 tmp2         
               [000007] -----------                         \--*  LCL_VAR   long   V05 tmp1         

***** BB01 [0000]
STMT00002 ( ??? ... ??? )
               [000011] --CXG------                         *  RETURN    int   
               [000010] --CXG------                         \--*  CALL ind stub int   
               [000000] ----------- this                       +--*  LCL_VAR   ref    V01 arg0         
               [000001] ----------- arg1                       +--*  LCL_VAR   ref    V02 arg1         
               [000002] ----------- arg2                       +--*  LCL_VAR   ref    V03 arg2         
               [000009] ----------- calli tgt                  \--*  LCL_VAR   long   V06 tmp2         

Metadata

Metadata

Assignees

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