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: fgMorphModToSubMulDiv should not reorder operands #65118

Merged
merged 4 commits into from
Feb 11, 2022

Conversation

AndyAyersMS
Copy link
Member

There was existing logic to spill but it was there to avoid duplicating costly trees and was
not considering possible interference. Unfortunately, this method is invoked in morph
preorder and child node flags can't be trusted for interference checks.

So, just always spill.

Doing so lets us clean up some logic later on that needed set reverse ops.

Fixes #65104.

There was existing logic to spill but it was there to avoid duplicating costly trees and was
not considering possible interference. Unfortunately, this method is invoked in morph
preorder and child node flags can't be trusted for interference checks.

So, just always spill.

Doing so lets us clean up some logic later on that needed set reverse ops.

Fixes dotnet#65104.
@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 Feb 10, 2022
@ghost ghost assigned AndyAyersMS Feb 10, 2022
@ghost
Copy link

ghost commented Feb 10, 2022

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

Issue Details

There was existing logic to spill but it was there to avoid duplicating costly trees and was
not considering possible interference. Unfortunately, this method is invoked in morph
preorder and child node flags can't be trusted for interference checks.

So, just always spill.

Doing so lets us clean up some logic later on that needed set reverse ops.

Fixes #65104.

Author: AndyAyersMS
Assignees: -
Labels:

area-CodeGen-coreclr

Milestone: -

@AndyAyersMS
Copy link
Member Author

@jakobbotsch PTAL
cc @dotnet/jit-contrib

If this ends up causing bad diffs we can see if we can do some ad-hoc analysis to avoid spilling unaliased locals.

@AndyAyersMS
Copy link
Member Author

If this ends up causing bad diffs

diffs

Looks like quite a bit more regression than I would have expected. Will need to look deeper. Some of this may be inevitable given safety constraints.

@AndyAyersMS
Copy link
Member Author

Also seeing a few instances of Arm64 hitting

Assertion failed '!"Write to unaliased local overlaps outstanding read"' in 'ArrayLengthArithmeticTests:ArrayLengthMod_cns0(System.Int32[]):int' during 'Rationalize IR' (IL size 6)

So could be something in rationalize needs looking into as well.

@AndyAyersMS
Copy link
Member Author

Updated to minimize diffs.

@AndyAyersMS
Copy link
Member Author

Finally realized yes, we need reverse ops, as we are putting the comma ops in the op2 subtree of the sub. So put that bit back in with a hopefully clearer comment.

@AndyAyersMS
Copy link
Member Author

New diffs look reasonable.

@AndyAyersMS AndyAyersMS merged commit f3eaf31 into dotnet:main Feb 11, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Mar 13, 2022
jakobbotsch added a commit to jakobbotsch/runtime that referenced this pull request Jul 4, 2022
fgMorphModToSubMulDiv tries to check if it is ok to "clone" locals
instead of spilling them by checking for address exposure. This was
necessary because GTF_GLOB_REF is not up-to-date in preorder during
morph, which is when this runs. However, address exposure is not valid
for implicit byrefs at this point, so the check is not enough.

The logic is trying to figure out which of the operands need to be
spilled and which of them can be cloned. However, the logic was also
wrong in the face of potential embedded assignments. Thus, rework it to
be a bit more conservative but correct.

As part of this, remove fgIsSafeToClone and make fgMakeMultiUse less
conservative by avoiding checking for address exposure. This was
probably an attempt at some limited interference checks, but from what I
could see other uses do not need this.

Fix dotnet#65118
TIHan pushed a commit that referenced this pull request Jul 6, 2022
* JIT: Avoid reordering operands in fgMorphModToSubMulDiv

fgMorphModToSubMulDiv tries to check if it is ok to "clone" locals
instead of spilling them by checking for address exposure. This was
necessary because GTF_GLOB_REF is not up-to-date in preorder during
morph, which is when this runs. However, address exposure is not valid
for implicit byrefs at this point, so the check is not enough.

The logic is trying to figure out which of the operands need to be
spilled and which of them can be cloned. However, the logic was also
wrong in the face of potential embedded assignments. Thus, rework it to
be a bit more conservative but correct.

As part of this, remove fgIsSafeToClone and make fgMakeMultiUse less
conservative by avoiding checking for address exposure. This was
probably an attempt at some limited interference checks, but from what I
could see other uses do not need this.

Fix #65118

* Add a test

* Revert unnecessary change

* Switch to gtCloneExpr
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.

JIT: Incorrect result computed with forward sub
2 participants