Skip to content

JIT: Avoid removing multi-use boxes - #72842

Merged
jakobbotsch merged 3 commits into
dotnet:mainfrom
jakobbotsch:fix-72775
Jul 27, 2022
Merged

jakobbotsch merged 3 commits into
dotnet:mainfrom
jakobbotsch:fix-72775

Conversation

@jakobbotsch

Copy link
Copy Markdown
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
@ghost ghost 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

ghost commented Jul 26, 2022

Copy link
Copy Markdown

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

jakobbotsch commented Jul 26, 2022 •

Copy link
Copy Markdown
Member Author

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

@jakobbotsch
jakobbotsch requested a review from AndyAyersMS July 26, 2022 09:41
Comment thread src/coreclr/jit/gentree.h
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
Copy Markdown
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
Copy Markdown
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).

@SingleAccretion SingleAccretion Jul 26, 2022 •

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
Member Author

/backport to release/6.0

@github-actions

Copy link
Copy Markdown
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

Development

Successfully merging this pull request may close these issues.

[libraries-pgo] NRE in System.Text.Json.Serialization.Tests.TypeInfoResolverFunctionalTests.DoNotSerializeValue42

3 participants