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

JIT: Avoid unnecessary GTF_GLOB_REFs #84349

Merged
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
24 changes: 1 addition & 23 deletions src/coreclr/jit/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7714,16 +7714,6 @@ GenTreeField* Compiler::gtNewFieldRef(var_types type, CORINFO_FIELD_HANDLE fldHn
LclVarDsc* varDsc = lvaGetDesc(obj->AsLclVarCommon());

varDsc->lvFieldAccessed = 1;

if (lvaIsImplicitByRefLocal(lvaGetLclNum(varDsc)))
{
// These structs are passed by reference and can easily become global references if those
// references are exposed. We clear out address-exposure information for these parameters
// when they are converted into references in fgRetypeImplicitByRefArgs() so we do not have
// the necessary information in morph to know if these indirections are actually global
// references, so we have to be conservative here.
fieldNode->gtFlags |= GTF_GLOB_REF;
}
}
else
{
Expand Down Expand Up @@ -7758,20 +7748,8 @@ GenTreeField* Compiler::gtNewFieldAddrNode(var_types type, CORINFO_FIELD_HANDLE
// If "obj" is the address of a local, note that a field of that struct local has been accessed.
if ((obj != nullptr) && obj->IsLclVarAddr())
{
LclVarDsc* varDsc = lvaGetDesc(obj->AsLclVarCommon());

LclVarDsc* varDsc = lvaGetDesc(obj->AsLclVarCommon());
varDsc->lvFieldAccessed = 1;

if (lvaIsImplicitByRefLocal(lvaGetLclNum(varDsc)))
{
// TODO-ADDR: delete this zero-diff quirk.
fieldNode->gtFlags |= GTF_GLOB_REF;
}
}
else
{
// TODO-ADDR: delete this zero-diff quirk.
fieldNode->gtFlags |= GTF_GLOB_REF;
}

// TODO-ADDR: add GTF_EXCEPT handling here and delete it from callers.
Expand Down
4 changes: 1 addition & 3 deletions src/coreclr/jit/importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8397,9 +8397,7 @@ void Compiler::impImportBlockCode(BasicBlock* block)
}
else if (op1->TypeIs(TYP_BYREF, TYP_I_IMPL) && impIsAddressInLocal(op1))
{
// We mark implicit byrefs with GTF_GLOB_REF (see gtNewFieldRef for why).
// Avoid cloning for these.
clone = (op1->gtFlags & GTF_GLOB_REF) == 0;
clone = true;
}

if (clone)
Expand Down
12 changes: 10 additions & 2 deletions src/coreclr/jit/importercalls.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2881,8 +2881,16 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis,
// We need to use both index and ptr-to-span twice, so clone or spill.
index = impCloneExpr(index, &indexClone, NO_CLASS_HANDLE, CHECK_SPILL_ALL,
nullptr DEBUGARG("Span.get_Item index"));
ptrToSpan = impCloneExpr(ptrToSpan, &ptrToSpanClone, NO_CLASS_HANDLE, CHECK_SPILL_ALL,
nullptr DEBUGARG("Span.get_Item ptrToSpan"));

if (impIsAddressInLocal(ptrToSpan))
{
ptrToSpanClone = gtCloneExpr(ptrToSpan);
}
else
{
ptrToSpan = impCloneExpr(ptrToSpan, &ptrToSpanClone, NO_CLASS_HANDLE, CHECK_SPILL_ALL,
nullptr DEBUGARG("Span.get_Item ptrToSpan"));
}

// Bounds check
CORINFO_FIELD_HANDLE lengthHnd = info.compCompHnd->getFieldInClass(clsHnd, 1);
Expand Down