diff --git a/src/coreclr/jit/compiler.h b/src/coreclr/jit/compiler.h index 36e35ba3ecc190..db8c2ec39f3540 100644 --- a/src/coreclr/jit/compiler.h +++ b/src/coreclr/jit/compiler.h @@ -4516,7 +4516,7 @@ class Compiler }; bool impIsPrimitive(CorInfoType type); - bool impILConsumesAddr(const BYTE* codeAddr); + bool impILConsumesAddr(const BYTE* codeAddr, const BYTE* codeEndp); void impResolveToken(const BYTE* addr, CORINFO_RESOLVED_TOKEN* pResolvedToken, CorInfoTokenKind kind); diff --git a/src/coreclr/jit/fgbasic.cpp b/src/coreclr/jit/fgbasic.cpp index 4fa17a9c6c8207..12720c3f38cba3 100644 --- a/src/coreclr/jit/fgbasic.cpp +++ b/src/coreclr/jit/fgbasic.cpp @@ -2310,11 +2310,10 @@ void Compiler::fgFindJumpTargets(const BYTE* codeAddr, IL_OFFSET codeSize, Fixed // generate for this ldfld, and we require that we // won't need the address of this local at all - const bool notStruct = !varTypeIsStruct(lvaGetDesc(varNum)); const bool notLastInstr = (codeAddr < codeEndp - sz); const bool notDebugCode = !opts.compDbgCode; - if (notStruct && notLastInstr && notDebugCode && impILConsumesAddr(codeAddr + sz)) + if (notLastInstr && notDebugCode && impILConsumesAddr(codeAddr + sz, codeEndp)) { // We can skip the addrtaken, as next IL instruction consumes // the address. diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index 21f12c21e0dc59..8b6a9af39e0553 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -50,51 +50,16 @@ void Compiler::impPushOnStack(GenTree* tree, typeInfo ti) // helper function that will tell us if the IL instruction at the addr passed // by param consumes an address at the top of the stack. We use it to save // us lvAddrTaken -bool Compiler::impILConsumesAddr(const BYTE* codeAddr) +bool Compiler::impILConsumesAddr(const BYTE* codeAddr, const BYTE* codeEndp) { - assert(!compIsForInlining()); - - OPCODE opcode; - - opcode = (OPCODE)getU1LittleEndian(codeAddr); - + OPCODE opcode = impGetNonPrefixOpcode(codeAddr, codeEndp); switch (opcode) { - // case CEE_LDFLDA: We're taking this one out as if you have a sequence - // like - // - // ldloca.0 - // ldflda whatever - // - // of a primitivelike struct, you end up after morphing with addr of a local - // that's not marked as addrtaken, which is wrong. Also ldflda is usually used - // for structs that contain other structs, which isnt a case we handle very - // well now for other reasons. - case CEE_LDFLD: { - // We won't collapse small fields. This is probably not the right place to have this - // check, but we're only using the function for this purpose, and is easy to factor - // out if we need to do so. - - CORINFO_RESOLVED_TOKEN resolvedToken; - impResolveToken(codeAddr + sizeof(int8_t), &resolvedToken, CORINFO_TOKENKIND_Field); - - var_types lclTyp = JITtype2varType(info.compCompHnd->getFieldType(resolvedToken.hField)); - - // Preserve 'small' int types - if (!varTypeIsSmall(lclTyp)) - { - lclTyp = genActualType(lclTyp); - } - - if (varTypeIsSmall(lclTyp)) - { - return false; - } - return true; } + default: break; } @@ -7062,9 +7027,7 @@ void Compiler::impImportBlockCode(BasicBlock* block) return; } - op1->ChangeType(TYP_BYREF); - op1->SetOper(GT_LCL_ADDR); - op1->AsLclFld()->SetLclOffs(0); + op1 = gtNewLclAddrNode(op1->AsLclVar()->GetLclNum(), 0, TYP_BYREF); goto _PUSH_ADRVAR; }