Skip to content
Merged
Show file tree
Hide file tree
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
9 changes: 9 additions & 0 deletions src/coreclr/jit/forwardsub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -665,6 +665,15 @@ bool Compiler::fgForwardSubStatement(Statement* stmt)

// Quirks:
//
// Don't substitute nodes "AddFinalArgsAndDetermineABIInfo" doesn't handle into struct args.
//
if (fsv.IsCallArg() && fsv.GetNode()->TypeIs(TYP_STRUCT) &&
!fwdSubNode->OperIs(GT_OBJ, GT_LCL_VAR, GT_LCL_FLD, GT_MKREFANY))
{
JITDUMP(" use is a struct arg; fwd sub node is not OBJ/LCL_VAR/LCL_FLD/MKREFANY\n");
return false;
}

// We may sometimes lose or change a type handle. Avoid substituting if so.
//
if (gtGetStructHandleIfPresent(fwdSubNode) != gtGetStructHandleIfPresent(fsv.GetNode()))
Expand Down
3 changes: 3 additions & 0 deletions src/coreclr/jit/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -597,6 +597,9 @@ ClassLayout* GenTree::GetLayout(Compiler* compiler) const
case GT_BLK:
return AsBlk()->GetLayout();

case GT_MKREFANY:
return compiler->typGetObjLayout(compiler->impGetRefAnyClass());

default:
unreached();
}
Expand Down
44 changes: 21 additions & 23 deletions src/coreclr/jit/lclmorph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1049,10 +1049,9 @@ class LocalAddressVisitor final : public GenTreeVisitor<LocalAddressVisitor>
return IndirTransform::None;
}

if ((user == nullptr) || !user->OperIs(GT_ASG, GT_RETURN))
if ((user == nullptr) || !user->OperIs(GT_ASG, GT_CALL, GT_RETURN))
{
// TODO-ADDR: call args require extra work because currently they must
// be wrapped in OBJ nodes so we can't replace those with local nodes.
// TODO-ADDR: remove unused indirections.
return IndirTransform::None;
}

Expand All @@ -1075,7 +1074,6 @@ class LocalAddressVisitor final : public GenTreeVisitor<LocalAddressVisitor>
//
enum class StructMatch
{
Exact,
Compatible,
Partial
};
Expand All @@ -1084,44 +1082,44 @@ class LocalAddressVisitor final : public GenTreeVisitor<LocalAddressVisitor>
assert(varDsc->GetLayout() != nullptr);

StructMatch match = StructMatch::Partial;
if (val.Offset() == 0)
if ((val.Offset() == 0) && ClassLayout::AreCompatible(indirLayout, varDsc->GetLayout()))
{
if (indirLayout->GetClassHandle() == varDsc->GetStructHnd())
{
match = StructMatch::Exact;
}
else if (ClassLayout::AreCompatible(indirLayout, varDsc->GetLayout()))
{
match = StructMatch::Compatible;
}
match = StructMatch::Compatible;
}

// Current matrix of matches/users/types:
//
// |------------|------|-------------|---------|
// | STRUCT | CALL | ASG | RETURN |
// |------------|------|-------------|---------|
// | Exact | None | LCL_VAR | LCL_VAR |
// | Compatible | None | LCL_VAR | LCL_VAR |
// | Partial | None | OBJ/LCL_FLD | LCL_FLD |
// |------------|------|-------------|---------|
// |------------|---------|-------------|---------|
// | STRUCT | CALL(*) | ASG | RETURN |
// |------------|---------|-------------|---------|
// | Compatible | LCL_VAR | LCL_VAR | LCL_VAR |
// | Partial | LCL_FLD | OBJ/LCL_FLD | LCL_FLD |
// |------------|---------|-------------|---------|
//
// * - On Windows x64 only.
//
// |------------|------|------|--------|----------|
// | SIMD | CALL | ASG | RETURN | HWI/SIMD |
// |------------|------|------|--------|----------|
// | Exact | None | None | None | None |
// | Compatible | None | None | None | None |
// | Partial | None | None | None | None |
// |------------|------|------|--------|----------|
//
// TODO-ADDR: delete all the "None" entries and always
// transform local nodes into LCL_VAR or LCL_FLD.

assert(indir->TypeIs(TYP_STRUCT) && user->OperIs(GT_ASG, GT_RETURN));
assert(indir->TypeIs(TYP_STRUCT) && user->OperIs(GT_ASG, GT_CALL, GT_RETURN));

*pStructLayout = indirLayout;

if ((match == StructMatch::Exact) || (match == StructMatch::Compatible))
if (user->IsCall())
{
#ifndef WINDOWS_AMD64_ABI
return IndirTransform::None;
#endif // !WINDOWS_AMD64_ABI
}

if (match == StructMatch::Compatible)
{
return IndirTransform::LclVar;
}
Expand Down
36 changes: 4 additions & 32 deletions src/coreclr/jit/morph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2347,30 +2347,9 @@ void CallArgs::AddFinalArgsAndDetermineABIInfo(Compiler* comp, GenTreeCall* call
GenTree* actualArg = argx->gtEffectiveVal(true /* Commas only */);

// Here we look at "actualArg" to avoid calling "getClassSize".
if (actualArg->TypeGet() == TYP_STRUCT)
{
switch (actualArg->OperGet())
{
case GT_OBJ:
structSize = actualArg->AsObj()->Size();
break;
case GT_LCL_VAR:
structSize = comp->lvaGetDesc(actualArg->AsLclVarCommon())->lvExactSize;
break;
case GT_MKREFANY:
structSize = comp->info.compCompHnd->getClassSize(argSigClass);
break;
default:
BADCODE("illegal argument tree: cannot determine size for ABI handling");
break;
}
}
else
{
structSize = genTypeSize(actualArg);
}
structSize = actualArg->TypeIs(TYP_STRUCT) ? actualArg->GetLayout(comp)->GetSize() : genTypeSize(actualArg);
Comment on lines 2349 to +2350
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe this is proof that we should actually be storing ClassLayout* instead of the class handle in CallArg?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps, I am not sure. Essentially, the question is if we view the fact layout carries a handle to be a coincidence/artifact or its intrinsic property.

I think it would be beneficial to at some point move away from using handles in IR at large, and would that involve removing handles from layouts I do not know (yet).


assert(structSize = comp->info.compCompHnd->getClassSize(argSigClass));
assert(structSize == comp->info.compCompHnd->getClassSize(argSigClass));
}
#if defined(TARGET_AMD64)
#ifdef UNIX_AMD64_ABI
Expand Down Expand Up @@ -3190,15 +3169,8 @@ GenTreeCall* Compiler::fgMorphArgs(GenTreeCall* call)
unsigned originalSize;
if (argObj->TypeGet() == TYP_STRUCT)
{
if (argObj->OperIs(GT_OBJ))
{
originalSize = argObj->AsObj()->Size();
}
else
{
// Must be LCL_VAR: we have a BADCODE assert for this in AddFinalArgsAndDetermineABIInfo.
originalSize = lvaGetDesc(argObj->AsLclVar())->lvExactSize;
}
assert(argObj->OperIs(GT_OBJ, GT_LCL_VAR, GT_LCL_FLD));
originalSize = argObj->GetLayout(this)->GetSize();
}
else
{
Expand Down