Skip to content

Commit

Permalink
Optimize typeof(T).IsValueType (mono/mono#18307)
Browse files Browse the repository at this point in the history
* Optimize Type.IsValueType

* Ignore gsharedvt types

* use mini_is_gsharedvt_variable_klass

* test

* fix build


Commit migrated from mono/mono@08bb566
  • Loading branch information
EgorBo authored and lewing committed Jan 14, 2020
1 parent f60db7c commit 4eecc94
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/mono/mono/mini/method-to-ir.c
Original file line number Diff line number Diff line change
Expand Up @@ -10085,6 +10085,24 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b
MonoClass *tclass = mono_class_from_mono_type_internal ((MonoType *)handle);

mono_class_init_internal (tclass);

// Optimize to true/false if next instruction is `call instance bool Type::get_IsValueType()`
guchar *is_vt_ip;
guint32 is_vt_token;
if ((is_vt_ip = il_read_call (next_ip + 5, end, &is_vt_token)) && ip_in_bb (cfg, cfg->cbb, is_vt_ip)) {
MonoMethod *is_vt_method = mini_get_method (cfg, method, is_vt_token, NULL, generic_context);
if (is_vt_method->klass == mono_defaults.systemtype_class &&
!mini_is_gsharedvt_variable_klass (tclass) &&
!mono_class_is_open_constructed_type (m_class_get_byval_arg (tclass)) &&
!strcmp ("get_IsValueType", is_vt_method->name)) {
next_ip = is_vt_ip;
EMIT_NEW_ICONST (cfg, ins, m_class_is_valuetype (tclass) ? 1 : 0);
ins->type = STACK_I4;
*sp++ = ins;
break;
}
}

if (context_used) {
ins = mini_emit_get_rgctx_klass (cfg, context_used,
tclass, MONO_RGCTX_INFO_REFLECTION_TYPE);
Expand Down

0 comments on commit 4eecc94

Please sign in to comment.