Skip to content

Forbid creating layout-less TYP_STRUCT LCL_FLD nodes - #70170

Merged
jakobbotsch merged 5 commits into
dotnet:mainfrom
SingleAccretion:No-Layout-Less-Struct-LclFld
Jun 12, 2022
Merged

jakobbotsch merged 5 commits into
dotnet:mainfrom
SingleAccretion:No-Layout-Less-Struct-LclFld

Conversation

@SingleAccretion

@SingleAccretion SingleAccretion commented Jun 2, 2022 •

Copy link
Copy Markdown
Contributor

This is essentially an improved version of the reverted #66251, addressing the promotion issue that was seen in the subsequent test runs, and simplifying some code.

We're expecting a small number of diffs. Sources:

  1. gtSetEvalOrder sees ADDR(LCL_FLD byte) as a bit costlier than ADDR(LCL_FLD struct).
  2. BLK(ADDR(LCL_VAR) + OFFSET) is now simplified to BLK(ADDR(LCL_FLD)). This can be a size regression in case we would choose to use an inline copy sequence instead of a helper call.
  3. VN-based copy propagation is sometimes not performed because it type checks LCL_VARs and does not type check LCL_FLDs.

There is also a small TP regression that will be payed for with the next change and #69991.

Diffs.

@ghost ghost added 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 labels Jun 2, 2022
@ghost

ghost commented Jun 2, 2022

Copy link
Copy Markdown

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

Issue Details

This is essentially an improved version of the reverted #66251, addressing the promotion issue that was seen in the subsequent test runs, and simplifying some code.

We're expecting a tiny number of diffs. Sources:

  1. gtSetEvalOrder sees ADDR(LCL_FLD byte) as a bit costlier than ADDR(LCL_FLD struct).
  2. BLK(ADDR(LCL_VAR) + OFFSET) is now simplified to BLK(ADDR(LCL_FLD)).
  3. VN-based copy propagation is sometimes not performed because it type checks LCL_VARs and does not type check LCL_FLDs.
Author: SingleAccretion
Assignees: -
Labels:

area-CodeGen-coreclr

Milestone: -

@SingleAccretion
SingleAccretion force-pushed the No-Layout-Less-Struct-LclFld branch 2 times, most recently from 74858dc to 9a3bf94 Compare June 2, 2022 22:05
@SingleAccretion

Copy link
Copy Markdown
Contributor Author

@dotnet/jit-contrib I would like to request stress and libraries stress runs for this change.

@jakobbotsch

Copy link
Copy Markdown
Member

/azp run runtime-coreclr jitstress, runtime-coreclr libraries-jitstress

@azure-pipelines

Copy link
Copy Markdown
Azure Pipelines successfully started running 2 pipeline(s).

@SingleAccretion
SingleAccretion force-pushed the No-Layout-Less-Struct-LclFld branch from 3e39c16 to 13fd37a Compare June 7, 2022 15:58
@SingleAccretion
SingleAccretion marked this pull request as ready for review June 7, 2022 20:29
@SingleAccretion
SingleAccretion marked this pull request as draft June 7, 2022 20:33
Comment thread src/coreclr/jit/morph.cpp Resolved
@SingleAccretion
SingleAccretion marked this pull request as ready for review June 7, 2022 21:20
@SingleAccretion

Copy link
Copy Markdown
Contributor Author

@dotnet/jit-contrib

Comment thread src/coreclr/jit/morph.cpp Outdated
{
break;
}
assert(!gtIsActiveCSE_Candidate(op1)); // GT_ADDRs cannot be CSE candidates.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Hmm, why not?

@SingleAccretion SingleAccretion Jun 12, 2022 •

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Immediate reason is that optIsCSEcandidate always returns false for them.

Reasons why we wouldn't want / be able to CSE them:

  1. CSEing ADDRs that point to tracked locals would break things.
  2. CSEing ADDRs that point to address-exposed locals is likely not very useful because they're cheap to rematerialize (with the exception of non-XARCH platforms + huge frames, I suppose).
  3. CSEing ADDR(HWI/SIMD) would break things.
  4. All other ADDRs (ADDR(IND/BLK/OBJ)) are pretty much transient (get created and then immediately morphed away).

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I don't really see a good reason to bake an implicit assumption that we are never going to be able to CSE GT_ADDR nodes, e.g. in a case like: https://godbolt.org/z/fWEhhGaoK

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

I don't think it is unreasonable to CSE local addresses, but I do not see us doing that with ADDRs, because they will increasingly only get used for tracked locals. Note: your example would have LCL_VAR_ADDR nodes.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

but I do not see us doing that with ADDRs, because they will increasingly only get used for tracked locals

Well, ideally that should not matter. The same example with a promoted struct shows the same codegen difference between Clang/GCC and RyuJIT.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Well, ideally that should not matter

Do you mean not matter as in that we should be able to CSE even addresses of tracked locals? That seems like a hard problem.

Regardless, I will put the CSE check back in.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Do you mean not matter as in that we should be able to CSE even addresses of tracked locals? That seems like a hard problem.

I agree, the bookkeeping required for this would surely make it infeasible/not worth it. I'd just hope this wasn't a global invariant (but given that you are way more familiar with the story around GT_ADDR and the other addressing nodes, maybe this hope is unfounded :) ).

@jakobbotsch

Copy link
Copy Markdown
Member

Failure is #70549

@jakobbotsch
jakobbotsch merged commit d9d6e82 into dotnet:main Jun 12, 2022
@SingleAccretion
SingleAccretion deleted the No-Layout-Less-Struct-LclFld branch June 12, 2022 20:18
@ghost ghost locked as resolved and limited conversation to collaborators Jul 13, 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 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.

3 participants