[Mono-devel-list] cmove patch

dietmar dietmar at ximian.com
Fri Jun 20 05:03:38 EDT 2003

On Thu, 2003-06-19 at 10:52, Paolo Molaro wrote:
> On 06/18/03 dietmar wrote:
> > if (cond) a = x; else a = y;
> > 
> > which could be translated into 2 conditional movex
> > 
> > cmove (cond, a, x)
> > cmove (!cond, a, y)
> > 
> > but x and y can be expression, so they can set the EFALGS. Sure, we
> can
> > avoid that if we first compute them, but IMO thats a bit clumsy.
> We need to add that kind of info to the machine descriptions: which
> instructions modify the flags and so on: with that in place it's easy
> to
> check for this case.

I would say its possible (instead of easy).

> > any better ideas, suggestion?
> Note: the use of conditional move instructions needs to be dependent
> on
> the MONO_OPT_CMOV optimization flag.
sure, this is just a prototype to play around.

> The main issue with your patch is that we can't do the conditional
> moves at 
> the point you inserted them in the compilation process: it needs to
> happen after instruction selection and also probably after local
> register allocation, since it would be very complex otherwise to
> take into account conditional moves in some optimizations (copy prop,
> instruction scheduling, register allocation itself).

Well, I agree that we have a phase ordering problem here, but its the
best place i found. 

Please notice that I inserted the cmove optimization after all other ssa
based optimizations, just before instruction selection. So you dont need
to consider cmove for complex optimizations like copy prop (althought
IMO it would be even simple to consider cmove for ssa based
optimizations). And i think its also no real problem for instruction

The only problem I see it with local register allocation. Maybe its
would be possible to detect more cmoves if we do it after we assigned
all registers.

But the current version has one big advantage, and thats why i have done
it that way. It works on the tree presentation. Here is a example:

if (v == true) {
	x = a*b+c;

at tree level its easy to detect this, because the whole expression is
just one tree (ar just a few trees if you want to detect more complex

STLOC (x, ADD (MULT(a,b)), c)

After instruction selection its a list of instruction:

r1 = a * b;
r2 = r1 + c;
mov x, r2

Well, that list of instructions can be much more complex, for example if
the expression is more complex, or when the local register allocator
spill and reloads variables.

So I dont really have an idea howto detect cmoves on this level.

- Dietmar

More information about the Mono-devel-list mailing list