diff --git a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/TypePreinit.cs b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/TypePreinit.cs index 5564907e4bc248..54ff6c6c544afe 100644 --- a/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/TypePreinit.cs +++ b/src/coreclr/tools/aot/ILCompiler.Compiler/Compiler/TypePreinit.cs @@ -1860,9 +1860,7 @@ private bool TryHandleIntrinsicCall(MethodDesc method, Value[] parameters, out V return spanRef.TryAccessElement(spanIndex.AsInt32(), out retVal); } return false; - case "GetTypeFromHandle" when method.OwningType is MetadataType typeType - && typeType.Name == "Type" && typeType.Namespace == "System" - && typeType.Module == typeType.Context.SystemModule + case "GetTypeFromHandle" when IsSystemType(method.OwningType) && parameters[0] is RuntimeTypeHandleValue typeHandle: { if (!_internedTypes.TryGetValue(typeHandle.Type, out RuntimeTypeValue runtimeType)) @@ -1872,17 +1870,13 @@ private bool TryHandleIntrinsicCall(MethodDesc method, Value[] parameters, out V retVal = runtimeType; return true; } - case "get_IsValueType" when method.OwningType is MetadataType typeType - && typeType.Name == "Type" && typeType.Namespace == "System" - && typeType.Module == typeType.Context.SystemModule + case "get_IsValueType" when IsSystemType(method.OwningType) && parameters[0] is RuntimeTypeValue typeToCheckForValueType: { retVal = ValueTypeValue.FromSByte(typeToCheckForValueType.TypeRepresented.IsValueType ? (sbyte)1 : (sbyte)0); return true; } - case "op_Equality" when method.OwningType is MetadataType typeType - && typeType.Name == "Type" && typeType.Namespace == "System" - && typeType.Module == typeType.Context.SystemModule + case "op_Equality" when IsSystemType(method.OwningType) && (parameters[0] is RuntimeTypeValue || parameters[1] is RuntimeTypeValue): { retVal = ValueTypeValue.FromSByte(parameters[0] == parameters[1] ? (sbyte)1 : (sbyte)0); @@ -1890,6 +1884,11 @@ private bool TryHandleIntrinsicCall(MethodDesc method, Value[] parameters, out V } } + static bool IsSystemType(TypeDesc type) + => type is MetadataType typeType + && typeType.Name == "Type" && typeType.Namespace == "System" + && typeType.Module == typeType.Context.SystemModule; + return false; }