Skip to content

Commit

Permalink
JIT: propagate some block assertions after expansion (#75321)
Browse files Browse the repository at this point in the history
In #74384 I modified morph to generate assertions before a block op
was morphed, but after the source and dest were morphed. This misses
generating some assertions that arise once the expanded form is
known.

We now re-run assertion gen on the expanded tree, when we do an
`OneAsgBlock` expansion. Other cases my also prove profitable.

Closes #75229.
  • Loading branch information
AndyAyersMS committed Sep 9, 2022
1 parent b622489 commit 8101ace
Showing 1 changed file with 25 additions and 4 deletions.
29 changes: 25 additions & 4 deletions src/coreclr/jit/morphblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ class MorphInitBlockHelper
virtual void TrySpecialCases();
virtual void MorphStructCases();

void PropagateAssertions();
void PropagateBlockAssertions();
void PropagateExpansionAssertions();

virtual const char* GetHelperName() const
{
Expand Down Expand Up @@ -127,7 +128,7 @@ GenTree* MorphInitBlockHelper::Morph()

PrepareDst();
PrepareSrc();
PropagateAssertions();
PropagateBlockAssertions();
TrySpecialCases();

if (m_transformationDecision == BlockTransformation::Undefined)
Expand All @@ -150,6 +151,8 @@ GenTree* MorphInitBlockHelper::Morph()
}
}

PropagateExpansionAssertions();

assert(m_transformationDecision != BlockTransformation::Undefined);
assert(m_result != nullptr);

Expand Down Expand Up @@ -278,22 +281,40 @@ void MorphInitBlockHelper::PrepareDst()
}

//------------------------------------------------------------------------
// PropagateAssertions: propagate assertions based on the original tree
// PropagateBlockAssertions: propagate assertions based on the original tree
//
// Notes:
// Once the init or copy tree is morphed, assertion gen can no
// longer recognize what it means.
//
// So we generate assertions based on the original tree.
//
void MorphInitBlockHelper::PropagateAssertions()
void MorphInitBlockHelper::PropagateBlockAssertions()
{
if (m_comp->optLocalAssertionProp)
{
m_comp->optAssertionGen(m_asg);
}
}

//------------------------------------------------------------------------
// PropagateExpansionAssertions: propagate assertions based on the
// expanded tree
//
// Notes:
// After the copy/init is expanded, we may see additional expansions
// to generate.
//
void MorphInitBlockHelper::PropagateExpansionAssertions()
{
// Consider doing this for FieldByField as well
//
if (m_comp->optLocalAssertionProp && (m_transformationDecision == BlockTransformation::OneAsgBlock))
{
m_comp->optAssertionGen(m_asg);
}
}

//------------------------------------------------------------------------
// PrepareSrc: Transform the asg src to an appropriate form and initialize member fields
// with information about it.
Expand Down

0 comments on commit 8101ace

Please sign in to comment.