Skip to content

Commit

Permalink
[jit] Make alias analysis properly handle alias cloberring
Browse files Browse the repository at this point in the history
Alias analysis attempts to remove indirection when using OP_LDADDR (which fetches the address of a variable). For example :

	ldaddr r1 <- r0
	load_mem r2 <- r1

is equivalent to

	mov r2 <- r0

The remembered r1 alias needs to be forgotten in case r1 is changed. We were handling this for direct assignment with MOV, but not for the more subtle case where an alias to r1 would be passed to a call, which could lead to changing r1.

mono#14872
  • Loading branch information
BrzVlad committed Jun 19, 2019
1 parent 879c850 commit 95af2e7
Showing 1 changed file with 35 additions and 0 deletions.
35 changes: 35 additions & 0 deletions mono/mini/alias-analysis.c
Expand Up @@ -150,6 +150,30 @@ lower_store_imm (MonoCompile *cfg, MonoInst *store, MonoInst *ldaddr)
return TRUE;
}

static void
kill_call_arg_alias (MonoCompile *cfg, GHashTable *addr_loads, GSList *l)
{
for (; l; l = l->next) {
MonoInst *tmp;
guint32 regpair, reg;

regpair = (guint32)(gssize)(l->data);
reg = regpair & 0xffffff;

tmp = (MonoInst *)g_hash_table_lookup (addr_loads, GINT_TO_POINTER (reg));
if (tmp) {
// This call passes an alias as an argument. This means that the contents
// of the passed pointer can change. If the content is also an alias then
// we need to forget it as we do for moves.
if (g_hash_table_remove (addr_loads, GINT_TO_POINTER (((MonoInst*)tmp->inst_p0)->dreg))) {
if (cfg->verbose_level > 2)
printf ("Killed alias %d\n", ((MonoInst*)tmp->inst_p0)->dreg);
}

}
}
}

static gboolean
lower_memory_access (MonoCompile *cfg)
{
Expand Down Expand Up @@ -264,6 +288,17 @@ lower_memory_access (MonoCompile *cfg)
needs_dce = TRUE;
}
break;
default: {
if (MONO_IS_CALL (ins)) {
MonoCallInst *call = (MonoCallInst*)ins;

kill_call_arg_alias (cfg, addr_loads, call->out_ireg_args);
}
// FIXME Kill more aliases if used as dreg, since we are not in ssa form.
// This would need some optimizations so we don't lookup hash table for every
// instruction
break;
}
}
}
}
Expand Down

0 comments on commit 95af2e7

Please sign in to comment.