From ad038c6b90b676b7e4be2b6aa405491213375a59 Mon Sep 17 00:00:00 2001 From: fanyang-mono Date: Wed, 24 Apr 2024 14:08:12 -0400 Subject: [PATCH] Check if type is compatible right before emitting box --- src/mono/mono/mini/method-to-ir.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/mono/mono/mini/method-to-ir.c b/src/mono/mono/mini/method-to-ir.c index 8d569eae92a35..c8a4fade7d30f 100644 --- a/src/mono/mono/mini/method-to-ir.c +++ b/src/mono/mono/mini/method-to-ir.c @@ -9595,8 +9595,7 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b if (klass == mono_defaults.void_class) UNVERIFIED; - if (target_type_is_incompatible (cfg, m_class_get_byval_arg (klass), val)) - UNVERIFIED; + /* frequent check in generic code: box (struct), brtrue */ /* @@ -9955,6 +9954,8 @@ mono_method_to_ir (MonoCompile *cfg, MonoMethod *method, MonoBasicBlock *start_b MONO_ADD_INS (cfg->cbb, ins); *sp++ = ins; } else { + if (target_type_is_incompatible (cfg, m_class_get_byval_arg (klass), val)) + UNVERIFIED; *sp++ = mini_emit_box (cfg, val, klass, context_used); } CHECK_CFG_EXCEPTION;