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=-1.9 required=5.0 tests=BAYES_00 autolearn=ham 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!proxad.net!oleane.net!oleane!news.ecp.fr!news.jacob-sparre.dk!pnx.dk!not-for-mail From: "Randy Brukardt" Newsgroups: comp.lang.ada Subject: Re: GNAT Optimization of Constant Expressions Date: Fri, 18 May 2007 12:20:19 -0500 Organization: Jacob's private Usenet server Message-ID: References: <1179355028.624745.258370@q75g2000hsh.googlegroups.com> <87k5v631kp.fsf@mid.deneb.enyo.de> NNTP-Posting-Host: static-69-95-181-76.mad.choiceone.net X-Trace: jacob-sparre.dk 1179508698 11238 69.95.181.76 (18 May 2007 17:18:18 GMT) X-Complaints-To: news@jacob-sparre.dk NNTP-Posting-Date: Fri, 18 May 2007 17:18:18 +0000 (UTC) X-Priority: 3 X-MSMail-Priority: Normal X-Newsreader: Microsoft Outlook Express 6.00.2800.1807 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2800.1807 Xref: g2news1.google.com comp.lang.ada:15834 Date: 2007-05-18T12:20:19-05:00 List-Id: "Florian Weimer" 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.