Article View: comp.lang.c.moderated
Article #2427Re: use of the break statement
From: J. Kanze
Date: Thu, 28 Mar 1996 12:48
Date: Thu, 28 Mar 1996 12:48
56 lines
3262 bytes
3262 bytes
In article <4jbcjd$2l4@solutions.solon.com> falstaff@xs4all.nl
(Falstaff) writes:
|> tanmoy@qcd.Lanl.GOV (Tanmoy Bhattacharya) writes:
|> >> do
|> >> statement;
|> >> while (exp);
|> >> label:
|> >> statement;
|> >> if (exp)
|> >> goto label;
|> >>
|> >> If a compiler can't optimize this, I reserve the right to refuse
|> >> to trust it's optimizations on more complex constructs.
|> >Let us take your example. In the structured form of a loop, a compiler
|> >can specifically check for expressions that are constants and pull
|> >them out of the loop. In the second form, it has to first check that
|> >no other statement branches to the label from anywhere (in which case
|> >it may or may not be expressible as a simple while loop), and only
|> >then make the determination of what are constants. In fact, loop
|> >optimizations are usually easier than control flow analyses that
|> >you need to optimize the latter.
|> I don't agree. Usually the optimization is done near the back-end
|> of the compiler, at which point both program segments will have
|> been decomposed into (identical) basic blocks anyway. The compiler
|> then runs data flow analysis on them to find loop invariant expressions
|> and strength reductions etc. -- and will perform identically on
|> both examples. Only a compiler with a weak optimizer may have to
|> rely on the actual while() statement used to enable certain optimizations.
Roughly speaking, what you are recommending is to throw out any
information that you have, and recalculated it later. As if optimized
compilers are not slow enough as is.
Such techniques *were* frequent in the days of Fortran, and are probably
still frequent in Fortran compilers today, because traditional Fortran
didn't offer a large enough variety of looping constructs, and most
programs had to emulate some of the loops with goto's.
The idea of keeping semantic information for later optimization is not
new. (I first read about it in the mid '80's.) I would imagine today
that most C compilers count on source level information to determine
flow control. (Similarly, Fortran compilers will typically convert
array operations into pointer operations like you would write in C. But
they don't throw away the information that the pointer was originally an
array. The added information means better aliasing analysis, and
typically, better array handling code.)
--
James Kanze (+33) 88 14 49 00 email: kanze@gabi-soft.fr
GABI Software, Sarl., 8 rue des Francs Bourgeois, 67000 Strasbourg, France
Conseils en informatique industrielle --
-- Beratung in industrieller Datenverarbeitung
Technical Details
Message-ID:
<4je1q9$g3n@solutions.solon.com>Path:
arc1-ca.pugleaf.net!solon.com!not-for-mailReferences:
<4hqedf$1m0@solutions.solon.com> <4i2k0n$8jd@solutions.solon.com> <4i97ht$8gb@solutions.solon.com> <4ianbt$h8m@solutions.solon.com>Show Full Headers
Complete Article Headers
Path: arc1-ca.pugleaf.net!solon.com!not-for-mail From: kanze@gabi-soft.fr (J. Kanze) Newsgroups: comp.lang.c.moderated Subject: Re: use of the break statement Date: 28 Mar 1996 06:48:09 -0600 Organization: GABI Software, Sarl. Sender: clc@solutions.solon.com Approved: clc@solutions.solon.com Message-ID: <4je1q9$g3n@solutions.solon.com> References: <4hqedf$1m0@solutions.solon.com> <4i2k0n$8jd@solutions.solon.com> <4i97ht$8gb@solutions.solon.com> <4ianbt$h8m@solutions.solon.com> NNTP-Posting-Host: solutions.solon.com