Skip to content

Commit

Permalink
[jit] Avoid generating wbarriers for vtype stores to the stack. (dotn…
Browse files Browse the repository at this point in the history
…et#2089)

The existing heuristic doesn't work with llvm.

Co-authored-by: Zoltan Varga <[email protected]>
  • Loading branch information
monojenkins and vargaz authored Jan 31, 2020
1 parent 0713a24 commit b652dd0
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 7 deletions.
9 changes: 8 additions & 1 deletion src/mono/mono/mini/alias-analysis.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,9 +255,16 @@ lower_memory_access (MonoCompile *cfg)
#endif
case OP_STORER8_MEMBASE_REG:
case OP_STOREV_MEMBASE:
tmp = NULL;
if (ins->opcode == OP_STOREV_MEMBASE) {
tmp = (MonoInst *)g_hash_table_lookup (addr_loads, GINT_TO_POINTER (ins->dreg));
if (tmp)
ins->flags |= MONO_INST_STACK_STORE;
}
if (ins->inst_offset != 0)
continue;
tmp = (MonoInst *)g_hash_table_lookup (addr_loads, GINT_TO_POINTER (ins->dreg));
if (!tmp)
tmp = (MonoInst *)g_hash_table_lookup (addr_loads, GINT_TO_POINTER (ins->dreg));
if (tmp) {
if (cfg->verbose_level > 2) { printf ("Found candidate store:"); mono_print_ins (ins); }
if (lower_store (cfg, ins, tmp)) {
Expand Down
2 changes: 1 addition & 1 deletion src/mono/mono/mini/decompose.c
Original file line number Diff line number Diff line change
Expand Up @@ -1287,7 +1287,7 @@ mono_decompose_vtype_opts (MonoCompile *cfg)

dreg = alloc_preg (cfg);
EMIT_NEW_BIALU_IMM (cfg, dest, OP_ADD_IMM, dreg, ins->inst_destbasereg, ins->inst_offset);
mini_emit_memory_copy (cfg, dest, src, src_var->klass, src_var->backend.is_pinvoke, 0);
mini_emit_memory_copy (cfg, dest, src, src_var->klass, src_var->backend.is_pinvoke, ins->flags);
break;
}
case OP_LOADV_MEMBASE: {
Expand Down
11 changes: 6 additions & 5 deletions src/mono/mono/mini/memory-access.c
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,8 @@ mini_emit_wb_aware_memcpy (MonoCompile *cfg, MonoClass *klass, MonoInst *iargs[4
}

static void
mini_emit_memory_copy_internal (MonoCompile *cfg, MonoInst *dest, MonoInst *src, MonoClass *klass, int explicit_align, gboolean native)
mini_emit_memory_copy_internal (MonoCompile *cfg, MonoInst *dest, MonoInst *src, MonoClass *klass, int explicit_align, gboolean native,
gboolean stack_store)
{
MonoInst *iargs [4];
int size;
Expand Down Expand Up @@ -404,8 +405,8 @@ mini_emit_memory_copy_internal (MonoCompile *cfg, MonoInst *dest, MonoInst *src,

mini_emit_write_barrier (cfg, dest, load);
return;

} else if (cfg->gen_write_barriers && (m_class_has_references (klass) || size_ins) && !native) { /* if native is true there should be no references in the struct */
} else if (cfg->gen_write_barriers && (m_class_has_references (klass) || size_ins) &&
!native && !stack_store) { /* if native is true there should be no references in the struct */
/* Avoid barriers when storing to the stack */
if (!((dest->opcode == OP_ADD_IMM && dest->sreg1 == cfg->frame_reg) ||
(dest->opcode == OP_LDADDR))) {
Expand Down Expand Up @@ -504,7 +505,7 @@ mini_emit_memory_store (MonoCompile *cfg, MonoType *type, MonoInst *dest, MonoIn
tmp_var = mono_compile_create_var (cfg, type, OP_LOCAL);
EMIT_NEW_TEMPSTORE (cfg, mov, tmp_var->inst_c0, value);
EMIT_NEW_VARLOADA (cfg, addr, tmp_var, tmp_var->inst_vtype);
mini_emit_memory_copy_internal (cfg, dest, addr, mono_class_from_mono_type_internal (type), 1, FALSE);
mini_emit_memory_copy_internal (cfg, dest, addr, mono_class_from_mono_type_internal (type), 1, FALSE, (ins_flag & MONO_INST_STACK_STORE) != 0);
} else {
MonoInst *ins;

Expand Down Expand Up @@ -594,7 +595,7 @@ mini_emit_memory_copy (MonoCompile *cfg, MonoInst *dest, MonoInst *src, MonoClas
mini_emit_memory_barrier (cfg, MONO_MEMORY_BARRIER_SEQ);
}

mini_emit_memory_copy_internal (cfg, dest, src, klass, explicit_align, native);
mini_emit_memory_copy_internal (cfg, dest, src, klass, explicit_align, native, (ins_flag & MONO_INST_STACK_STORE) != 0);

if (ins_flag & MONO_INST_VOLATILE) {
/* Volatile loads have acquire semantics, see 12.6.7 in Ecma 335 */
Expand Down
2 changes: 2 additions & 0 deletions src/mono/mono/mini/mini.h
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,8 @@ enum {
MONO_INST_LMF = 32,
/* On loads, the source address points to a constant value */
MONO_INST_INVARIANT_LOAD = 64,
/* On stores, the destination is the stack */
MONO_INST_STACK_STORE = 64,
/* On variables, the variable needs GC tracking */
MONO_INST_GC_TRACK = 128,
/*
Expand Down

0 comments on commit b652dd0

Please sign in to comment.