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

Consolidate importer spilling code #72291

Merged
merged 8 commits into from
Jul 23, 2022

Conversation

SingleAccretion
Copy link
Contributor

@SingleAccretion SingleAccretion commented Jul 15, 2022

Fixes #72133.

Diffs are mostly regressions, with some improvements due to the new logic being less conservative in some cases (not spilling ADDR(LCL_VAR)s as much).

The most common cause of regression is from initobj. Essentially, for IL like below:

ld <some load>
ldloca V01
initboj
ldloc V01
call

We will now get this IR:

ASG
   LCL_VAR V00
   <some load>

ASG
   LCL_VAR V01
   0

CALL
   LCL_VAR V00
   LCL_VAR V01

Instead of:

ASG
   LCL_VAR V01
   0

CALL
   <some load>
   LCL_VAR V01

This is, of course, because the new code (correctly) presumes <some load> could be aliased by the store.

A solution to this could be to enhance the impILConsumesAddr logic to account for initobjs. This, however, is both risky and non-trivial, as there are dependencies (e. g. the single-def logic) on lvHasLdAddrOp. Essentially, it would requires treating ldloca; initobj as equivalent to stloc very early on.

@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 Jul 15, 2022
@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Jul 15, 2022
@ghost
Copy link

ghost commented Jul 15, 2022

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

Issue Details

Fixes #72133.

Author: SingleAccretion
Assignees: -
Labels:

area-CodeGen-coreclr

Milestone: -

@SingleAccretion SingleAccretion changed the title Consolidate spilling code Consolidate importer spilling code Jul 15, 2022
@SingleAccretion SingleAccretion force-pushed the More-Spilling-Fixes-Upstream branch 2 times, most recently from 9771593 to 230661b Compare July 15, 2022 21:33
@SingleAccretion SingleAccretion marked this pull request as ready for review July 18, 2022 17:37
@SingleAccretion
Copy link
Contributor Author

@dotnet/jit-contrib

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.

My preference would be to split this into two PRs, one that is just the fix and the other that cleans up the CHECK_SPILL_ALL stuff, so that it's more obvious where the fix lies.

The comment states we don't need it, which is incorrect.

Diffs are improvements because we block forward substitution of
calls into "ASG(BLK(ADDR(LCL_VAR<field>, ...)))", which allows
morph to leave the "can be replaced with its field" local alone.
Spill "glob refs" on stores to "aliased" locals.
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.

I'm ok taking this now, but we are getting quite close to the date when we'll want to hold off on this sort of thing until after we branch off .NET 7 from main (mid-August).

@AndyAyersMS AndyAyersMS merged commit c624626 into dotnet:main Jul 23, 2022
@SingleAccretion SingleAccretion deleted the More-Spilling-Fixes-Upstream branch July 23, 2022 18:14
jkotas added a commit to jkotas/runtime that referenced this pull request Jul 24, 2022
jkotas added a commit that referenced this pull request Jul 24, 2022
SingleAccretion added a commit to SingleAccretion/runtime that referenced this pull request Jul 24, 2022
* Add tests

* Fix losing GLOB_REF on the LHS

The comment states we don't need it, which is incorrect.

Diffs are improvements because we block forward substitution of
calls into "ASG(BLK(ADDR(LCL_VAR<field>, ...)))", which allows
morph to leave the "can be replaced with its field" local alone.

* Prospective fix

Spill "glob refs" on stores to "aliased" locals.

* Delete now-not-necessary code

* Fix up asserts

* Clean out '(unsigned)CHECK_SPILL_ALL/NONE' casts

* Don't manually spill for 'st[s]fld'

* Revert 'Clean out '(unsigned)CHECK_SPILL_ALL/NONE' casts'
AndyAyersMS pushed a commit that referenced this pull request Jul 26, 2022
* Consolidate importer spilling code (#72291)

* Add tests

* Fix losing GLOB_REF on the LHS

The comment states we don't need it, which is incorrect.

Diffs are improvements because we block forward substitution of
calls into "ASG(BLK(ADDR(LCL_VAR<field>, ...)))", which allows
morph to leave the "can be replaced with its field" local alone.

* Prospective fix

Spill "glob refs" on stores to "aliased" locals.

* Delete now-not-necessary code

* Fix up asserts

* Clean out '(unsigned)CHECK_SPILL_ALL/NONE' casts

* Don't manually spill for 'st[s]fld'

* Revert 'Clean out '(unsigned)CHECK_SPILL_ALL/NONE' casts'

* Fix assignments done via return buffers

The mistake in logic was that the only trees which could modify
unaliased locals are assignments, which is not true, calls can
do that as well.

One day we will move the return buffer handling out of importer,
but until then, special handling is required.

An alternative fix would have been to bring back the explicit
"impSpillLclRefs" to "stloc/starg" code, but that would contradict
the overall goal of consolidating the spilling logic.
SingleAccretion added a commit to SingleAccretion/runtime that referenced this pull request Aug 22, 2022
* Consolidate importer spilling code (dotnet#72291)

* Add tests

* Fix losing GLOB_REF on the LHS

The comment states we don't need it, which is incorrect.

Diffs are improvements because we block forward substitution of
calls into "ASG(BLK(ADDR(LCL_VAR<field>, ...)))", which allows
morph to leave the "can be replaced with its field" local alone.

* Prospective fix

Spill "glob refs" on stores to "aliased" locals.

* Delete now-not-necessary code

* Fix up asserts

* Clean out '(unsigned)CHECK_SPILL_ALL/NONE' casts

* Don't manually spill for 'st[s]fld'

* Revert 'Clean out '(unsigned)CHECK_SPILL_ALL/NONE' casts'

* Fix assignments done via return buffers

The mistake in logic was that the only trees which could modify
unaliased locals are assignments, which is not true, calls can
do that as well.

One day we will move the return buffer handling out of importer,
but until then, special handling is required.

An alternative fix would have been to bring back the explicit
"impSpillLclRefs" to "stloc/starg" code, but that would contradict
the overall goal of consolidating the spilling logic.
@ghost ghost locked as resolved and limited conversation to collaborators Aug 22, 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.

Importer's spilling logic is incomplete in subtle ways
2 participants