Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Minor cleanup
  • Loading branch information
EgorBo committed Feb 25, 2020
commit fd107758fc25f5e26c358e1a608e1d536a18e27f
23 changes: 12 additions & 11 deletions src/coreclr/src/jit/gentree.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12498,23 +12498,24 @@ GenTree* Compiler::gtFoldTypeCompare(GenTree* tree)
objOp = opOther->AsCall()->gtCallThisArg->GetNode();
}

bool pIsExact = false;
bool pIsNonNull = false;
CORINFO_CLASS_HANDLE objCls = gtGetClassHandle(objOp, &pIsExact, &pIsNonNull);

// if both classes are "final" arrays (e.g. string[]) we can replace the comparison
// with `true` + null check.
if (objCls != NO_CLASS_HANDLE &&
// double check if it's final via impIsClassExact rather than pIsExact
bool pIsExact = false;
bool pIsNonNull = false;
CORINFO_CLASS_HANDLE objCls = gtGetClassHandle(objOp, &pIsExact, &pIsNonNull);

// if both classes are "final" (e.g. System.String[]) we can replace the comparison
// with `true/false` + null check.
if ((objCls != NO_CLASS_HANDLE) &&
// double check if it's final via impIsClassExact
impIsClassExact(objCls) && impIsClassExact(clsHnd))
{
const bool typesAreEqual = objCls == clsHnd;
const bool operatorIsEQ = (oper == GT_EQ);
const bool operatorIsEQ = oper == GT_EQ;
const int compareResult = operatorIsEQ ^ typesAreEqual ? 0 : 1;

// we still have to emit a null-check
// obj.GetType == typeof() -> (nullcheck) true/false
GenTree* nullcheck = gtNewNullCheck(objOp, compCurBB);
return gtNewOperNode(GT_COMMA, tree->TypeGet(), nullcheck,
gtNewIconNode(compareResult));
return gtNewOperNode(GT_COMMA, tree->TypeGet(), nullcheck, gtNewIconNode(compareResult));
}

GenTree* const objMT = gtNewOperNode(GT_IND, TYP_I_IMPL, objOp);
Expand Down
4 changes: 2 additions & 2 deletions src/coreclr/src/jit/importer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20654,7 +20654,7 @@ void Compiler::addExpRuntimeLookupCandidate(GenTreeCall* call)
// variance or similar.
//
// Note:
// We are conservative on arrays here, only array of sealed clases can
// We are conservative on arrays here, only arrays of sealed classes can
// be considered as final.

bool Compiler::impIsClassExact(CORINFO_CLASS_HANDLE classHnd)
Expand All @@ -20666,7 +20666,7 @@ bool Compiler::impIsClassExact(CORINFO_CLASS_HANDLE classHnd)
{
return true;
}
if ((flags & (CORINFO_FLG_VARIANCE | CORINFO_FLG_ARRAY)) == CORINFO_FLG_ARRAY)
if ((flags & flagsMask) == (CORINFO_FLG_FINAL | CORINFO_FLG_ARRAY))
{
CORINFO_CLASS_HANDLE arrayElementHandle = nullptr;
if (info.compCompHnd->getChildType(classHnd, &arrayElementHandle) == CORINFO_TYPE_CLASS)
Expand Down