diff --git a/src/coreclr/jit/importer.cpp b/src/coreclr/jit/importer.cpp index 680ee0f1a006..3cfa6bd2013c 100644 --- a/src/coreclr/jit/importer.cpp +++ b/src/coreclr/jit/importer.cpp @@ -5487,6 +5487,14 @@ GenTree* Compiler::impCastClassOrIsInstToTree( { // Jit can only inline expand CHKCASTCLASS and CHKCASTARRAY helpers. canExpandInline = (helper == CORINFO_HELP_CHKCASTCLASS) || (helper == CORINFO_HELP_CHKCASTARRAY); + + // For ChkCastAny we ignore cases where the class is known to be abstract or is an interface. + if (helper == CORINFO_HELP_CHKCASTANY) + { + const bool isAbstract = (info.compCompHnd->getClassAttribs(pResolvedToken->hClass) & + (CORINFO_FLG_INTERFACE | CORINFO_FLG_ABSTRACT)) != 0; + canExpandInline = !isAbstract; + } } else if ((helper == CORINFO_HELP_ISINSTANCEOFCLASS) || (helper == CORINFO_HELP_ISINSTANCEOFARRAY)) { @@ -5625,7 +5633,7 @@ GenTree* Compiler::impCastClassOrIsInstToTree( if (isCastClass) { assert((helper == CORINFO_HELP_CHKCASTCLASS) || (helper == CORINFO_HELP_CHKCASTARRAY) || - (helper == CORINFO_HELP_CHKCASTINTERFACE)); + (helper == CORINFO_HELP_CHKCASTANY) || (helper == CORINFO_HELP_CHKCASTINTERFACE)); CorInfoHelpFunc specialHelper = helper; if ((helper == CORINFO_HELP_CHKCASTCLASS) &&