This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: How to not fold constants?
- To: moshier at mediaone dot net
- Subject: Re: How to not fold constants?
- From: Toon Moene <toon at moene dot indiv dot nluug dot nl>
- Date: Tue, 10 Aug 1999 21:38:39 +0200
- CC: gcc at gcc dot gnu dot org
- Organization: Moene Computational Physics, Maartensdijk, The Netherlands
- References: <Pine.LNX.4.05.9908100836430.16704-100000@moshier.ne.mediaone.net>
Stephen L Moshier wrote:
> IEEE awareness rules in C9X require that floating point constant
> expressions sometimes get folded and sometimes not. For example, if
> the expression occurs in executable code, it might not be folded; but
^^^^^ ^^^
"might not" or "shall not" ?
> if it is a static initializer it would be folded.
^^^^^
"would" or "shall" ?
> It looks like c-parse.c makes up a tree containing the constant
> expression and passes that tree to fold-const.c, without any indication
> of the context where the expression came from in the source program.
> Other functions also call fold-const.c and maybe they are not aware
> of the context either. The question is, how can fold-const.c figure
> out whether the expression is a static initializer or is executable code?
I think an easier (and more obvious IMHO) solution is to have the C
frontend "Do The Right Thing", i.e. call build(fold(...)) in case of a
static initializer and build(...) otherwise [or is there a snag in there
that I'm overlooking ?]
More serious is the problem of constant propagation. I do not know
off-hand how much cprop gcc does these days, but with it, the following
code:
p = 0.1;
... /* no intervening assignments to p */
for (i = 0; i < n; i++)
a[i] = 10.0 * p * b[i];
could be turned into:
for (i = 0; i < n; i++)
a[i] = one * b[i];
where `one' is the constant one gets when letting the compiler combine
0.1 * 10.0 instead of letting it happen at run time ["what's the
difference ?" I hear from the audience. The difference is that the
rounding mode (away from or towards zero or up or down) might be
different at compile time than at run time, giving you a different
`one'].
It's not clear from your mail what the C9X standard requires here, but
for consistency's sake I would say that it also has to prohibit this
"constant folding".
--
Toon Moene (toon@moene.indiv.nluug.nl)
Saturnushof 14, 3738 XG Maartensdijk, The Netherlands
Phone: +31 346 214290; Fax: +31 346 214286
GNU Fortran: http://world.std.com/~burley/g77.html