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

Remove GTF_GLOB_REF on a few more addressing nodes #68741

Merged
merged 3 commits into from
May 2, 2022

Conversation

jakobbotsch
Copy link
Member

GTF_GLOB_REF is necessary on a GT_ADDR node only if the child actually
uses a tree with this flag as a value (and not as a location). This
removes the flag in a few more places by using IsLocalAddrExpr.

Fixes #68669

I've also improved the assertion for not breaking recognition of the retbuf.
I realized that in release builds even if we did introduce a temp, the noway_assert that I added would pass.

GTF_GLOB_REF is necessary on a GT_ADDR node only if the child actually
uses a tree with this flag as a value (and not as a location). This
removes the flag in a few more places by using IsLocalAddrExpr.

Fixes dotnet#68669
@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 May 1, 2022
@ghost ghost assigned jakobbotsch May 1, 2022
@ghost
Copy link

ghost commented May 1, 2022

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

Issue Details

GTF_GLOB_REF is necessary on a GT_ADDR node only if the child actually
uses a tree with this flag as a value (and not as a location). This
removes the flag in a few more places by using IsLocalAddrExpr.

Fixes #68669

I've also improved the assertion for not breaking recognition of the retbuf.
I realized that in release builds even if we did introduce a temp, the noway_assert that I added would pass.

Author: jakobbotsch
Assignees: -
Labels:

area-CodeGen-coreclr

Milestone: -

@jakobbotsch jakobbotsch changed the title Fewer gtf glob ref on gt addr Remove GTF_GLOB_REF on a few more addressing nodes May 1, 2022
@@ -3085,8 +3085,8 @@ void Compiler::fgDebugCheckFlags(GenTree* tree)
return GenTree::VisitResult::Continue;
});

// ADDR nodes break the "parent flags >= operands flags" invariant for GTF_GLOB_REF.
if (tree->OperIs(GT_ADDR) && op1->OperIs(GT_LCL_VAR, GT_LCL_FLD))
// Addresses of locals never need GTF_GLOB_REF
Copy link
Contributor

Choose a reason for hiding this comment

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

Nit: could you keep the mention of the ADDR in the comment (here and in morph)?

It makes it stand out as the quirk this special handling is (and will help find places that need to be updated when ADDR is deleted).

Copy link
Member Author

Choose a reason for hiding this comment

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

I've readded the check for GT_ADDR, I don't believe we need to handle other cases anyway as they will just be handled when it's their turn in morph anyway.

@jakobbotsch jakobbotsch requested a review from kunalspathak May 2, 2022 17:52
@jakobbotsch
Copy link
Member Author

cc @dotnet/jit-contrib PTAL @kunalspathak, this is a fix for #68669

Copy link
Member

@kunalspathak kunalspathak left a comment

Choose a reason for hiding this comment

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

I realize that we should also check for !varDsc->IsAddressExposed() below:

if (varTypeIsStruct(varDsc) && varDsc->lvIsTemp)

Looking at the tree that you have in the repro, while visiting [000196] , we mark it as address-exposed and then while visiting [000198] we mark it as hidden buffer.

LocalAddressVisitor visiting statement:
STMT00044 ( INL14 @ 0x015[E-] ... ??? ) <- INL12 @ ??? <- INL09 @ 0x00B[E-] <- INLRT @ ???
               [000198] S-C-G-------                        ▌  CALL      void   System.Reflection.TypeLoading.Ecma.MetadataExtensions.GetMethodDefinition
               [000203] ------------ retbuf                 ├──▌  ADDR      byref 
               [000202] -------N----                        │  └──▌  FIELD     struct hackishFieldName
               [000191] ------------                        │     └──▌  ADDR      byref 
               [000192] -------N----                        │        └──▌  LCL_VAR   struct<System.Reflection.TypeLoading.Ecma.EcmaMethodDecoder, 32> V16 tmp14        
               [000200] n----------- arg1                   ├──▌  OBJ       struct<System.Reflection.Metadata.MethodDefinitionHandle, 4>
               [000199] ------------                        │  └──▌  ADDR      byref 
               [000193] -------N----                        │     └──▌  LCL_VAR   struct<System.Reflection.Metadata.MethodDefinitionHandle, 4> V18 tmp16        
               [000196] --C-G------- arg2                   └──▌  CALL      ref    System.Reflection.TypeLoading.Ecma.EcmaMethodDecoder.get_Reader
               [000194] ------------ this                      └──▌  ADDR      byref 
               [000195] -------N----                              └──▌  LCL_VAR   struct<System.Reflection.TypeLoading.Ecma.EcmaMethodDecoder, 32> V16 tmp14        

Local V16 should not be enregistered because: it is address exposed

Local V16 should not be enregistered because: it is hidden buffer struct arg

@ghost ghost added the needs-author-action An issue or pull request that requires more info or actions from the author. label May 2, 2022
@SingleAccretion
Copy link
Contributor

What's the reason for the special handling for address-exposed locals?

(Noting that previously non-exposed locals can become exposed "later on", as late as morph in fact)

@kunalspathak
Copy link
Member

(Noting that previously non-exposed locals can become exposed "later on", as late as morph in fact)

Here we explicitly not mark something address exposed if something was marked as "hidden buffer", so probably we should avoid marking something "hidden buffer" if it is addressed exposed. But yes, it can be marked exposed later on.

@SingleAccretion
Copy link
Contributor

Here we explicitly not mark something address exposed if something was marked as "hidden buffer", so probably we should avoid marking something "hidden buffer" if it is addressed exposed.

Well, the reason we don't mark it exposed is because we can reason about the liveness now.

I suppose the reason for not marking it (RB) would would be to avoid looking at these locals down the line (i. e. save a little throughput).

@jakobbotsch
Copy link
Member Author

I realize that we should also check for !varDsc->IsAddressExposed() below:

It seems weird to me to do that, there is no guarantee that we visited the address-exposing tree before we visit the call here. So this can never be done for correctness, as @SingleAccretion points out above.

@ghost ghost removed the needs-author-action An issue or pull request that requires more info or actions from the author. label May 2, 2022
@kunalspathak
Copy link
Member

there is no guarantee that we visited the address-exposing tree before we visit the call here.

Agree

Copy link
Member

@kunalspathak kunalspathak left a comment

Choose a reason for hiding this comment

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

LGTM

@jakobbotsch jakobbotsch merged commit ff6af23 into dotnet:main May 2, 2022
@jakobbotsch jakobbotsch deleted the fewer-GTF_GLOB_REF-on-GT_ADDR branch May 2, 2022 21:16
@ghost ghost locked as resolved and limited conversation to collaborators Jun 2, 2022
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
3 participants