Re: non trivial constant folding

Michael Morrell <morrell@morrell.cup.hp.com>
9 Jan 2001 23:23:55 -0500

          From comp.compilers

Related articles
[8 earlier articles]
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)
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)
[2 later articles]
| List of all articles for this month |

From: Michael Morrell <morrell@morrell.cup.hp.com>
Newsgroups: comp.compilers
Date: 9 Jan 2001 23:23:55 -0500
Organization: SSO-IT, Hewlett-Packard Co.
References: 01-01-015 01-01-022
Keywords: optimize, C
Posted-Date: 09 Jan 2001 23:23:55 EST

Mihai Christodorescu <mihai@cs.wisc.edu> wrote:
> As far as I know, expression rewriting for optimization purposes is
> NP-complete. There are some compilers that perform some expression
> optimizations, but not really extensive, as you have noticed yourself.
> There is also another problem: the optimized expression can behave
> differently than the original expression, due to operations being executed
> in different order/with different operands. Consider:
> "MAXINT + x - 1"
> If x is 1, then evaluating MAXINT + x will overflow.


> If you optimize the expression to be:
> "the_value_of_MAXINT_minus_1 + x"
> (i.e. you evaluate MAXINT - 1 at compile time), then if x is 1, the
> expression will not overflow. Of course, these are contrived examples, but a
> compiler has to work for all cases, not most of the time (OK, at least in
> theory).


But what you suggest is perfectly fine in C. An overflow produces
undefined behavior and one of the allowed results is to not actually
overflow. What is not allowed is converting an expression from one
which cannot overflow to one which would.


    Michael


Post a followup to this message

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