Skip to content

Commit

Permalink
JIT: Avoid unnecessary GTF_GLOB_REFs
Browse files Browse the repository at this point in the history
* 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.

These changes are necessary to avoid address exposure in the two user
benchmarks in dotnet#83388.

Fix dotnet#74563
  • Loading branch information
jakobbotsch committed Apr 5, 2023
1 parent 6114f19 commit 4ae47a2
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 26 deletions.
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

0 comments on commit 4ae47a2

Please sign in to comment.