Re: Loop Optimizations and Gotos

baynes@ukpsshp1.serigate.philips.nl
Mon, 20 Nov 1995 13:56:19 GMT

          From comp.compilers

Related articles
[2 earlier articles]
Loop Optimizations and Gotos dave@occl-cam.demon.co.uk (Dave Lloyd) (1995-11-12)
Re: Loop Optimizations and Gotos cliffc@ami.sps.mot.com (1995-11-13)
Re: Loop Optimizations and Gotos cdg@nullstone.com (1995-11-13)
Re: Loop Optimizations and Gotos faiman@zko.dec.com (1995-11-16)
Re: Loop Optimizations and Gotos hrubin@stat.purdue.edu (1995-11-17)
Re: Loop Optimizations and Gotos j-grout@glibm9.cen.uiuc.edu (1995-11-17)
Re: Loop Optimizations and Gotos baynes@ukpsshp1.serigate.philips.nl (1995-11-20)
Re: Loop Optimizations and Gotos plong@perf.com (Paul Long) (1995-11-21)
Re: Loop Optimizations and Gotos preston@tera.com (1995-11-21)
Re: Loop Optimizations and Gotos cliffc@ami.sps.mot.com (1995-11-21)
Re: Loop Optimizations and Gotos cliffc@ami.sps.mot.com (1995-11-22)
Re: Loop Optimizations and Gotos Paul_Long@ortel.org (1995-11-23)
Re: Loop Optimizations and Gotos bill@amber.ssd.hcsc.com (1995-11-27)
[2 later articles]
| List of all articles for this month |
Newsgroups: comp.compilers
From: baynes@ukpsshp1.serigate.philips.nl
Keywords: C, optimize
Organization: Compilers Central
References: 95-11-076
Date: Mon, 20 Nov 1995 13:56:19 GMT

Jim Allard (jra@gensym.com) wrote:
: [in automatically generated C code, is it worth the effort to generate
: for and while loops rather than equivalent if and goto loops?]


I know of one C compiler (for an embeded system) that if it finds a goto it
turns off most optimizations.


The technology exists for reconstructing loops and is probably used in
(older?) fortran compilers as many loops in fortran have to be constructed
using GOTO. I expect many C compilers may have inherited the technology and
will attempt to do this. However compilers written directly as C compilers
are quite likly to use the structure provided by the programer and not try and
reconstruct their own. Even if a C compiler can reconstruct loops it may not
do a good job. The compiler writers will have concentrated on optimizing
typical code which uses loop constructs rather than code that loops using
gotos. Recronstructed loops are unlikly to receive all the special loop
optimizations that are made. If you can reconstruct the loops and you are
worried about performance it is probably worth doing. In particular
reconstruct 'for' loops that iterate using an obvious control variable.
For example
        for( x = 0; x < 10; x++ )
may recive special optimizations that using the equivalent 'while' loop does
not.




There are two ways a compiler can view code:


1: It can flatten down the code into basic blocks (with no jumps in them) and
work on these finding its own loops and other structures. This is typical of
compilers for unstructured languages though it can be used on structured
languages too. This is able to cope with almost anything, but tends to lose
any hints that can be gained from how the programer wrote the code (eg using
'for' loops).


2: It can use the stucture of the language working recursively on the
structure tree of the parsed code. It the input code is perfectly structured
(each block has one way in and one way out) then it makes a clean and
efficent compiler which can easily look for specifc constructs such for loops
with simple iterators.




--
Stephen Baynes baynes@mulsoc2.serigate.philips.nl
Philips Semiconductors Ltd
Southampton My views are my own.
United Kingdom
--


Post a followup to this message

Return to the comp.compilers page.
Search the comp.compilers archives again.