Skip to content

Commit 15c7022

Browse files
authored
JIT: Avoid unnecessary GTF_GLOB_REFs (#84349)
* Avoid setting GTF_GLOB_REF on GT_FIELD_ADDR nodes * Avoid setting GTF_GLOB_REF on GT_FIELD nodes off of implicit byrefs. This is ok now since implicit byref morphing indiscriminately sets GTF_GLOB_REF for these. * Manually clone a "pointer to span" in span intrinsic expansion when it points to a local. Unfortunately this does not fall out from the above since gtClone does not handle FIELD_ADDR, and making it handle this needs some more work. These changes are necessary to avoid address exposure in the two user benchmarks in #83388. Fix #74563 Fix #856
1 parent 092f752 commit 15c7022

File tree

3 files changed

+12
-28
lines changed

3 files changed

+12
-28
lines changed

src/coreclr/jit/gentree.cpp

Lines changed: 1 addition & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -7714,16 +7714,6 @@ GenTreeField* Compiler::gtNewFieldRef(var_types type, CORINFO_FIELD_HANDLE fldHn
77147714
LclVarDsc* varDsc = lvaGetDesc(obj->AsLclVarCommon());
77157715

77167716
varDsc->lvFieldAccessed = 1;
7717-
7718-
if (lvaIsImplicitByRefLocal(lvaGetLclNum(varDsc)))
7719-
{
7720-
// These structs are passed by reference and can easily become global references if those
7721-
// references are exposed. We clear out address-exposure information for these parameters
7722-
// when they are converted into references in fgRetypeImplicitByRefArgs() so we do not have
7723-
// the necessary information in morph to know if these indirections are actually global
7724-
// references, so we have to be conservative here.
7725-
fieldNode->gtFlags |= GTF_GLOB_REF;
7726-
}
77277717
}
77287718
else
77297719
{
@@ -7758,20 +7748,8 @@ GenTreeField* Compiler::gtNewFieldAddrNode(var_types type, CORINFO_FIELD_HANDLE
77587748
// If "obj" is the address of a local, note that a field of that struct local has been accessed.
77597749
if ((obj != nullptr) && obj->IsLclVarAddr())
77607750
{
7761-
LclVarDsc* varDsc = lvaGetDesc(obj->AsLclVarCommon());
7762-
7751+
LclVarDsc* varDsc = lvaGetDesc(obj->AsLclVarCommon());
77637752
varDsc->lvFieldAccessed = 1;
7764-
7765-
if (lvaIsImplicitByRefLocal(lvaGetLclNum(varDsc)))
7766-
{
7767-
// TODO-ADDR: delete this zero-diff quirk.
7768-
fieldNode->gtFlags |= GTF_GLOB_REF;
7769-
}
7770-
}
7771-
else
7772-
{
7773-
// TODO-ADDR: delete this zero-diff quirk.
7774-
fieldNode->gtFlags |= GTF_GLOB_REF;
77757753
}
77767754

77777755
// TODO-ADDR: add GTF_EXCEPT handling here and delete it from callers.

src/coreclr/jit/importer.cpp

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8397,9 +8397,7 @@ void Compiler::impImportBlockCode(BasicBlock* block)
83978397
}
83988398
else if (op1->TypeIs(TYP_BYREF, TYP_I_IMPL) && impIsAddressInLocal(op1))
83998399
{
8400-
// We mark implicit byrefs with GTF_GLOB_REF (see gtNewFieldRef for why).
8401-
// Avoid cloning for these.
8402-
clone = (op1->gtFlags & GTF_GLOB_REF) == 0;
8400+
clone = true;
84038401
}
84048402

84058403
if (clone)

src/coreclr/jit/importercalls.cpp

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2881,8 +2881,16 @@ GenTree* Compiler::impIntrinsic(GenTree* newobjThis,
28812881
// We need to use both index and ptr-to-span twice, so clone or spill.
28822882
index = impCloneExpr(index, &indexClone, NO_CLASS_HANDLE, CHECK_SPILL_ALL,
28832883
nullptr DEBUGARG("Span.get_Item index"));
2884-
ptrToSpan = impCloneExpr(ptrToSpan, &ptrToSpanClone, NO_CLASS_HANDLE, CHECK_SPILL_ALL,
2885-
nullptr DEBUGARG("Span.get_Item ptrToSpan"));
2884+
2885+
if (impIsAddressInLocal(ptrToSpan))
2886+
{
2887+
ptrToSpanClone = gtCloneExpr(ptrToSpan);
2888+
}
2889+
else
2890+
{
2891+
ptrToSpan = impCloneExpr(ptrToSpan, &ptrToSpanClone, NO_CLASS_HANDLE, CHECK_SPILL_ALL,
2892+
nullptr DEBUGARG("Span.get_Item ptrToSpan"));
2893+
}
28862894

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

0 commit comments

Comments
 (0)