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

Do not create non-null assertions from location nodes #62743

Merged

Conversation

SingleAccretion
Copy link
Contributor

@SingleAccretion SingleAccretion commented Dec 13, 2021

Some indirection nodes in the compiler represent locations, not values. These are either the LHSs of ASGs or the operands of ADDR nodes (they can be also be chained via COMMAs). We cannot create non-null assertions from such nodes because they do not end up dereferencing their operands.

The problem is that we also cannot detect them reliably. The optimization phases use the GTF_IND_ASG_LHS flag, but that is not strong enough as it does not account for ADDR operands (indeed, we "evaluate" these nodes in VN, wasting memory and potentially confusing people who are new to the compiler). Adding a new flag that will capture the general idea of such a location indirection seems very risky and cumbersome to me, as the flag would need to be maintained throughout all the front-end phases (and the maintenance of such flags is known to be a source of bugs).

Thus, the solution I propose is a conservative one, but correct: rely on GTF_NO_CSE. All locations will be marked with it, and it has already been "plumbed through" the compiler.

Contributes to #13762.

Mixed diffs: the change unblocks some CSEs (because their defs now have the exception sets of their uses).

@ghost ghost added the community-contribution Indicates that the PR has been added by a community member label Dec 13, 2021
@dotnet-issue-labeler dotnet-issue-labeler bot added area-CodeGen-coreclr CLR JIT compiler in src/coreclr/src/jit and related components such as SuperPMI and removed community-contribution Indicates that the PR has been added by a community member labels Dec 13, 2021
@ghost
Copy link

ghost commented Dec 13, 2021

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

Issue Details

Some indirection nodes in the compiler represent locations, not values. These are either the LHSs of ASGs or the operands of ADDR nodes (they can be also be chained via COMMAs). We cannot create non-null assertions from such nodes because they do not end up dereferencing their operands.

The problem is that we also cannot detect them reliably. The optimization phases use the GTF_IND_ASG_LHS flag, but that is not strong enough as it does not account for ADDR operands (indeed, we "evaluate" these nodes in VN, wasting memory and potentially confusing people who are new to the compiler). Adding a new flag that will capture the general idea of such location indirection seems very risky and cumbersome to me, as the flag would need to be maintained throughout all the front-end phases (and the maintenance of such flags is known to be a source of bugs).

Thus, the solution I propose is a conservative one, but correct: rely on GTF_NO_CSE. All locations will be marked with it, and it has already been "plumbed through" the compiler.

Contributes to #13762.

We are expecting mixed diffs: the change unblocks some CSEs (because their defs now have the exception sets of their uses).

Author: SingleAccretion
Assignees: -
Labels:

area-CodeGen-coreclr

Milestone: -

@SingleAccretion SingleAccretion marked this pull request as ready for review December 14, 2021 12:56
@SingleAccretion
Copy link
Contributor Author

@dotnet/jit-contrib

Copy link
Member

@jakobbotsch jakobbotsch left a comment

Choose a reason for hiding this comment

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

LGTM, thanks for the fix!

@jakobbotsch jakobbotsch merged commit 0ef205d into dotnet:main Jan 3, 2022
@SingleAccretion SingleAccretion deleted the Incorrect-Null-Assertions-Fix branch January 4, 2022 13:42
@ghost ghost locked as resolved and limited conversation to collaborators Feb 3, 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.

2 participants