diff --git a/src/coreclr/src/jit/morph.cpp b/src/coreclr/src/jit/morph.cpp index cd2650f142242..87021857f8066 100644 --- a/src/coreclr/src/jit/morph.cpp +++ b/src/coreclr/src/jit/morph.cpp @@ -10347,11 +10347,20 @@ GenTree* Compiler::fgMorphCopyBlock(GenTree* tree) CORINFO_CLASS_HANDLE classHnd = srcVarDsc->lvVerTypeInfo.GetClassHandle(); CORINFO_FIELD_HANDLE fieldHnd = info.compCompHnd->getFieldInClass(classHnd, srcFieldVarDsc->lvFldOrdinal); - FieldSeqNode* curFieldSeq = GetFieldSeqStore()->CreateSingleton(fieldHnd); - unsigned srcFieldOffset = lvaGetDesc(srcFieldLclNum)->lvFldOffset; - GenTree* fieldOffsetNode = gtNewIconNode(srcFieldVarDsc->lvFldOffset, curFieldSeq); + FieldSeqNode* curFieldSeq = GetFieldSeqStore()->CreateSingleton(fieldHnd); + + unsigned srcFieldOffset = lvaGetDesc(srcFieldLclNum)->lvFldOffset; + + if (srcFieldOffset == 0) + { + fgAddFieldSeqForZeroOffset(dstFld, curFieldSeq); + } + else + { + GenTree* fieldOffsetNode = gtNewIconNode(srcFieldVarDsc->lvFldOffset, curFieldSeq); + dstFld = gtNewOperNode(GT_ADD, TYP_BYREF, dstFld, fieldOffsetNode); + } - dstFld = gtNewOperNode(GT_ADD, TYP_BYREF, dstFld, fieldOffsetNode); dstFld = gtNewIndir(srcFieldVarDsc->TypeGet(), dstFld); // !!! The destination could be on stack. !!! @@ -10427,15 +10436,18 @@ GenTree* Compiler::fgMorphCopyBlock(GenTree* tree) } } } - else // if (lvaGetDesc(fieldLclNum)->lvFldOffset != 0) - { - srcFld = gtNewOperNode(GT_ADD, TYP_BYREF, srcFld, - new (this, GT_CNS_INT) - GenTreeIntCon(TYP_I_IMPL, lvaGetDesc(dstFieldLclNum)->lvFldOffset, - curFieldSeq)); - } if (!done) { + unsigned fldOffset = lvaGetDesc(dstFieldLclNum)->lvFldOffset; + if (fldOffset == 0) + { + fgAddFieldSeqForZeroOffset(srcFld, curFieldSeq); + } + else + { + GenTreeIntCon* fldOffsetNode = gtNewIconNode(fldOffset, curFieldSeq); + srcFld = gtNewOperNode(GT_ADD, TYP_BYREF, srcFld, fldOffsetNode); + } srcFld = gtNewIndir(destType, srcFld); } }