[m-dev.] Deforestation question

Simon Taylor stayl at cs.mu.OZ.AU
Tue Feb 13 10:39:45 AEDT 2001


On Tue, Feb 13, 2001 at 03:37:16AM +1100, Fergus Henderson wrote:
> On 12-Feb-2001, Ralph Becket <rbeck at microsoft.com> wrote:
> > Say I write something like
> > 
> > 	{X, Y} = list__foldl(func(A, {X, Y}) = {X + A, Y + A}, As, {X0, Y0})
> > 
> > and compile under -O6 (or whatever), can I expect the compiler to
> > spot that it is unnecessary to create a new {}/2 cell on every
> > iteration?
> 
> Well, that would certainly be a nice optimization for the compiler to
> do, and with intermodule optimization and deforestation, we have
> most of the machinery to do it.  But currently the compiler does
> not do that optimization.  Nor does it do it if you replace the
> pair type with
> 
> 	:- type mypair ---> mypair(int, int).
> 
> However, it *does* do the optimization if you replace the
> pair type with
> 
> 	:- type mypair ---> mypair(int, int) ; other.
> 
> and add some bogus code for the `other' case!
> The basic reason is that deforestation only occurs for types with more
> than one constructor, where you have a switch statement.

As far as I can tell, deforestation does nothing to either case
other than some unrolling of the foldl loop. I wouldn't expect
it to do more than that.

> Perhaps it would not be hard to change the deforestation heuristics
> so that the deforestation pass will optimize cases like this...
> Simon, what do you think?

What Ralph wants is the unboxing optimization that we've
discussed many times but have never implemented because we
couldn't come up with a decent heuristic.

Simon.
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list