Skip to content

Commit 84de128

Browse files
Some small copy propagation changes (#66582)
* Add asserts * Remove the quirk comment, replace with a TODO-CQ
1 parent 1a35d27 commit 84de128

File tree

1 file changed

+19
-2
lines changed

1 file changed

+19
-2
lines changed

src/coreclr/jit/copyprop.cpp

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -312,7 +312,7 @@ void Compiler::optCopyPropPushDef(GenTreeOp* asg,
312312
{
313313
assert((lclNode->gtFlags & GTF_VAR_DEF) != 0);
314314

315-
// Quirk: do not collect defs from PHIs. Preserves previous behavior.
315+
// TODO-CQ: design better heuristics for propagation and remove this condition.
316316
if (!asg->IsPhiDefn())
317317
{
318318
ssaDefNum = GetSsaNumForLocalVarDef(lclNode);
@@ -480,10 +480,27 @@ void Compiler::optVnCopyProp()
480480
// TODO-Cleanup: Move this function from Compiler to this class.
481481
m_compiler->optBlockCopyPropPopStacks(block, &m_curSsaName);
482482
}
483+
484+
void PropagateCopies()
485+
{
486+
WalkTree();
487+
488+
#ifdef DEBUG
489+
// Verify the definitions remaining are only those we pushed for parameters.
490+
for (LclNumToLiveDefsMap::KeyIterator iter = m_curSsaName.Begin(); !iter.Equal(m_curSsaName.End()); ++iter)
491+
{
492+
unsigned lclNum = iter.Get();
493+
assert(m_compiler->lvaGetDesc(lclNum)->lvIsParam || (lclNum == m_compiler->info.compThisArg));
494+
495+
CopyPropSsaDefStack* defStack = iter.GetValue();
496+
assert(defStack->Height() == 1);
497+
}
498+
#endif // DEBUG
499+
}
483500
};
484501

485502
CopyPropDomTreeVisitor visitor(this);
486-
visitor.WalkTree();
503+
visitor.PropagateCopies();
487504

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

0 commit comments

Comments
 (0)