Skip to content

Commit

Permalink
Allow more obj(addr(lcl_var) foldings. (#42343)
Browse files Browse the repository at this point in the history
* Allow `struct<N> with no GCPointers <-> block<N>` replacements.

* Alllow local morph to fold `OBJ(ADDR(LCL_VAR))` when obj and lclVar loayouts are compatible.
  • Loading branch information
Sergey Andreenko authored Sep 18, 2020
1 parent fd09c80 commit 92b125f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
7 changes: 4 additions & 3 deletions src/coreclr/src/jit/layout.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand All @@ -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;
Expand Down
3 changes: 2 additions & 1 deletion src/coreclr/src/jit/lclmorph.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1021,7 +1021,8 @@ class LocalAddressVisitor final : public GenTreeVisitor<LocalAddressVisitor>
// 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());
Expand Down

0 comments on commit 92b125f

Please sign in to comment.