[mercury-users] accumulator introduction

Zoltan Somogyi zs at cs.mu.OZ.AU
Mon Jul 17 08:53:05 AEST 2000


On 10-Jul-2000, Michael Day <mcda at students.cs.mu.oz.au> wrote:
> Is gcc any better at optimising for loops than hand rolled goto loops?

Most current compilers will treat a hand rolled goto loop the same way as
they will a while loop, i.e. the two should generate the same code if the
labels involved in the hand-written loop are local. I would be very surprised
if gcc were different.

The real difference between hand-written goto loops on the one hand and while
and for loops on the other is that with the former, the labels may be visible
outside the function defining them if the program uses gcc extensions. If
the C compiler cannot see all at once all the places that can jump to a label,
there are some optimizations it cannot perform, e.g. it cannot rearrange the
registers in which the variables live at that label are stored. This is why
Mercury uses local labels whereever possible.

Performance problems may also arise if a hand written goto loop isn't
equivalent to any while loop, e.g. because it has two or more entry points.
In technical terms, such code is called irreducible. Some standard
optimization algorithms are applicable only to reducible code. However,
the Mercury compiler never generates irreducible loops.

Zoltan.
--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list