Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
39 changes: 23 additions & 16 deletions src/coreclr/jit/morph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3779,30 +3779,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 @@ -3811,6 +3814,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