From 4ae47a247208abc28c0077705110774a89a088f5 Mon Sep 17 00:00:00 2001 From: Jakob Botsch Nielsen Date: Wed, 5 Apr 2023 14:32:38 +0200 Subject: [PATCH] JIT: Avoid unnecessary GTF_GLOB_REFs * 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 #83388. Fix #74563 --- src/coreclr/jit/gentree.cpp | 24 +----------------------- src/coreclr/jit/importer.cpp | 4 +--- 2 files changed, 2 insertions(+), 26 deletions(-) diff --git a/src/coreclr/jit/gentree.cpp b/src/coreclr/jit/gentree.cpp index a1d3fdb805630..518edb0918f2e 100644 --- a/src/coreclr/jit/gentree.cpp +++ b/src/coreclr/jit/gentree.cpp @@ -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 { @@ -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. diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index 8e4365023b357..2ed77627fe412 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -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)