Re: non trivial constant folding

Dennis Ritchie <dmr@bell-labs.com>
11 Jan 2001 12:25:30 -0500

          From comp.compilers

Related articles
[9 earlier articles]
Re: non trivial constant folding metzger@rsn.hp.com (Robert Metzger) (2001-01-09)
Re: non trivial constant folding sjmeyer@www.tdl.com (2001-01-09)
Re: non trivial constant folding henry@spsystems.net (2001-01-09)
Re: non trivial constant folding dew@cray.com (2001-01-09)
Re: non trivial constant folding mpointie@eden-studios.fr (MickaŽl Pointier) (2001-01-09)
Re: non trivial constant folding morrell@morrell.cup.hp.com (Michael Morrell) (2001-01-09)
Re: non trivial constant folding dmr@bell-labs.com (Dennis Ritchie) (2001-01-11)
Re: non trivial constant folding ONeillCJ@logica.com (Conor O'Neill) (2001-01-11)
Re: non trivial constant folding sjmeyer@www.tdl.com (2001-01-18)
Re: non trivial constant folding genew@shuswap.net (2001-01-18)
Re: non trivial constant folding anton@mips.complang.tuwien.ac.at (2001-01-19)
Re: non trivial constant folding genew@shuswap.net (2001-01-20)
Re: non trivial constant folding anton@mips.complang.tuwien.ac.at (2001-01-26)
[1 later articles]
| List of all articles for this month |

From: Dennis Ritchie <dmr@bell-labs.com>
Newsgroups: comp.compilers
Date: 11 Jan 2001 12:25:30 -0500
Organization: Bell Labs/Lucent Technologies
References: 01-01-015 01-01-022 01-01-040
Keywords: C, optimize, history
Posted-Date: 11 Jan 2001 12:25:30 EST

Steve Meyer wrote:
>
> The old Bell Labs non portable C Compiler (early Unix compiler) had a
> very good heuristic method for finding foldable constants (It is
> described in Ctour document from 70s - someone posted url to it here a
> while ago but I did not save it).


Try http://plan9.bell-labs.com/7thEdMan/bswv7.html .
Download the PDF or ps.gz version of V7vol2b, and look up C tour.


> Idea is to sort expressions by
> operand complexity for communative and associative operators. Int
> constant is less complex than real, etc. Then apply constant folding
> after sorting. Then re-sort and re-fold until no progress or for a
> few times. The sorting was most complex (on left) to least complex
> order which has the added advantage that simple register assignment
> algorithms do quite well on expressions with left operands more
> complex.


Pretty much. This part wasn't explicitly iterative--it was done once,
though I suppose the recursiveness and other accidents of coding
got the routines called more than once on occasion.


Dennis


Post a followup to this message

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