Re: non trivial constant folding

bonzini@gnu.org (Bonz)
6 Jan 2001 22:12:03 -0500

          From comp.compilers

Related articles
non trivial constant folding mpointie@eden-studios.fr (Mickaƫl Pointier) (2001-01-05)
Re: non trivial constant folding broeker@physik.rwth-aachen.de (Hans-Bernhard Broeker) (2001-01-05)
Re: non trivial constant folding mihai@cs.wisc.edu (Mihai Christodorescu) (2001-01-06)
Re: non trivial constant folding pat@jantar.org (Patryk Zadarnowski) (2001-01-06)
Re: non trivial constant folding bonzini@gnu.org (2001-01-06)
Re: non trivial constant folding idbaxter@semdesigns.com (Ira D. Baxter) (2001-01-06)
Re: non trivial constant folding cfc@world.std.com (Chris F Clark) (2001-01-06)
Re: non trivial constant folding anton@mips.complang.tuwien.ac.at (2001-01-09)
Re: non trivial constant folding anton@mips.complang.tuwien.ac.at (2001-01-09)
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)
[12 later articles]
| List of all articles for this month |

From: bonzini@gnu.org (Bonz)
Newsgroups: comp.compilers
Date: 6 Jan 2001 22:12:03 -0500
Organization: Mailgate.ORG Server - http://www.Mailgate.ORG
References: 01-01-015
Keywords: optimize
Posted-Date: 06 Jan 2001 22:12:03 EST

> +(+(1.000000,var),1.000000)


Even if it is quite far from the direct question, it might help to
know how Mathematica handles this. Each operator has attributes
including "Flat" (associative) and "Unordered" (commutative).
Mathematica uses lists internally and automatically converts for
"Flat" operators


    Dot(Dot(a,b),c) ---> Dot(a,b,c)


(Dot is matrix multiplication). For "Unordered" operators it also sorts
items in a canonical order; for example:


    Plus(1,a,1) ---> Plus(1,1,a)


Then it does not do constant folding, but having the expression in this
state makes it simple.


What I'd call "non trivial folding" (not really constant folding, but
generically parse tree folding), instead, is converting for example


        !((a < b) && (b < c)) to
        !(a < b) || !(b < c) to
        a >= b || b >= c


or


        (a >= 5) && (a < 10) to
        (unsigned) (a - 5) < 5


or finally


        a * 16 to
        a << 4


I know that GCC does some of these. The source file is fold.c if
memory serves me correctly, but it is dauntingly long for taking a
quick look at it (in the order of 5k lines).


Paolo


Post a followup to this message

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