Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fold obj.GetType to a constant #87101

Merged
merged 4 commits into from
Jun 5, 2023
Merged

Fold obj.GetType to a constant #87101

merged 4 commits into from
Jun 5, 2023

Conversation

EgorBo
Copy link
Member

@EgorBo EgorBo commented Jun 3, 2023

Type Test() => "test".GetType();

Was:

; Method X:Test():System.Type:this
       sub      rsp, 40
       mov      rcx, 0xD1FFAB1E      ; 'test'
       call     System.Object:GetType():System.Type:this
       nop      
       add      rsp, 40
       ret      
; Total bytes of code: 25

Now:

; Method X:Test():System.Type:this
       mov      rax, 0xD1FFAB1E      ; RuntimeType frozen object representing 'System.String'
       ret      
; Total bytes of code: 11

@dotnet-issue-labeler dotnet-issue-labeler bot added the area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI label Jun 3, 2023
@ghost ghost assigned EgorBo Jun 3, 2023
@ghost
Copy link

ghost commented Jun 3, 2023

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

Issue Details
Type Test() => "test".GetType();

Was:

; Method X:Test():System.Type:this
       sub      rsp, 40
       mov      rcx, 0xD1FFAB1E      ; 'test'
       call     System.Object:GetType():System.Type:this
       nop      
       add      rsp, 40
       ret      
; Total bytes of code: 25

Now:

; Method X:Test():System.Type:this
       mov      rax, 0xD1FFAB1E      ; RuntimeType frozen object representing 'System.String'
       ret      
; Total bytes of code: 11
Author: EgorBo
Assignees: EgorBo
Labels:

area-CodeGen-coreclr

Milestone: -

@EgorBo EgorBo marked this pull request as ready for review June 4, 2023 09:12
@EgorBo
Copy link
Member Author

EgorBo commented Jun 4, 2023

Diffs are small: https://dev.azure.com/dnceng-public/public/_build/results?buildId=294970&view=ms.vss-build-web.run-extensions-tab due to new contexts (see missing contexts values).

We already had this optimization (mostly, for value types) this just extends it a bit 🙂 (not sure I understand why so many likes on it 😆)

PTAL @dotnet/jit-contrib

@ShreyasJejurkar
Copy link
Contributor

I love to see this kind of improvement where the number of instructions is going down and down and down! 😅
These little improvements here and there contribute a lot to bigger efforts! 🙌

Keep those coming...🫡🎉

@EgorBo EgorBo merged commit 404aede into dotnet:main Jun 5, 2023
@EgorBo EgorBo deleted the fold-obj-gettype branch June 5, 2023 15:58
@ghost ghost locked as resolved and limited conversation to collaborators Jul 5, 2023
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.

3 participants