Skip to content

Commit c580f49

Browse files
authored
[mono][jit] Optimize calls to Type:get_IsValueType () on gshared constrained types. (#61514)
These are used for example in Span<T>:.ctor ().
1 parent 8574ce9 commit c580f49

File tree

1 file changed

+27
-0
lines changed

1 file changed

+27
-0
lines changed

src/mono/mono/mini/intrinsics.c

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1894,6 +1894,33 @@ mini_emit_inst_for_method (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSign
18941894
MONO_ADD_INS (cfg->cbb, ins);
18951895
}
18961896
return ins;
1897+
} else if (cmethod->klass == mono_defaults.systemtype_class && !strcmp (cmethod->name, "get_IsValueType") &&
1898+
args [0]->klass == mono_defaults.runtimetype_class) {
1899+
MonoClass *k1 = get_class_from_ldtoken_ins (args [0]);
1900+
if (k1) {
1901+
MonoType *t1 = m_class_get_byval_arg (k1);
1902+
MonoType *constraint1 = NULL;
1903+
1904+
/* Common case in gshared BCL code: t1 is a gshared type like T_INT */
1905+
if (mono_class_is_gparam (k1)) {
1906+
MonoGenericParam *gparam = t1->data.generic_param;
1907+
constraint1 = gparam->gshared_constraint;
1908+
if (constraint1) {
1909+
if (constraint1->type == MONO_TYPE_OBJECT) {
1910+
if (cfg->verbose_level > 2)
1911+
printf ("-> false\n");
1912+
EMIT_NEW_ICONST (cfg, ins, 0);
1913+
return ins;
1914+
} else if (MONO_TYPE_IS_PRIMITIVE (constraint1)) {
1915+
if (cfg->verbose_level > 2)
1916+
printf ("-> true\n");
1917+
EMIT_NEW_ICONST (cfg, ins, 1);
1918+
return ins;
1919+
}
1920+
}
1921+
}
1922+
}
1923+
return NULL;
18971924
} else if (((!strcmp (cmethod_klass_image->assembly->aname.name, "MonoMac") ||
18981925
!strcmp (cmethod_klass_image->assembly->aname.name, "monotouch")) &&
18991926
!strcmp (cmethod_klass_name_space, "XamCore.ObjCRuntime") &&

0 commit comments

Comments
 (0)