Skip to content

Commit

Permalink
Fold more "OBJ(ADDR(LCL))" patterns in multi-reg morphing (#70207)
Browse files Browse the repository at this point in the history
It is unfortunate that we have to expand this code, but it
will avoid diffs for a TYP_STRUCT LCL_FLD change.
  • Loading branch information
SingleAccretion authored Jun 7, 2022
1 parent 019a009 commit eef6c7f
Showing 1 changed file with 23 additions and 16 deletions.
39 changes: 23 additions & 16 deletions src/coreclr/jit/morph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3792,30 +3792,33 @@ GenTree* Compiler::fgMorphMultiregStructArg(CallArg* arg)
GenTree* argValue = argNode; // normally argValue will be arg, but see right below
unsigned structSize = 0;

if (argNode->TypeGet() != TYP_STRUCT)
if (argNode->OperGet() == GT_OBJ)
{
structSize = genTypeSize(argNode->TypeGet());
}
else if (argNode->OperGet() == GT_OBJ)
{
GenTreeObj* argObj = argNode->AsObj();
const ClassLayout* objLayout = argObj->GetLayout();
structSize = objLayout->GetSize();
GenTreeObj* argObj = argNode->AsObj();
ClassLayout* objLayout = argObj->GetLayout();
structSize = objLayout->GetSize();

// If we have a GT_OBJ of a GT_ADDR then we set argValue to the child node of the GT_ADDR.
GenTree* op1 = argObj->gtOp1;
if (op1->OperGet() == GT_ADDR)
// TODO-ADDR: always perform this transformation in local morph and delete this code.
GenTree* addr = argObj->Addr();
if (addr->OperGet() == GT_ADDR)
{
GenTree* underlyingTree = op1->AsOp()->gtOp1;
GenTree* location = addr->AsOp()->gtOp1;

// Only update to the same type.
if (underlyingTree->OperIs(GT_LCL_VAR))
if (location->OperIsLocalRead())
{
const LclVarDsc* varDsc = lvaGetDesc(underlyingTree->AsLclVar());
if (ClassLayout::AreCompatible(varDsc->GetLayout(), objLayout))
if (!location->OperIs(GT_LCL_VAR) ||
!ClassLayout::AreCompatible(lvaGetDesc(location->AsLclVarCommon())->GetLayout(), objLayout))
{
argValue = underlyingTree;
unsigned lclOffset = location->AsLclVarCommon()->GetLclOffs();

location->ChangeType(argObj->TypeGet());
location->SetOper(GT_LCL_FLD);
location->AsLclFld()->SetLclOffs(lclOffset);
location->AsLclFld()->SetLayout(objLayout);
}

argValue = location;
}
}
}
Expand All @@ -3824,6 +3827,10 @@ GenTree* Compiler::fgMorphMultiregStructArg(CallArg* arg)
LclVarDsc* varDsc = lvaGetDesc(argNode->AsLclVarCommon());
structSize = varDsc->lvExactSize;
}
else if (!argNode->TypeIs(TYP_STRUCT))
{
structSize = genTypeSize(argNode);
}
else
{
structSize = info.compCompHnd->getClassSize(objClass);
Expand Down

0 comments on commit eef6c7f

Please sign in to comment.