Skip to content
This repository has been archived by the owner on Jan 23, 2023. It is now read-only.

Match BOX idioms early in the importer #23550

Merged
merged 1 commit into from
Apr 1, 2019
Merged

Conversation

jkotas
Copy link
Member

@jkotas jkotas commented Mar 29, 2019

This avoids some of the surprise allocations mentioned in #22984, and helps with downstream optimizations in some cases.

@jkotas
Copy link
Member Author

jkotas commented Mar 29, 2019

Number of small improvements in CoreLib R2R image (the CoreLib image is about 2kB smaller with this change). For example:

; Assembly listing for method ThrowHelper:IfNullAndNullsAreIllegalThenThrow(ref,int)

Before:

       sub      rsp, 40
       mov      qword ptr [rsp+20H], rcx

G_M57383_IG02:
       test     rdx, rdx
       je       SHORT G_M57383_IG04

G_M57383_IG03:
       add      rsp, 40
       ret      

G_M57383_IG04:
       mov      ecx, r8d
       call     [ThrowHelper:ThrowArgumentNullException(int)]
       int3     

After:

G_M57383_IG01:
       sub      rsp, 40
       nop      // Argument is not spilled to stack anymore

G_M57383_IG02:
       test     rdx, rdx
       je       SHORT G_M57383_IG04

G_M57383_IG03:
       add      rsp, 40
       ret      

G_M57383_IG04:
       mov      ecx, r8d
       call     [ThrowHelper:ThrowArgumentNullException(int)]
       int3     

@jkotas
Copy link
Member Author

jkotas commented Mar 29, 2019

@AndyAyersMS PTLA

// box + br_true/false
if ((codeAddr + ((codeAddr[0] >= CEE_BRFALSE) ? 5 : 2)) <= codeEndp)
{
if (!(impStackTop().val->gtFlags & GTF_SIDE_EFFECT))
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be better to just spill the side-effects here instead?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it's cleaner like you have it -- leaves the eval stack unmodified when the patterns don't match.

@mikedn
Copy link

mikedn commented Mar 29, 2019

Yay, the JIT team got bigger 😄

@MarcoRossignoli
Copy link
Member

Someone should write a "detailed "book on it, there are a lot of info/book on GC but few info(other than code and old high level BOTR) of this great piece of tech.

Copy link
Member

@AndyAyersMS AndyAyersMS left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changes LGTM.

Interesting that this led to diffs even when optimizing. I would have expected we'd end up with teh same code. Did you look into why this happens? If not, I'll put it on my todo list.

@jkotas
Copy link
Member Author

jkotas commented Apr 1, 2019

Did you look into why this happens?

I have looked into a few of them:

  • The box instruction can fail inlining in shared generic code because of dictionary lookup. When we pick up the box idiom early, the inlining will succeed. IfNullAndNullsAreIllegalThenThrow is method that hits it.
  • The extra locals created by the box expansion do not disappear and affect register allocation.

@jkotas jkotas merged commit 13bc9b7 into dotnet:master Apr 1, 2019
@jkotas jkotas deleted the box-import branch April 6, 2019 13:54
picenka21 pushed a commit to picenka21/runtime that referenced this pull request Feb 18, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants