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

Skip to content

Conversation

Sergio0694
Copy link
Contributor

@Sergio0694 Sergio0694 commented Jun 15, 2024

Closes #96898

public static Type? Test1<T>() =>
    typeof(T).IsGenericType
    ? typeof(T).GetGenericTypeDefinition()
    : null;

Codegen diffs:

; Assembly listing for method Foo:Test1[System.Collections.Generic.KeyValuePair`2[System.__Canon,int]]():System.Type (FullOpts)

-   sub      rsp, 40
-   mov      qword ptr [rsp+0x20], rcx
-   mov      rcx, qword ptr [rcx+0x40]
-   mov      rcx, qword ptr [rcx]
-   call     CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPE
-   mov      rcx, rax
-   call     [System.RuntimeType:GetGenericTypeDefinition():System.Type:this]
-   nop      
-   add      rsp, 40
+   mov      rax, 0x275000095B0
    ret
public static bool Test2<T>() =>
        typeof(T).IsGenericType &&
        typeof(T).GetGenericTypeDefinition() == typeof(KeyValuePair<,>);

Codegen diffs:

; Assembly listing for method Foo:Test2[System.Collections.Generic.KeyValuePair`2[System.__Canon,int]]():ubyte (FullOpts)

-   sub      rsp, 40
-   mov      qword ptr [rsp+0x20], rcx
-   mov      rcx, qword ptr [rcx+0x40]
-   mov      rcx, qword ptr [rcx]
-   call     CORINFO_HELP_TYPEHANDLE_TO_RUNTIMETYPE
-   mov      rcx, rax
-   call     [System.RuntimeType:GetGenericTypeDefinition():System.Type:this]
-   mov      rcx, 0x19F800095D8      ; 'System.Collections.Generic.KeyValuePair`2[TKey,TValue]'
-   cmp      rax, rcx
-   sete     al
-   movzx    rax, al
-   add      rsp, 40
+   mov      eax, 1
    ret    

Note

Reopening from #97159 because the bot closed that one.

@ghost ghost added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Jun 15, 2024
@dotnet-policy-service dotnet-policy-service bot added the community-contribution Indicates that the PR has been added by a community member label Jun 15, 2024
@Sergio0694 Sergio0694 force-pushed the user/sergiopedri/get-generic-type-definition-intrinsic branch from c507e7c to 5beced9 Compare June 16, 2024 18:53
@Sergio0694
Copy link
Contributor Author

Sergio0694 commented Jun 16, 2024

@MihuBot

@En3Tho
Copy link
Contributor

En3Tho commented Jun 16, 2024

@Sergio0694 wrong command it seems? Box => bot

@Sergio0694
Copy link
Contributor Author

Oops, typo, thank you! 😅

@Sergio0694 Sergio0694 marked this pull request as ready for review June 16, 2024 21:00
@Sergio0694
Copy link
Contributor Author

@MihuBot

@EgorBo
Copy link
Member

EgorBo commented Jun 17, 2024

@MihuBot

@Sergio0694 Sergio0694 force-pushed the user/sergiopedri/get-generic-type-definition-intrinsic branch from 7f0594b to 4cbe7f3 Compare July 19, 2024 18:08
@EgorBo
Copy link
Member

EgorBo commented Jul 19, 2024

Failures are unrelated and changes in the recent force push look good, merging

@EgorBo EgorBo merged commit 5ee8f4a into dotnet:main Jul 19, 2024
@github-actions github-actions bot locked and limited conversation to collaborators Aug 19, 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 community-contribution Indicates that the PR has been added by a community member
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Make Type.IsGenericType and GetGenericTypeDefinition() JIT intrinsics (and JIT time constants)
5 participants