-
Notifications
You must be signed in to change notification settings - Fork 4.9k
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
Fix issue with hoisting and copy prop interaction #85493
Conversation
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch Issue DetailsAfter hoisting creates a tree copy, it morphs it. That morph might lose the value numbers on LCL_VAR uses, but leave the SSA numbers. Copy prop was assuming that such a use had a VN. Instead, check this dynamically instead of asserting. Fixes #84619
|
/azp run Fuzzlyn |
Azure Pipelines successfully started running 1 pipeline(s). |
Slight TP cost |
@AndyAyersMS PTAL |
I hate to open a can of worms here, but why does hoisting call morph? Seems like maybe it shouldn't. |
Disabling morphing only causes one family of diffs. Another question, though: why does morphing lose VNs on LCL_VARs? |
The case from #84619 is |
I was wondering if you'd actually see improvements, since hoisting relies on CSE and perhaps morphing the hoisted copy would break CSE (either by changing tree shape so it no longer matches the in-loop tree or perhaps by losing the Oddly we don't check for
Could be there's a missing surgical VN update that could be fixed, you'd have to dig in. |
@BruceForstall you're not waiting on me here, are you? |
No. But the questions asked require investigations, which I've prioritized very low compared to other work (even though it would be nice to get Fuzzlyn cleaner, but it has good baselining anyway) |
After hoisting creates a tree copy, it morphs it. That morph might lose the value numbers on LCL_VAR uses, but leave the SSA numbers. Copy prop was assuming that such a use had a VN. Instead, check this dynamically instead of asserting. Fixes dotnet#84619
If we optimize the cast, call `fgOptimizeCast` to see if it can be optimized further.
@AndyAyersMS I updated this. I found the case that was creating a CAST that wasn't getting fully morphed/optimized, in I also added a unit test. There are a few diffs, with the additional call to There is a bit of TP hit. |
src/coreclr/jit/copyprop.cpp
Outdated
else if (tree->OperIs(GT_LCL_VAR, GT_LCL_FLD) && tree->AsLclVarCommon()->HasSsaName() && | ||
tree->gtVNPair.BothDefined()) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I would recommend removing this check. optCopyProp
doesn't actually depends on the VNs being present for trees it examines, so this is effectively the same as removing the assert.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
optCopyProp
does assert(tree->gtVNPair.BothDefined())
which is why I added this.
But it's true that optCopyProp
does not actually use the tree->gtVNPair
: it looks up the VN in the lvPerSsaData
for the SSA def of the local. Presumably this assert is a partial expression of the expectation that if a local has an SSA number, then its SSA def should have the same VN as the SSA use (I believe that should be true?). It would therefore seem odd to ignore the fact that a lclvar use has no VN but its SSA does, and just use the def. That seems to indicate something is odd/wrong, perhaps due to morph, like what happened here.
Of course, I could remove the assert from optCopyProp
, too.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Presumably this assert is a partial expression of the expectation that if a local has an SSA number, then its SSA def should have the same VN as the SSA use (I believe that should be true?).
Here is how this situation came to be: optCopyProp
used to use the tree VN, but was changed to use the definition VN in #65250, with the main motivation being LCL_FLD
handling. I left the tree VN assert as it seemed valuable on its own (indeed, as you say, to catch missing VNs - we are generally sorely lacking in validating this aspect of morph).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So it seems like I could either:
- Remove both the
tree->gtVNPair.BothDefined()
check here andassert(tree->gtVNPair.BothDefined())
inoptCopyProp
(sooptCopyProp
will no longer check for "missing" VNs), or - Leave it as I've written it -- with more testing/checking than maybe should be required, or
- Something else? (e.g., asserting for and fixing "missing VNs" -- but that seems out of scope for this fix)
Do you have a preference?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My preference would be to check for missing VNs and fix them (leave the assert without the check, or even migrate it to the general loop in optBlockCopyProp
), but barring that removing the assert (1
) seems better.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the SSA checker should also be able to spot missing VNs, though not perhaps in as timely a manner.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the SSA checker should also be able to spot missing VNs, though not perhaps in as timely a manner.
Well, fgDebugCheckSsa()
already has this comment: * Verify VNs on uses match the VN on the def
:-)
Ok, I've removed the assert in |
@AndyAyersMS ping |
ping |
After hoisting creates a tree copy, it morphs it. That morph might lose the value numbers on LCL_VAR uses, but leave the SSA numbers. Copy prop was assuming that such a use had a VN. Instead, check this dynamically instead of asserting.
Fixes #84619