Do not create non-null assertions from location nodes #62743
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Some indirection nodes in the compiler represent locations, not values. These are either the LHSs of
ASG
s or the operands ofADDR
nodes (they can be also be chained viaCOMMA
s). 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 forADDR
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).