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

Transform STRUCT-typed uses of primitives in local morph #78131

Merged
merged 8 commits into from
Nov 30, 2022
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
2 changes: 1 addition & 1 deletion src/coreclr/jit/compiler.h
Original file line number Diff line number Diff line change
Expand Up @@ -5723,7 +5723,7 @@ class Compiler
GenTree* fgMorphExpandStackArgForVarArgs(GenTreeLclVarCommon* lclNode);
#endif // TARGET_X86
GenTree* fgMorphExpandImplicitByRefArg(GenTreeLclVarCommon* lclNode);
GenTree* fgMorphLocalVar(GenTree* tree, bool forceRemorph);
GenTree* fgMorphLocalVar(GenTree* tree);

public:
bool fgAddrCouldBeNull(GenTree* addr);
Expand Down
2 changes: 2 additions & 0 deletions src/coreclr/jit/flowgraph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -944,6 +944,8 @@ bool Compiler::fgAddrCouldBeNull(GenTree* addr)
case GT_CNS_STR:
case GT_ADDR:
case GT_FIELD_ADDR:
case GT_LCL_VAR_ADDR:
case GT_LCL_FLD_ADDR:
case GT_CLS_VAR_ADDR:
// A GT_ADDR node, by itself, never requires null checking. The expression whose address is being
// taken is either a local or static variable, whose address is necessarily non-null, or else it is
Expand Down
9 changes: 9 additions & 0 deletions src/coreclr/jit/forwardsub.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -641,6 +641,15 @@ bool Compiler::fgForwardSubStatement(Statement* stmt)
return false;
}

// A "CanBeReplacedWithItsField" SDSU can serve as a sort of "BITCAST<primitive>(struct)"
// device, forwarding it risks forcing things to memory.
//
if (fwdSubNode->IsCall() && varDsc->CanBeReplacedWithItsField(this))
{
JITDUMP(" fwd sub local is 'CanBeReplacedWithItsField'\n");
return false;
}

// There are implicit assumptions downstream on where/how multi-reg ops
// can appear.
//
Expand Down
22 changes: 11 additions & 11 deletions src/coreclr/jit/lclmorph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -933,7 +933,13 @@ class LocalAddressVisitor final : public GenTreeVisitor<LocalAddressVisitor>
indir->AsLclFld()->SetLayout(indirLayout);
lclNode = indir->AsLclVarCommon();

m_compiler->lvaSetVarDoNotEnregister(lclNum DEBUGARG(DoNotEnregisterReason::LocalField));
if (!indir->TypeIs(TYP_STRUCT))
{
// The general invariant in the compiler is that whoever creates a LCL_FLD node after local morph
// must mark the associated local DNER. We break this invariant here, for STRUCT fields, to allow
// global morph to transform these into enregisterable LCL_VARs, applying DNER otherwise.
m_compiler->lvaSetVarDoNotEnregister(val.LclNum() DEBUGARG(DoNotEnregisterReason::LocalField));
}
break;

default:
Expand Down Expand Up @@ -1037,14 +1043,6 @@ class LocalAddressVisitor final : public GenTreeVisitor<LocalAddressVisitor>
return IndirTransform::LclFld;
}

if (varDsc->TypeGet() != TYP_STRUCT)
{
// TODO-ADDR: STRUCT uses of primitives require more work: "fgMorphOneAsgBlockOp"
// and init block morphing need to be updated to recognize them. Alternatively,
// we could consider moving some of their functionality here.
return IndirTransform::None;
}

ClassLayout* indirLayout = nullptr;

if (indir->OperIs(GT_FIELD))
Expand All @@ -1062,8 +1060,10 @@ class LocalAddressVisitor final : public GenTreeVisitor<LocalAddressVisitor>

*pStructLayout = indirLayout;

// We're only processing TYP_STRUCT uses and variables now.
assert(indir->TypeIs(TYP_STRUCT) && (varDsc->GetLayout() != nullptr));
if (varDsc->TypeGet() != TYP_STRUCT)
{
return IndirTransform::LclFld;
}

if ((val.Offset() == 0) && ClassLayout::AreCompatible(indirLayout, varDsc->GetLayout()))
{
Expand Down
Loading