-
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
JIT: Stop creating "location" commas #83814
JIT: Stop creating "location" commas #83814
Conversation
A bit too many downstream things to teach about this to avoid diffs.
Tagging subscribers to this area: @JulieLeeMSFT, @jakobbotsch, @kunalspathak Issue DetailsAvoid creating commas that are on the LHS of an assignment or below an ADDR node. These primarily were created by morph which has an I initially tried removing the
|
src/coreclr/jit/morph.cpp
Outdated
if ((op1 != nullptr) && fgIsCommaThrow(op1, true)) | ||
bool mightBeLocation = (tree->OperIsIndir() || tree->OperIsLocal()) && ((tree->gtFlags & GTF_DONT_CSE) != 0); | ||
if (!mightBeLocation) | ||
{ | ||
GenTree* propagatedThrow = fgPropagateCommaThrow(tree, op1->AsOp(), GTF_EMPTY); | ||
if (propagatedThrow != nullptr) | ||
if ((op1 != nullptr) && fgIsCommaThrow(op1, true)) | ||
{ | ||
return propagatedThrow; | ||
GenTree* propagatedThrow = fgPropagateCommaThrow(tree, op1->AsOp(), GTF_EMPTY); | ||
if (propagatedThrow != nullptr) | ||
{ | ||
return propagatedThrow; | ||
} | ||
} | ||
} | ||
|
||
if ((op2 != nullptr) && fgIsCommaThrow(op2, true)) | ||
{ | ||
GenTree* propagatedThrow = fgPropagateCommaThrow(tree, op2->AsOp(), op1->gtFlags & GTF_ALL_EFFECT); | ||
if (propagatedThrow != nullptr) | ||
if ((op2 != nullptr) && fgIsCommaThrow(op2, true)) | ||
{ | ||
return propagatedThrow; | ||
GenTree* propagatedThrow = fgPropagateCommaThrow(tree, op2->AsOp(), op1->gtFlags & GTF_ALL_EFFECT); | ||
if (propagatedThrow != nullptr) | ||
{ | ||
return propagatedThrow; | ||
} |
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.
This transform was creating illegal IR like the following:
fgMorphTree BB01, STMT00017 (after)
[000098] -ACXG+----- ▌ ASG long
[000134] --CXG+-N--- ├──▌ COMMA long
[000137] --CXG+----- │ ├──▌ CALL help void CORINFO_HELP_OVERFLOW
[000136] -----+----- arg0 in rcx │ │ └──▌ CNS_INT int 0
[000142] -----+----- │ └──▌ CNS_INT long 0
[000095] -----+----- └──▌ CNS_INT long 0xFFFFFFFF
/azp run runtime-coreclr jitstress, runtime-coreclr libraries-jitstress |
Azure Pipelines successfully started running 2 pipeline(s). |
/azp run runtime-coreclr jitstress, runtime-coreclr libraries-jitstress |
Azure Pipelines successfully started running 2 pipeline(s). |
This passed jitstress with a failure that looked like #82690. cc @dotnet/jit-contrib PTAL @AndyAyersMS @SingleAccretion Use of |
Diffs seem to be due to new/missed CSE opportunities The TP regressions are the same as in #83590 (comment). Apparently removing the call to |
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.
These can still be created explicitly?
Wondering at what point we can transition from "avoid creating more of these" to "avoid having these all together" ?
There are no known cases where we create these anymore, and we have asserts in block morphing (and |
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.
There is also some code which can be deleted/simplified:
runtime/src/coreclr/jit/valuenum.cpp
Lines 9842 to 9844 in 768c3ff
// We have to handle the case where the LHS is a comma. In that case, we don't evaluate the comma, | |
// and we're really just interested in the effective value. | |
lhs = lhs->gtEffectiveVal(); |
runtime/src/coreclr/jit/optimizer.cpp
Line 8620 in 768c3ff
GenTree* lhs = tree->AsOp()->gtOp1->gtEffectiveVal(/*commaOnly*/ true); |
Nice to see the IR getting better :).
src/coreclr/jit/morph.cpp
Outdated
@@ -11504,6 +11502,13 @@ GenTree* Compiler::fgPropagateCommaThrow(GenTree* parent, GenTreeOp* commaThrow, | |||
assert(fgGlobalMorph); | |||
assert(fgIsCommaThrow(commaThrow)); | |||
|
|||
bool mightBeLocation = (parent->OperIsLocal() || parent->OperIsIndir()) && ((parent->gtFlags & GTF_DONT_CSE) != 0); |
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.
parent->OperIsLocal
looks a bit unnecessary as LCL_VAR/LCL_FLD
LHSs cannot have children, and STORE_LCL_VAR/FLD
(when those start appearing here) won't need to be restricted like this.
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.
Removed that check.
src/coreclr/jit/morphblock.cpp
Outdated
// Data is a location. | ||
tree->Data()->gtFlags |= GTF_DONT_CSE; |
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.
If we're relying on this NO_CSE, seems prudent to set it in import as well.
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 decided to leave this here only, I think we should either set it on all locations in the importer or none of them, and today we don't set it on any of them. As you probably know we rely on this flag for the similar purpose in fgMorphLocalVar
as well.
I guess today only the IND form of locations is allowed for STORE_DYN_BLK
, but you could imagine if we allowed locations in general then something like STORE_DYN_BLK(LCL_VAR int, LCL_VAR int, 4)
would have also been incorrectly handled without this.
Failures are known according to build analysis. |
Avoid creating commas that are on the LHS of an assignment or below an ADDR node.
These primarily were created by morph which has an
IND(COMMA(x, y)) -> COMMA(x, IND(y))
transformation that did not pay attention to whether it was on the left of an assignment.The IR shape is pretty odd; the RHS of these commas are not actually evaluated in the traditional sense, but happen as part of the parent ASG, so the semantics of the construct ends up being confusing.
Additionally it complicates #83590.
I initially tried removing the
IND(COMMA(x, y)) -> COMMA(x, IND(y))
transformation entirely but this has a lot of diffs -- probably a bit of work to teach downstream phases about these new commas would be required. I gave up after doing that in a few separate places.