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=-0.9 required=5.0 tests=BAYES_00,FORGED_GMAIL_RCVD, FREEMAIL_FROM autolearn=no 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!postnews.google.com!l77g2000hsb.googlegroups.com!not-for-mail From: David Smith Newsgroups: comp.lang.ada Subject: Re: GNAT Optimization of Constant Expressions Date: 17 May 2007 15:49:13 -0700 Organization: http://groups.google.com Message-ID: <1179442153.169828.109970@l77g2000hsb.googlegroups.com> References: <1179355028.624745.258370@q75g2000hsh.googlegroups.com> <464cb4cd$1_3@news.bluewin.ch> NNTP-Posting-Host: 72.211.146.117 Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" X-Trace: posting.google.com 1179442153 30995 127.0.0.1 (17 May 2007 22:49:13 GMT) X-Complaints-To: groups-abuse@google.com NNTP-Posting-Date: Thu, 17 May 2007 22:49:13 +0000 (UTC) In-Reply-To: User-Agent: G2/1.0 X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.1.3) Gecko/20061201 Firefox/2.0.0.3 (Ubuntu-feisty),gzip(gfe),gzip(gfe) Complaints-To: groups-abuse@google.com Injection-Info: l77g2000hsb.googlegroups.com; posting-host=72.211.146.117; posting-account=hjwdNg0AAADrWbU8BVPocB6GQuDF5upL Xref: g2news1.google.com comp.lang.ada:15823 Date: 2007-05-17T15:49:13-07:00 List-Id: > > I agree for any function call, but in the special case of functions from > > Generic_Elementary_Functions, it is _not_ asking a lot! A decent compiler > > should perform optimizations around these functions as well as around > > arithmetic operators. The purpose in leaving them in was to test this aspect of the optimization process. This is a very common expression to see in legacy scientific codes written by novices, and I wanted to know if GNAT can handle naive structures as well as Fortran compilers do. If it can't, then many scientists and potential Ada converts will be turned off because they'll write a naive bit of code for a benchmark and find that Ada is much slower than Fortran without trying to understand why. I understand that the FP ops are not associative, but doesn't the gcc - O3 imply that the user chooses speed over accuracy? And especially if the user passes -ffast-math the compiler should get the hint. > There are optimizations that you can do safely, like common subexpression > evaluation, but there are many fewer of them than you have with integer > optimizations. Luckily, most of the code in a program (any program, once you > take address calculations like array indexing into account) is integer code. > It is very important to do a good job on integer expressions, much less > valuable of float ones (because of the limited things that you can do). This may be true, but FP ops are very expensive, so trimming those can potentially save more than you might think. In this example, the common expression elimination speeds the code up by a factor of 10, roughly. -Dave