comp.lang.ada
 help / color / mirror / Atom feed
From: "Randy Brukardt" <randy@rrsoftware.com>
Subject: Re: GNAT Optimization of Constant Expressions
Date: Fri, 18 May 2007 12:20:19 -0500
Date: 2007-05-18T12:20:19-05:00	[thread overview]
Message-ID: <f2kn4p$av6$1@jacob-sparre.dk> (raw)
In-Reply-To: 87k5v631kp.fsf@mid.deneb.enyo.de

"Florian Weimer" <fw@deneb.enyo.de> wrote in message
news:87k5v631kp.fsf@mid.deneb.enyo.de...
...
> It's more likely that the run-time library lacks a few Pure_Function
> pragmas, so the compiler does not know that it's a constant
> expression.  Ideally, GNAT would translate the function calls to GCC
> built-in calls, so that they can be expanded at compile time.  This
> optimization probably kicks in for C and Fortran, whose front ends are
> more closely aligned with the rest of the compiler.

That doesn't match the OP's original description of the problem. He said
that declaring constants in front of the expression made it run fast, even
if they were *not used* in the expression in the loop. That could only
happen if the compiler did a common subexpression elimination in that case,
and a common subexpression elimination is *only* valid on a function call if
it is Pure. (Other functions could have significant side effects that
eliminating the extra calls would make the program incorrect, for example if
the function is a random number generator.)

I think it is more likely that it didn't recognize the functions as being
worth hoisting (there is only one instance of each in the original program)
or it didn't do so because of other concerns. In thinking about it now, the
former is probably more likely.

                         Randy.





  parent reply	other threads:[~2007-05-18 17:20 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-05-16 22:37 GNAT Optimization of Constant Expressions David Smith
2007-05-17  4:50 ` Randy Brukardt
2007-05-17 20:03   ` Gautier
2007-05-17 20:46     ` Randy Brukardt
2007-05-17 22:49       ` David Smith
2007-05-17 23:38         ` Randy Brukardt
2007-05-18  7:58           ` Dmitry A. Kazakov
2007-05-18 11:27           ` Georg Bauhaus
2007-05-18 17:28             ` Randy Brukardt
2007-05-18 16:25       ` Ray Blaak
2007-05-18 17:40         ` Randy Brukardt
2007-05-18 22:51           ` Adam Beneschan
2007-05-19  2:44             ` Randy Brukardt
2007-05-18  9:05   ` Markus E Leypold
2007-05-18  9:47   ` Florian Weimer
2007-05-18 11:32     ` Duncan Sands
2007-05-18 17:20     ` Randy Brukardt [this message]
2007-05-18 17:35       ` Duncan Sands
     [not found]       ` <200705181935.23877.baldrick@free.fr>
2007-05-18 17:49         ` Duncan Sands
2007-05-17  5:30 ` Martin Krischik
2007-05-18  9:56 ` Duncan Sands
2007-05-18 15:39   ` David Smith
2007-05-18 17:08     ` Duncan Sands
     [not found]     ` <200705181908.54920.baldrick@free.fr>
2007-05-18 17:32       ` Duncan Sands
replies disabled

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox