Skip to content

Commit 2ec664a

Browse files
authored
[release/9.0-staging] [mono][interp] Minor SSA fixes (#116428)
* [mono][interp] Add possibility to configure interp options from env var * [mono][interp] Update var definition when inserting new instructions during cprop (#116179) The definition was not updated, leading to invalid optimizations later on. * [mono][interp] Fix broken code attempting to reapply superinstruction optimization (#116069) For each instruction in a basic block we check for patterns. In a certain case, once we replaced the instruction with a new one, we were attempting to do a loop reiteration by setting `ins = ins->prev` so after the loop reincrements with `ins = ins->next` we check super instruction patterns again for the current instruction. This is broken if `ins` was the first instruction in a basic block, aka `ins->prev` is NULL. This used to be impossible before SSA optimizations, since super instruction pass was applying optimizations in a single basic block only.
1 parent 805cb73 commit 2ec664a

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

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

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8981,6 +8981,10 @@ mono_ee_interp_init (const char *opts)
89818981
set_context (NULL);
89828982

89838983
interp_parse_options (opts);
8984+
8985+
const char *env_opts = g_getenv ("MONO_INTERPRETER_OPTIONS");
8986+
if (env_opts)
8987+
interp_parse_options (env_opts);
89848988
/* Don't do any optimizations if running under debugger */
89858989
if (mini_get_debug_options ()->mdb_optimizations)
89868990
mono_interp_opt = 0;

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3124,6 +3124,7 @@ interp_cprop (TransformData *td)
31243124
ins->data [2] = GINT_TO_UINT16 (ldsize);
31253125

31263126
interp_clear_ins (ins->prev);
3127+
td->var_values [ins->dreg].def = ins;
31273128
}
31283129
if (td->verbose_level) {
31293130
g_print ("Replace ldloca/ldobj_vt pair :\n\t");
@@ -3204,6 +3205,7 @@ interp_cprop (TransformData *td)
32043205
ins->data [2] = vtsize;
32053206

32063207
interp_clear_ins (ins->prev);
3208+
td->var_values [ins->dreg].def = ins;
32073209

32083210
// MINT_MOV_DST_OFF doesn't work if dreg is allocated at the same location as the
32093211
// field value to be stored, because its behavior is not atomic in nature. We first
@@ -3400,9 +3402,11 @@ interp_super_instructions (TransformData *td)
34003402
current_liveness.bb_dfs_index = bb->dfs_index;
34013403
current_liveness.ins_index = 0;
34023404
for (InterpInst *ins = bb->first_ins; ins != NULL; ins = ins->next) {
3403-
int opcode = ins->opcode;
3405+
int opcode;
34043406
if (bb->dfs_index >= td->bblocks_count_no_eh || bb->dfs_index == -1 || (ins->flags & INTERP_INST_FLAG_LIVENESS_MARKER))
34053407
current_liveness.ins_index++;
3408+
retry_ins:
3409+
opcode = ins->opcode;
34063410
if (MINT_IS_NOP (opcode))
34073411
continue;
34083412

@@ -3801,9 +3805,7 @@ interp_super_instructions (TransformData *td)
38013805
g_print ("superins: ");
38023806
interp_dump_ins (ins, td->data_items);
38033807
}
3804-
// The newly added opcode could be part of further superinstructions. Retry
3805-
ins = ins->prev;
3806-
continue;
3808+
goto retry_ins;
38073809
}
38083810
}
38093811
}

0 commit comments

Comments
 (0)