diff --git a/src/coreclr/jit/importercalls.cpp b/src/coreclr/jit/importercalls.cpp index a0340343c58c44..7955788e1f6010 100644 --- a/src/coreclr/jit/importercalls.cpp +++ b/src/coreclr/jit/importercalls.cpp @@ -3898,6 +3898,12 @@ GenTree* Compiler::impIntrinsic(CORINFO_CLASS_HANDLE clsHnd, break; } + case NI_System_Activator_CreateInstance_T: + { + isSpecial = true; + break; + } + case NI_System_Span_get_Item: case NI_System_ReadOnlySpan_get_Item: { @@ -9989,6 +9995,40 @@ CORINFO_CLASS_HANDLE Compiler::impGetSpecialIntrinsicExactReturnType(GenTreeCall break; } + case NI_System_Activator_CreateInstance_T: + { + // Expect one method generic parameter; figure out which it is. + CORINFO_SIG_INFO sig; + info.compCompHnd->getMethodSig(methodHnd, &sig); + assert(sig.sigInst.methInstCount == 1); + assert(sig.sigInst.classInstCount == 0); + + CORINFO_CLASS_HANDLE typeHnd = sig.sigInst.methInst[0]; + assert(typeHnd != nullptr); + + CallArg* instParam = call->gtArgs.FindWellKnownArg(WellKnownArg::InstParam); + if (instParam != nullptr) + { + assert(instParam->GetNext() == nullptr); + CORINFO_METHOD_HANDLE hMethod = gtGetHelperArgMethodHandle(instParam->GetNode()); + if (hMethod != NO_METHOD_HANDLE) + { + result = getMethodInstantiationArgument(hMethod, 0); + } + } + + if (result != NO_CLASS_HANDLE) + { + JITDUMP("Special intrinsic: return type is %s\n", + result != nullptr ? eeGetClassName(result) : "unknown"); + } + else + { + JITDUMP("Special intrinsic: return type undetermined or inexact, so deferring opt\n"); + } + break; + } + default: { JITDUMP("This special intrinsic not handled, sorry...\n"); @@ -10726,6 +10766,15 @@ NamedIntrinsic Compiler::lookupNamedIntrinsic(CORINFO_METHOD_HANDLE method) { result = NI_System_Activator_AllocatorOf; } + else if (strcmp(methodName, "CreateInstance") == 0) + { + CORINFO_SIG_INFO sig; + eeGetMethodSig(method, &sig); + if ((sig.sigInst.methInstCount == 1) && (sig.sigInst.classInstCount == 0)) + { + result = NI_System_Activator_CreateInstance_T; + } + } else if (strcmp(methodName, "DefaultConstructorOf") == 0) { result = NI_System_Activator_DefaultConstructorOf; diff --git a/src/coreclr/jit/namedintrinsiclist.h b/src/coreclr/jit/namedintrinsiclist.h index 5f96a30903d1d2..7c9028e9fdffd8 100644 --- a/src/coreclr/jit/namedintrinsiclist.h +++ b/src/coreclr/jit/namedintrinsiclist.h @@ -100,6 +100,7 @@ enum NamedIntrinsic : unsigned short NI_System_Type_op_Inequality, NI_System_Type_GetTypeFromHandle, NI_System_Type_GetGenericTypeDefinition, + NI_System_Activator_CreateInstance_T, NI_System_Array_Clone, NI_System_Array_GetLength, NI_System_Array_GetLowerBound,