[Mono-devel-list] cmove patch

Paolo Molaro lupus at ximian.com
Fri Jun 20 08:35:20 EDT 2003


On 06/20/03 dietmar wrote:
> > 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).

For the list of instructions, you do:
	if (changes_flags (ins))
		cmov_not_applicable ();

> 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
> scheduling.

Note we may do copy-prop and deadce also after instruction scheduling,
on the low-level representation.

> 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
> cases):
> 
> STLOC (x, ADD (MULT(a,b)), c)

It may be easy, but it would be incorrect to apply it in this case, at
least on x86:-)
add and mul will change the flags, so the cmov will operate on the wrong
flags, not the ones produced by the original compare. So you can't do
the optimization at this level, because you don't have the info needed
to decide if you can do or not the optimization: it's a correctness
issue.

> 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.

If the expression is too complex, it's not worth to do a cmov, because
it means that you'r doing the calculation also in the cases where they
are not needed, so it reduces the effectiveness of the optimization.
We should also consider side effects that the expression may have: so I
think we should just do the optimization on simple cases right now.

lupus

-- 
-----------------------------------------------------------------
lupus at debian.org                                     debian/rules
lupus at ximian.com                             Monkeys do it better



More information about the Mono-devel-list mailing list