From: Egor Bogatov Date: Tue, 14 Jan 2020 15:37:16 +0000 (+0300) Subject: Optimize typeof(T).IsValueType (mono/mono#18307) X-Git-Tag: submit/tizen/20210909.063632~10331^2~5^2~19 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=4eecc94fd144af1ac2a980abd03d966b410ac3b5;p=platform%2Fupstream%2Fdotnet%2Fruntime.git Optimize typeof(T).IsValueType (mono/mono#18307) * Optimize Type.IsValueType * Ignore gsharedvt types * use mini_is_gsharedvt_variable_klass * test * fix build Commit migrated from https://github.com/mono/mono/commit/08bb5660f6b2cc87ec59fb77c01a1f8cdeda183f --- diff --git a/src/mono/mono/mini/method-to-ir.c b/src/mono/mono/mini/method-to-ir.c index eb4ea0a..e5190cf 100644 --- a/src/mono/mono/mini/method-to-ir.c +++ b/src/mono/mono/mini/method-to-ir.c @@ -10085,6 +10085,24 @@ field_access_end: 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);