From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-2.9 required=5.0 tests=BAYES_00,FREEMAIL_FROM, MAILING_LIST_MULTI autolearn=unavailable autolearn_force=no version=3.4.4 X-Google-Thread: 103376,acba876b1e3c9639 X-Google-Attributes: gid103376,public X-Google-Language: ENGLISH,ASCII-7-bit Path: g2news1.google.com!news3.google.com!proxad.net!fdn.fr!freenix!news.enst.fr!news.rfc1149.net!not-for-mail From: Duncan Sands Newsgroups: comp.lang.ada Subject: Re: GNAT Optimization of Constant Expressions Date: Fri, 18 May 2007 19:35:23 +0200 Organization: ENST, France Message-ID: References: <1179355028.624745.258370@q75g2000hsh.googlegroups.com> <87k5v631kp.fsf@mid.deneb.enyo.de> NNTP-Posting-Host: marvin.enst.fr Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Trace: news.enst.fr 1179509749 1953 137.194.161.2 (18 May 2007 17:35:49 GMT) X-Complaints-To: usenet@enst.fr NNTP-Posting-Date: Fri, 18 May 2007 17:35:49 +0000 (UTC) Cc: Randy Brukardt To: comp.lang.ada@ada-france.org Return-Path: User-Agent: KMail/1.9.6 In-Reply-To: Content-Disposition: inline X-Virus-Scanned: amavisd-new at ada-france.org X-BeenThere: comp.lang.ada@ada-france.org X-Mailman-Version: 2.1.9rc1 Precedence: list List-Id: "Gateway to the comp.lang.ada Usenet newsgroup" List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , X-Leafnode-NNTP-Posting-Host: 88.191.17.134 Xref: g2news1.google.com comp.lang.ada:15838 Date: 2007-05-18T19:35:23+02:00 Hi Randy, > 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. while what you say is very logical, unfortunately it seems to be wrong: I checked and these functions are not being marked pure. So how come declaring a constant helps? I don't know - I didn't look into it yet. Ciao, Duncan.