Skip to content

JIT: We should be able to avoid covariance checks when inlining with exact types #107080

@jakobbotsch

Description

@jakobbotsch
[MethodImpl(MethodImplOptions.NoInlining)]
public static void Foo(List<string> l)
{
    l[0] = "abc";
}

Current codegen:

; Assembly listing for method Program:Foo(System.Collections.Generic.List`1[System.String]) (Tier1)
; Emitting BLENDED_CODE for X64 with AVX - Windows
; Tier1 code
; optimized code
; optimized using Synthesized PGO
; rsp based frame
; partially interruptible
; with Synthesized PGO: fgCalledCount is 100
; No PGO data
; 1 inlinees with PGO data; 0 single block inlinees; 0 inlinees without PGO data
; Final local variable assignments
;
;  V00 arg0         [V00,T00] (  6,  6   )     ref  ->  rbx         class-hnd single-def <System.Collections.Generic.List`1[System.String]>
;  V01 OutArgs      [V01    ] (  1,  1   )  struct (32) [rsp+0x00]  do-not-enreg[XS] addr-exposed "OutgoingArgSpace"
;
; Lcl frame size = 32

G_M31751_IG01:  ;; offset=0x0000
       push     rbx
       sub      rsp, 32
       mov      rbx, rcx
                                                ;; size=8 bbWeight=1 PerfScore 1.50
G_M31751_IG02:  ;; offset=0x0008
       cmp      dword ptr [rbx+0x10], 0
       je       SHORT G_M31751_IG04
       mov      rcx, gword ptr [rbx+0x08]
       xor      edx, edx
       mov      r8, 0x27C2F262D78      ; 'abc'
       call     CORINFO_HELP_ARRADDR_ST
       inc      dword ptr [rbx+0x14]
                                                ;; size=30 bbWeight=1 PerfScore 10.50
G_M31751_IG03:  ;; offset=0x0026
       add      rsp, 32
       pop      rbx
       ret
                                                ;; size=6 bbWeight=1 PerfScore 1.75
G_M31751_IG04:  ;; offset=0x002C
       call     [System.ThrowHelper:ThrowArgumentOutOfRange_IndexMustBeLessException()]
       int3
                                                ;; size=7 bbWeight=0 PerfScore 0.00

; Total bytes of code 51, prolog size 5, PerfScore 13.75, instruction count 15, allocated bytes for code 51 (MethodHash=efae83f8) for method Program:Foo(System.Collections.Generic.List`1[System.String]) (Tier1)
; ============================================================

Expected: no call to CORINFO_HELP_ARRADDR_ST. It seems like we should be able to statically determine here that no covariance check is necessary.

cc @dotnet/jit-contrib, @EgorBo this might be up your alley...

Metadata

Metadata

Assignees

Labels

area-CodeGen-coreclrCLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMIin-prThere is an active PR which will close this issue when it is merged

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions