Skip to content

Commit

Permalink
JIT: run local assertion prop before morphing return of local struct …
Browse files Browse the repository at this point in the history
…to field

In some rare cases (currently only jitstress) morph may miss out in updating a
return of a "struct that can be replaced by its field" with the field, because
we run local assertion prop afterward we check for this update, and assertion
prop, and it may change the local from one that could not be updated into one
that could be.

So do a special run of assertion prop before this update, so that the local we
analyze for possible update is same the one we'll be using in the end.

I tried moving all of this to post-order so local assertion prop only ran
once but that lead to more diffs and some regressions.

Fixes dotnet#74900.
  • Loading branch information
AndyAyersMS committed Sep 8, 2022
1 parent 4cefab0 commit 4795c46
Showing 1 changed file with 12 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/coreclr/jit/morph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10243,6 +10243,18 @@ GenTree* Compiler::fgMorphSmpOp(GenTree* tree, MorphAddrContext* mac, bool* optA
{
op1 = fgMorphRetInd(tree->AsUnOp());
}
// Local assertions may enable zero or copy prop.
//
if (fgGlobalMorph && optLocalAssertionProp && (optAssertionCount > 0) && op1->OperIs(GT_LCL_VAR))
{
GenTree* newOp1 = op1;
while (newOp1 != nullptr)
{
op1 = newOp1;
newOp1 = optAssertionProp(apFull, newOp1, nullptr, nullptr);
}
assert(op1 != nullptr);
}
if (op1->OperIs(GT_LCL_VAR))
{
// With a `genReturnBB` this `RETURN(src)` tree will be replaced by a `ASG(genReturnLocal, src)`
Expand Down

0 comments on commit 4795c46

Please sign in to comment.