Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disallow IND<struct> except as a source of STORE_DYN_BLK #74784

Merged
merged 10 commits into from
Dec 15, 2022
Prev Previous commit
Next Next commit
Simplify code
  • Loading branch information
SingleAccretion committed Dec 9, 2022
commit 07d5d5f841e85d014612f5574767a9ee7dc039b5
7 changes: 3 additions & 4 deletions src/coreclr/jit/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15718,12 +15718,11 @@ GenTree* Compiler::gtNewTempAssign(
if (varTypeIsStruct(varDsc) && (valStructHnd == NO_CLASS_HANDLE) && !varTypeIsSIMD(valTyp))
{
// There are some cases where we do not have a struct handle on the return value:
// 1. Handle-less IND/BLK/LCL_FLD<struct> nodes.
// 1. Handle-less BLK/LCL_FLD nodes.
// 2. The zero constant created by local assertion propagation.
// In these cases, we can use the type of the merge return for the assignment.
// In these cases, we can use the type of the local for the assignment.
assert(val->gtEffectiveVal(true)->OperIs(GT_IND, GT_BLK, GT_LCL_FLD, GT_CNS_INT));
assert(tmp == genReturnLocal);
valStructHnd = lvaGetStruct(genReturnLocal);
valStructHnd = lvaGetDesc(tmp)->GetStructHnd();
assert(valStructHnd != NO_CLASS_HANDLE);
}

Expand Down
14 changes: 3 additions & 11 deletions src/coreclr/jit/lower.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3774,20 +3774,12 @@ void Lowering::LowerRetStruct(GenTreeUnOp* ret)
{
// Spill to a local if sizes don't match so we can avoid the "load more than requested"
// problem, e.g. struct size is 5 and we emit "ldr x0, [x1]"
unsigned realSize = retVal->AsIndir()->Size();
CORINFO_CLASS_HANDLE structCls = comp->info.compMethodInfo->args.retTypeClass;
if (realSize == 0)
{
// TODO-ADDR: delete once "IND<struct>" nodes are no more
realSize = comp->info.compCompHnd->getClassSize(structCls);
}

if (genTypeSize(nativeReturnType) > realSize)
if (genTypeSize(nativeReturnType) > retVal->AsIndir()->Size())
{
LIR::Use retValUse(BlockRange(), &ret->gtOp1, ret);
unsigned tmpNum = comp->lvaGrabTemp(true DEBUGARG("mis-sized struct return"));
comp->lvaSetStruct(tmpNum, structCls, false);
comp->genReturnLocal = tmpNum;
comp->lvaSetStruct(tmpNum, comp->info.compMethodInfo->args.retTypeClass, false);

ReplaceWithLclVar(retValUse, tmpNum);
LowerRetSingleRegStructLclVar(ret);
break;
Expand Down
13 changes: 1 addition & 12 deletions src/coreclr/jit/morphblock.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -753,21 +753,10 @@ void MorphCopyBlockHelper::PrepareSrc()
m_srcVarDsc = m_comp->lvaGetDesc(m_srcLclNum);
}

// Verify that the types on the LHS and RHS match and morph away "IND<struct>" nodes.
// Verify that the types on the LHS and RHS match.
assert(m_dst->TypeGet() == m_src->TypeGet());
if (m_dst->TypeIs(TYP_STRUCT))
{
// TODO-1stClassStructs: delete this once "IND<struct>" nodes are no more.
if (m_src->OperIs(GT_IND))
{
m_src->SetOper(m_blockLayout->IsBlockLayout() ? GT_BLK : GT_OBJ);
m_src->AsBlk()->SetLayout(m_blockLayout);
m_src->AsBlk()->gtBlkOpKind = GenTreeBlk::BlkOpKindInvalid;
#ifndef JIT32_GCENCODER
m_src->AsBlk()->gtBlkOpGcUnsafe = false;
#endif // !JIT32_GCENCODER
}

assert(ClassLayout::AreCompatible(m_blockLayout, m_src->GetLayout(m_comp)));
}
// TODO-1stClassStructs: produce simple "IND<simd>" nodes in importer.
Expand Down