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!news2.google.com!news.glorb.com!news2.arglkargh.de!news.n-ix.net!news.belwue.de!LF.net!news.enyo.de!not-for-mail From: Florian Weimer Newsgroups: comp.lang.ada Subject: Re: GNAT Optimization of Constant Expressions Date: Fri, 18 May 2007 11:47:50 +0200 Message-ID: <87k5v631kp.fsf@mid.deneb.enyo.de> References: <1179355028.624745.258370@q75g2000hsh.googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii X-Trace: idssi.enyo.de 1179481670 24675 212.9.189.177 (18 May 2007 09:47:50 GMT) X-Complaints-To: Cancel-Lock: sha1:2QT8jCtIZirpadKrgeP/azBTANs= Xref: g2news1.google.com comp.lang.ada:15827 Date: 2007-05-18T11:47:50+02:00 List-Id: * Randy Brukardt: > As such, the compiler has to do a loop-hoisting optimization in order to > pre-evaluate these function calls. I suspect that from your results, Gnat > doesn't do such an optimization in this case. That doesn't surprise me, a > loop hoist can make the program run slower if the loop is never executed. Not really. I suppose GCC special-cases the zero times case anyway because it transforms the loop into a do-while-style loop, which is easier to optimize. 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.