Skip to content

Commit 51d8e98

Browse files
authored
[interp] Small interp tweaks (#48412)
* [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
1 parent e6cc4ae commit 51d8e98

File tree

3 files changed

+16
-10
lines changed

3 files changed

+16
-10
lines changed

src/mono/mono/mini/interp/interp.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4841,11 +4841,6 @@ interp_exec_method (InterpFrame *frame, ThreadContext *context, FrameClauseArgs
48414841
ip += 4;;
48424842
MINT_IN_BREAK;
48434843
}
4844-
MINT_IN_CASE(MINT_INTRINS_BYREFERENCE_GET_VALUE) {
4845-
LOCAL_VAR (ip [1], gpointer) = *LOCAL_VAR (ip [2], gpointer*);
4846-
ip += 3;
4847-
MINT_IN_BREAK;
4848-
}
48494844
MINT_IN_CASE(MINT_INTRINS_UNSAFE_ADD_BYTE_OFFSET) {
48504845
LOCAL_VAR (ip [1], gpointer) = LOCAL_VAR (ip [2], guint8*) + LOCAL_VAR (ip [3], mono_u);
48514846
ip += 4;
@@ -7169,7 +7164,13 @@ interp_add_imethod (gpointer method)
71697164
static int
71707165
imethod_opcount_comparer (gconstpointer m1, gconstpointer m2)
71717166
{
7172-
return (*(InterpMethod**)m2)->opcounts - (*(InterpMethod**)m1)->opcounts;
7167+
long diff = (*(InterpMethod**)m2)->opcounts > (*(InterpMethod**)m1)->opcounts;
7168+
if (diff > 0)
7169+
return 1;
7170+
else if (diff < 0)
7171+
return -1;
7172+
else
7173+
return 0;
71737174
}
71747175

71757176
static void

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

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -716,7 +716,6 @@ OPDEF(MINT_INTRINS_ENUM_HASFLAG, "intrins_enum_hasflag", 5, 1, 2, MintOpClassTok
716716
OPDEF(MINT_INTRINS_GET_HASHCODE, "intrins_get_hashcode", 3, 1, 1, MintOpNoArgs)
717717
OPDEF(MINT_INTRINS_GET_TYPE, "intrins_get_type", 3, 1, 1, MintOpNoArgs)
718718
OPDEF(MINT_INTRINS_SPAN_CTOR, "intrins_span_ctor", 4, 1, 2, MintOpNoArgs)
719-
OPDEF(MINT_INTRINS_BYREFERENCE_GET_VALUE, "intrins_byreference_get_value", 3, 1, 1, MintOpNoArgs)
720719
OPDEF(MINT_INTRINS_UNSAFE_ADD_BYTE_OFFSET, "intrins_unsafe_add_byte_offset", 4, 1, 2, MintOpNoArgs)
721720
OPDEF(MINT_INTRINS_UNSAFE_BYTE_OFFSET, "intrins_unsafe_byte_offset", 4, 1, 2, MintOpNoArgs)
722721
OPDEF(MINT_INTRINS_RUNTIMEHELPERS_OBJECT_HAS_COMPONENT_SIZE, "intrins_runtimehelpers_object_has_component_size", 3, 1, 1, MintOpNoArgs)

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

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2026,7 +2026,7 @@ interp_handle_intrinsics (TransformData *td, MonoMethod *target_method, MonoClas
20262026
*op = MINT_INTRINS_CLEAR_WITH_REFERENCES;
20272027
} else if (in_corlib && !strcmp (klass_name_space, "System") && !strcmp (klass_name, "ByReference`1")) {
20282028
g_assert (!strcmp (tm, "get_Value"));
2029-
*op = MINT_INTRINS_BYREFERENCE_GET_VALUE;
2029+
*op = MINT_LDIND_I;
20302030
} else if (in_corlib && !strcmp (klass_name_space, "System") && !strcmp (klass_name, "Marvin")) {
20312031
if (!strcmp (tm, "Block"))
20322032
*op = MINT_INTRINS_MARVIN_BLOCK;
@@ -5621,14 +5621,20 @@ generate_code (TransformData *td, MonoMethod *method, MonoMethodHeader *header,
56215621
goto_if_nok (error, exit);
56225622
} else {
56235623
td->sp--;
5624+
int foffset = m_class_is_valuetype (klass) ? field->offset - MONO_ABI_SIZEOF (MonoObject) : field->offset;
56245625
if (td->sp->type == STACK_TYPE_O) {
56255626
interp_add_ins (td, MINT_LDFLDA);
5627+
td->last_ins->data [0] = foffset;
56265628
} else {
56275629
int sp_type = td->sp->type;
56285630
g_assert (sp_type == STACK_TYPE_MP || sp_type == STACK_TYPE_I);
5629-
interp_add_ins (td, MINT_LDFLDA_UNSAFE);
5631+
if (foffset) {
5632+
interp_add_ins (td, MINT_LDFLDA_UNSAFE);
5633+
td->last_ins->data [0] = foffset;
5634+
} else {
5635+
interp_add_ins (td, MINT_MOV_P);
5636+
}
56305637
}
5631-
td->last_ins->data [0] = m_class_is_valuetype (klass) ? field->offset - MONO_ABI_SIZEOF (MonoObject) : field->offset;
56325638
interp_ins_set_sreg (td->last_ins, td->sp [0].local);
56335639
push_simple_type (td, STACK_TYPE_MP);
56345640
interp_ins_set_dreg (td->last_ins, td->sp [-1].local);

0 commit comments

Comments
 (0)