Skip to content

Commit

Permalink
[mono][jit] Optimize calls to Type:get_IsValueType () on gshared cons…
Browse files Browse the repository at this point in the history
…trained types. (#61514)

These are used for example in Span<T>:.ctor ().
  • Loading branch information
vargaz authored Nov 12, 2021
1 parent 8574ce9 commit c580f49
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions src/mono/mono/mini/intrinsics.c
Original file line number Diff line number Diff line change
Expand Up @@ -1894,6 +1894,33 @@ mini_emit_inst_for_method (MonoCompile *cfg, MonoMethod *cmethod, MonoMethodSign
MONO_ADD_INS (cfg->cbb, ins);
}
return ins;
} else if (cmethod->klass == mono_defaults.systemtype_class && !strcmp (cmethod->name, "get_IsValueType") &&
args [0]->klass == mono_defaults.runtimetype_class) {
MonoClass *k1 = get_class_from_ldtoken_ins (args [0]);
if (k1) {
MonoType *t1 = m_class_get_byval_arg (k1);
MonoType *constraint1 = NULL;

/* Common case in gshared BCL code: t1 is a gshared type like T_INT */
if (mono_class_is_gparam (k1)) {
MonoGenericParam *gparam = t1->data.generic_param;
constraint1 = gparam->gshared_constraint;
if (constraint1) {
if (constraint1->type == MONO_TYPE_OBJECT) {
if (cfg->verbose_level > 2)
printf ("-> false\n");
EMIT_NEW_ICONST (cfg, ins, 0);
return ins;
} else if (MONO_TYPE_IS_PRIMITIVE (constraint1)) {
if (cfg->verbose_level > 2)
printf ("-> true\n");
EMIT_NEW_ICONST (cfg, ins, 1);
return ins;
}
}
}
}
return NULL;
} else if (((!strcmp (cmethod_klass_image->assembly->aname.name, "MonoMac") ||
!strcmp (cmethod_klass_image->assembly->aname.name, "monotouch")) &&
!strcmp (cmethod_klass_name_space, "XamCore.ObjCRuntime") &&
Expand Down

0 comments on commit c580f49

Please sign in to comment.