Skip to content

Commit

Permalink
Some small copy propagation changes (dotnet#66582)
Browse files Browse the repository at this point in the history
* Add asserts

* Remove the quirk comment, replace with a TODO-CQ
  • Loading branch information
SingleAccretion authored and radekdoulik committed Mar 30, 2022
1 parent 45f1173 commit 5bf9b18
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions src/coreclr/jit/copyprop.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -312,7 +312,7 @@ void Compiler::optCopyPropPushDef(GenTreeOp* asg,
{
assert((lclNode->gtFlags & GTF_VAR_DEF) != 0);

// Quirk: do not collect defs from PHIs. Preserves previous behavior.
// TODO-CQ: design better heuristics for propagation and remove this condition.
if (!asg->IsPhiDefn())
{
ssaDefNum = GetSsaNumForLocalVarDef(lclNode);
Expand Down Expand Up @@ -480,10 +480,27 @@ void Compiler::optVnCopyProp()
// TODO-Cleanup: Move this function from Compiler to this class.
m_compiler->optBlockCopyPropPopStacks(block, &m_curSsaName);
}

void PropagateCopies()
{
WalkTree();

#ifdef DEBUG
// Verify the definitions remaining are only those we pushed for parameters.
for (LclNumToLiveDefsMap::KeyIterator iter = m_curSsaName.Begin(); !iter.Equal(m_curSsaName.End()); ++iter)
{
unsigned lclNum = iter.Get();
assert(m_compiler->lvaGetDesc(lclNum)->lvIsParam || (lclNum == m_compiler->info.compThisArg));

CopyPropSsaDefStack* defStack = iter.GetValue();
assert(defStack->Height() == 1);
}
#endif // DEBUG
}
};

CopyPropDomTreeVisitor visitor(this);
visitor.WalkTree();
visitor.PropagateCopies();

// Tracked variable count increases after CopyProp, so don't keep a shorter array around.
// Destroy (release) the varset.
Expand Down

0 comments on commit 5bf9b18

Please sign in to comment.