Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Conversation

EgorBo
Copy link
Member

@EgorBo EgorBo commented Dec 7, 2023

Contributes to #50915

int Test<T>(T t) => ((IMyInterface)t).M();

interface IMyInterface
{
    int M();
}

struct S : IMyInterface
{
    public int M() => 42;
}

(for T being Nullable<S>)

; Assembly listing for method Program:Test[System.Nullable`1[S]](System.Nullable`1[S]):int
       sub      rsp, 40
       mov      qword ptr [rsp+0x30], rcx
       lea      rdx, [rsp+0x30]
       mov      rcx, 0xD1FFAB1E      ; System.Nullable`1[S]
       call     CORINFO_HELP_BOX_NULLABLE
-      mov      rdx, rax
-      mov      rcx, 0xD1FFAB1E      ; IMyInterface
-      call     CORINFO_HELP_CHKCASTINTERFACE
-      mov      rcx, rax
-      mov      r11, 0xD1FFAB1E      ; code for IMyInterface:M():int:this
-      call     [r11]IMyInterface:M():int:this
-      nop      
+      movsx    rax, byte  ptr [rax+0x08]
+      mov      eax, 42
       add      rsp, 40
       ret      
-; Total bytes of code 69
+; Total bytes of code 44

@ghost ghost added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Dec 7, 2023
@ghost ghost assigned EgorBo Dec 7, 2023
@ghost
Copy link

ghost commented Dec 7, 2023

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

Issue Details
int Test<T>(T t) => ((IMyInterface)t).M();

(for T being Nullable<>)

; Assembly listing for method Program:Test[System.Nullable`1[S]](System.Nullable`1[S]):int
       sub      rsp, 40
       mov      qword ptr [rsp+0x30], rcx
       lea      rdx, [rsp+0x30]
       mov      rcx, 0xD1FFAB1E      ; System.Nullable`1[S]
       call     CORINFO_HELP_BOX_NULLABLE
-      mov      rdx, rax
-      mov      rcx, 0xD1FFAB1E      ; IMyInterface
-      call     CORINFO_HELP_CHKCASTINTERFACE
-      mov      rcx, rax
-      mov      r11, 0xD1FFAB1E      ; code for IMyInterface:M():int:this
-      call     [r11]IMyInterface:M():int:this
-      nop      
+      movsx    rax, byte  ptr [rax+0x08]
+      mov      eax, 42
       add      rsp, 40
       ret      
-; Total bytes of code 69
+; Total bytes of code 44
Author: EgorBo
Assignees: EgorBo
Labels:

area-CodeGen-coreclr

Milestone: -

@EgorBo
Copy link
Member Author

EgorBo commented Dec 7, 2023

@MihuBot

@EgorBo
Copy link
Member Author

EgorBo commented Dec 8, 2023

@dotnet/jit-contrib PTAL, no spmi diffs due to missing context this PR introduces.

Jit-diffs are mostly size regressions because we devirtualize & inline more calls now, Example:
https://www.diffchecker.com/0fz2W9bM/
or
https://www.diffchecker.com/67HMr7qE/ (becomes direct call)

@EgorBo
Copy link
Member Author

EgorBo commented Dec 8, 2023

@MihuBot

@EgorBo EgorBo merged commit 19dafb6 into dotnet:main Dec 8, 2023
@EgorBo EgorBo deleted the optimize-cast-nullable branch December 8, 2023 17:47
@github-actions github-actions bot locked and limited conversation to collaborators Jan 8, 2024
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