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

JIT: Avoid removing multi-use boxes #72842

Merged
merged 3 commits into from
Jul 27, 2022
Merged

Conversation

jakobbotsch
Copy link
Member

There was an assumption that the local operand to a GT_BOX node is
single-use which was being violated when GDV clones these as arguments.
We now allow multi-uses of these locals by setting a flag when cloning
and then handle it in gtTryRemoveBoxUpstreamEffects.

There is also GTF_VAR_CLONED that would be set on the local itself, but
given that transformations can affect the operand local node arbitrarily
I went with another of these type of flags on GT_BOX instead.

Fix #72775

There was an assumption that the local operand to a GT_BOX node is
single-use which was being violated when GDV clones these as arguments.
We now allow multi-uses of these locals by setting a flag when cloning
and then handle it in gtTryRemoveBoxUpstreamEffects.

There is also GTF_VAR_CLONED that would be set on the local itself, but
given that transformations can affect the operand local node arbitrarily
I went with another of these type of flags on GT_BOX instead.

Fix dotnet#72775
@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 26, 2022
@ghost ghost assigned jakobbotsch Jul 26, 2022
@ghost
Copy link

ghost commented Jul 26, 2022

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

Issue Details

There was an assumption that the local operand to a GT_BOX node is
single-use which was being violated when GDV clones these as arguments.
We now allow multi-uses of these locals by setting a flag when cloning
and then handle it in gtTryRemoveBoxUpstreamEffects.

There is also GTF_VAR_CLONED that would be set on the local itself, but
given that transformations can affect the operand local node arbitrarily
I went with another of these type of flags on GT_BOX instead.

Fix #72775

Author: jakobbotsch
Assignees: -
Labels:

area-CodeGen-coreclr

Milestone: -

@jakobbotsch
Copy link
Member Author

jakobbotsch commented Jul 26, 2022

Sort of a shame that we do not get rid of the box in the hot path. I guess in general that would require some partial redundancy elimination, or the more ad-hoc fix is to have GDV move and clone the setup statements for arguments that are boxes.
In any case I plan to backport this to .NET 6 (where it also repros) so the simple fix suggested by @AndyAyersMS seems most appropriate here.

cc @dotnet/jit-contrib PTAL @AndyAyersMS

@@ -543,6 +543,7 @@ enum GenTreeFlags : unsigned int
GTF_QMARK_CAST_INSTOF = 0x80000000, // GT_QMARK -- Is this a top (not nested) level qmark created for
// castclass or instanceof?

GTF_BOX_CLONED = 0x40000000, // GT_BOX -- this box and its operand has been cloned, cannot assume it to be single-use anymore
Copy link
Contributor

Choose a reason for hiding this comment

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

The local under the box is also marked as "cloned" -- is a new flag truly needed?

Copy link
Member Author

Choose a reason for hiding this comment

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

Transformations can affect that local in arbitrary ways (I mentioned it above).

Copy link
Contributor

@SingleAccretion SingleAccretion Jul 26, 2022

Choose a reason for hiding this comment

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

Hmm, yes, sorry I missed the description somehow.

I suppose this is more robust in the face of something like:

var sdsuTmp = boxTmp; // Cloned.
Use(BOX(sdsuTmp));

So it is needed.

Copy link
Member Author

Choose a reason for hiding this comment

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

Right, something like that. It would probably be ok in practice, especially since gtTryRemoveBoxUpstreamEffects is only called very early, but given the function name it seems best to make it more robust.

@jakobbotsch
Copy link
Member Author

Failure is #72879

@jakobbotsch jakobbotsch merged commit 7177b9d into dotnet:main Jul 27, 2022
@jakobbotsch jakobbotsch deleted the fix-72775 branch July 27, 2022 14:48
@jakobbotsch
Copy link
Member Author

/backport to release/6.0

@github-actions
Copy link
Contributor

Started backporting to release/6.0: https://github.com/dotnet/runtime/actions/runs/2755682979

@ghost ghost locked as resolved and limited conversation to collaborators Aug 27, 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