diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index e474a325997a6..5f67160555849 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -1332,11 +1332,6 @@ GenTree* Compiler::impNormStructVal(GenTree* structVal, CORINFO_CLASS_HANDLE str case GT_LCL_VAR: case GT_LCL_FLD: - structLcl = structVal->AsLclVarCommon(); - // Wrap it in a GT_OBJ. - structVal = gtNewObjNode(structHnd, gtNewOperNode(GT_ADDR, TYP_BYREF, structVal)); - FALLTHROUGH; - case GT_IND: case GT_OBJ: case GT_BLK: @@ -1414,12 +1409,6 @@ GenTree* Compiler::impNormStructVal(GenTree* structVal, CORINFO_CLASS_HANDLE str structLcl = gtNewLclvNode(tmpNum, structType)->AsLclVarCommon(); structVal = structLcl; - - if (structType == TYP_STRUCT) - { - // Wrap it in a GT_OBJ - structVal = gtNewObjNode(structHnd, gtNewOperNode(GT_ADDR, TYP_BYREF, structVal)); - } } if (structLcl != nullptr) diff --git a/src/coreclr/jit/lclmorph.cpp b/src/coreclr/jit/lclmorph.cpp index 0e610ebf95c72..e3e9cccb7d51d 100644 --- a/src/coreclr/jit/lclmorph.cpp +++ b/src/coreclr/jit/lclmorph.cpp @@ -1565,40 +1565,42 @@ class LocalAddressVisitor final : public GenTreeVisitor // handled in fgCanFastTailCall and fgMakeOutgoingStructArgCopy. // // CALL(OBJ(LCL_VAR_ADDR...)) - bool isArgToCall = false; - bool keepSearching = true; - for (int i = 0; i < m_ancestors.Height() && keepSearching; i++) + // -or- + // CALL(LCL_VAR) + + // TODO-1stClassStructs: We've removed most, but not all, cases where OBJ(LCL_VAR_ADDR) + // is introduced (it was primarily from impNormStructVal). But until all cases are gone + // we still want to handle it as well. + + if (m_ancestors.Height() < 2) + { + return; + } + + GenTree* node = m_ancestors.Top(0); + + if (node->OperIs(GT_LCL_VAR)) { - GenTree* node = m_ancestors.Top(i); - switch (i) + node = m_ancestors.Top(1); + } + else if (node->OperIs(GT_LCL_VAR_ADDR)) + { + if (m_ancestors.Height() < 3) { - case 0: - { - keepSearching = node->OperIs(GT_LCL_VAR_ADDR); - } - break; + return; + } - case 1: - { - keepSearching = node->OperIs(GT_OBJ); - } - break; + node = m_ancestors.Top(1); - case 2: - { - keepSearching = false; - isArgToCall = node->IsCall(); - } - break; - default: - { - keepSearching = false; - } - break; + if (!node->OperIs(GT_OBJ)) + { + return; } + + node = m_ancestors.Top(2); } - if (isArgToCall) + if (node->IsCall()) { JITDUMP("LocalAddressVisitor incrementing weighted ref count from " FMT_WT " to " FMT_WT " for implicit by-ref V%02d arg passed to call\n",