[Mono-devel-list] StringBuilder patch

Piers Haken piersh at friskit.com
Tue Jan 13 18:35:02 EST 2004

> On 01/12/04 Piers Haken wrote:
> > - how easy would it be to implement support for this kind of 
> > optimization in the current JIT framework.
> It's not hard to implement. In the peephole pass, when a cond 
> branch is found, you can look at the true and false basic blocks.
> One should look like:
> 	iconst %reg // or storei4_membase_imm
> and the other:
> 	iconst %reg // or storei4_membase_imm
> 	br

Yeah, you could certainly apply this optimization in a few limited cases
during peephole. However, I believe you'd be able to do this (and similar
optimizations) in more complex cases like...

	if (c == 7)
		return obj.method (1);
		return obj.method (19);

...if you had some kind of higher-level branch analysis that occurred
earlier in the process. I'm not sure if burg would be useful for this or
not, but imagine you had some tuples that represented operation on sets of
basic blocks, for example:
	IF_ELSE (<cond>,<if tree>,<else tree>)
	WHILE (<cond>,<tree>)
	DO (<cond>,<tree>)
	TREES (<tree>, <tree>)

Then, instead of thinking of a method as a set of basic blocks, each of
which is a forest of tuple-trees, then you think of the method as a single
tuple-tree. Then, doing things like common subexpression elimination, loop
invariance, the above ternary extractions, etc... would just be a question
of moving nodes of the tree upwards as far as they can go while retaining
their store dependancies.

Obviously this isn't really well thought out within the context of the mono
JIT which I'm not really familiar with. It's just a concept I was using a
while ago when I was working on a decompiler (same idea, different results).


More information about the Mono-devel-list mailing list