From: Sergey Andreenko Date: Fri, 18 Sep 2020 05:21:29 +0000 (-0700) Subject: Allow more obj(addr(lcl_var) foldings. (#42343) X-Git-Tag: submit/tizen/20210909.063632~5435 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=92b125fc7671b82433f3adbd085b7e6b29b1a73d;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Allow more obj(addr(lcl_var) foldings. (#42343) * Allow `struct with no GCPointers <-> block` replacements. * Alllow local morph to fold `OBJ(ADDR(LCL_VAR))` when obj and lclVar loayouts are compatible. --- diff --git a/src/coreclr/src/jit/layout.cpp b/src/coreclr/src/jit/layout.cpp index bafe17b..87b0bef 100644 --- a/src/coreclr/src/jit/layout.cpp +++ b/src/coreclr/src/jit/layout.cpp @@ -430,10 +430,8 @@ bool ClassLayout::AreCompatible(const ClassLayout* layout1, const ClassLayout* l { CORINFO_CLASS_HANDLE clsHnd1 = layout1->GetClassHandle(); CORINFO_CLASS_HANDLE clsHnd2 = layout2->GetClassHandle(); - assert(clsHnd1 != NO_CLASS_HANDLE); - assert(clsHnd2 != NO_CLASS_HANDLE); - if (clsHnd1 == clsHnd2) + if ((clsHnd1 != NO_CLASS_HANDLE) && (clsHnd1 == clsHnd2)) { return true; } @@ -453,7 +451,10 @@ bool ClassLayout::AreCompatible(const ClassLayout* layout1, const ClassLayout* l return true; } + assert(clsHnd1 != NO_CLASS_HANDLE); + assert(clsHnd2 != NO_CLASS_HANDLE); assert(layout1->HasGCPtr() && layout2->HasGCPtr()); + if (layout1->GetGCPtrCount() != layout2->GetGCPtrCount()) { return false; diff --git a/src/coreclr/src/jit/lclmorph.cpp b/src/coreclr/src/jit/lclmorph.cpp index 1df4935..811cfc0 100644 --- a/src/coreclr/src/jit/lclmorph.cpp +++ b/src/coreclr/src/jit/lclmorph.cpp @@ -1021,7 +1021,8 @@ private: // otherwise the below layout equality check would be insufficient. assert(varDsc->GetLayout() != nullptr); - if ((val.Offset() == 0) && (structLayout == varDsc->GetLayout())) + if ((val.Offset() == 0) && (structLayout != nullptr) && + ClassLayout::AreCompatible(structLayout, varDsc->GetLayout())) { indir->ChangeOper(GT_LCL_VAR); indir->AsLclVar()->SetLclNum(val.LclNum());