[interp] Small interp tweaks (#48412)
authorVlad Brezae <brezaevlad@gmail.com>
Fri, 19 Feb 2021 09:07:44 +0000 (11:07 +0200)
committerGitHub <noreply@github.com>
Fri, 19 Feb 2021 09:07:44 +0000 (11:07 +0200)
* [interp] Fix overflow in PROFILE_INTERP log

* [interp] Replace LDFLDA of offset 0 field with MOV

Commonly used when accessing first field of valuetypes, eg span operations. Will help with cprop and remove redundant instruction.

* [interp] Remove redundant opcode

src/mono/mono/mini/interp/interp.c
src/mono/mono/mini/interp/mintops.def
src/mono/mono/mini/interp/transform.c

index e0e7abf..8519446 100644 (file)
@@ -4841,11 +4841,6 @@ call:
                        ip += 4;;
                        MINT_IN_BREAK;
                }
-               MINT_IN_CASE(MINT_INTRINS_BYREFERENCE_GET_VALUE) {
-                       LOCAL_VAR (ip [1], gpointer) = *LOCAL_VAR (ip [2], gpointer*);
-                       ip += 3;
-                       MINT_IN_BREAK;
-               }
                MINT_IN_CASE(MINT_INTRINS_UNSAFE_ADD_BYTE_OFFSET) {
                        LOCAL_VAR (ip [1], gpointer) = LOCAL_VAR (ip [2], guint8*) + LOCAL_VAR (ip [3], mono_u);
                        ip += 4;
@@ -7169,7 +7164,13 @@ interp_add_imethod (gpointer method)
 static int
 imethod_opcount_comparer (gconstpointer m1, gconstpointer m2)
 {
-       return (*(InterpMethod**)m2)->opcounts - (*(InterpMethod**)m1)->opcounts;
+       long diff = (*(InterpMethod**)m2)->opcounts > (*(InterpMethod**)m1)->opcounts;
+       if (diff > 0)
+               return 1;
+       else if (diff < 0)
+               return -1;
+       else
+               return 0;
 }
 
 static void
index 9103e2d..04dfb90 100644 (file)
@@ -716,7 +716,6 @@ OPDEF(MINT_INTRINS_ENUM_HASFLAG, "intrins_enum_hasflag", 5, 1, 2, MintOpClassTok
 OPDEF(MINT_INTRINS_GET_HASHCODE, "intrins_get_hashcode", 3, 1, 1, MintOpNoArgs)
 OPDEF(MINT_INTRINS_GET_TYPE, "intrins_get_type", 3, 1, 1, MintOpNoArgs)
 OPDEF(MINT_INTRINS_SPAN_CTOR, "intrins_span_ctor", 4, 1, 2, MintOpNoArgs)
-OPDEF(MINT_INTRINS_BYREFERENCE_GET_VALUE, "intrins_byreference_get_value", 3, 1, 1, MintOpNoArgs)
 OPDEF(MINT_INTRINS_UNSAFE_ADD_BYTE_OFFSET, "intrins_unsafe_add_byte_offset", 4, 1, 2, MintOpNoArgs)
 OPDEF(MINT_INTRINS_UNSAFE_BYTE_OFFSET, "intrins_unsafe_byte_offset", 4, 1, 2, MintOpNoArgs)
 OPDEF(MINT_INTRINS_RUNTIMEHELPERS_OBJECT_HAS_COMPONENT_SIZE, "intrins_runtimehelpers_object_has_component_size", 3, 1, 1, MintOpNoArgs)
index 0b94432..8a60845 100644 (file)
@@ -2026,7 +2026,7 @@ interp_handle_intrinsics (TransformData *td, MonoMethod *target_method, MonoClas
                *op = MINT_INTRINS_CLEAR_WITH_REFERENCES;
        } else if (in_corlib && !strcmp (klass_name_space, "System") && !strcmp (klass_name, "ByReference`1")) {
                g_assert (!strcmp (tm, "get_Value"));
-               *op = MINT_INTRINS_BYREFERENCE_GET_VALUE;
+               *op = MINT_LDIND_I;
        } else if (in_corlib && !strcmp (klass_name_space, "System") && !strcmp (klass_name, "Marvin")) {
                if (!strcmp (tm, "Block"))
                        *op = MINT_INTRINS_MARVIN_BLOCK;
@@ -5621,14 +5621,20 @@ generate_code (TransformData *td, MonoMethod *method, MonoMethodHeader *header,
                                        goto_if_nok (error, exit);
                                } else {
                                        td->sp--;
+                                       int foffset = m_class_is_valuetype (klass) ? field->offset - MONO_ABI_SIZEOF (MonoObject) : field->offset;
                                        if (td->sp->type == STACK_TYPE_O) {
                                                interp_add_ins (td, MINT_LDFLDA);
+                                               td->last_ins->data [0] = foffset;
                                        } else {
                                                int sp_type = td->sp->type;
                                                g_assert (sp_type == STACK_TYPE_MP || sp_type == STACK_TYPE_I);
-                                               interp_add_ins (td, MINT_LDFLDA_UNSAFE);
+                                               if (foffset) {
+                                                       interp_add_ins (td, MINT_LDFLDA_UNSAFE);
+                                                       td->last_ins->data [0] = foffset;
+                                               } else {
+                                                       interp_add_ins (td, MINT_MOV_P);
+                                               }
                                        }
-                                       td->last_ins->data [0] = m_class_is_valuetype (klass) ? field->offset - MONO_ABI_SIZEOF (MonoObject) : field->offset;
                                        interp_ins_set_sreg (td->last_ins, td->sp [0].local);
                                        push_simple_type (td, STACK_TYPE_MP);
                                        interp_ins_set_dreg (td->last_ins, td->sp [-1].local);