Article View: gnu.gcc.bug
Article #6303Re: Poor loop optimization - 2.7.2 (long)
From: Rusty, Paul , Russell
Date: Tue, 12 Dec 1995 00:00
Date: Tue, 12 Dec 1995 00:00
44 lines
2221 bytes
2221 bytes
In message <9512120442.AA00637@fafnir.fafnir.com> you write:
> gcc version 2.7.2
> NeXT 68040 Cube, NeXTSTEP 3.3 with patch 1
>
> 1) gcc often fails to move function calls out of a loop, even when
> they are declared "const"
> I hope I have done something stupid here; I was counting on GCC's
> loop optimization.
Yep, you were 8-); your code declared the return value const, not the
function. Please feast upon the following GNU extention (from the GNU
info pages):
`const'
Many functions do not examine any values except their arguments,
and have no effects except the return value. Such a function can
be subject to common subexpression elimination and loop
optimization just as an arithmetic operator would be. These
functions should be declared with the attribute `const'. For
example,
int square (int) __attribute__ ((const));
says that the hypothetical function `square' is safe to call fewer
times than the program says.
The attribute `const' is not implemented in GNU C versions earlier
than 2.5. An alternative way to declare that a function has no
side effects, which works in the current version and in some older
versions, is as follows:
typedef int intfn ();
extern const intfn square;
This approach does not work in GNU C++ from 2.6.0 on, since the
language specifies that the `const' must be attached to the return
value.
Hope this helps,
Rusty.
--
Rusty.Russell@adelaide.maptek.com.au "Engineer? So you drive trains?"
Lies, damned lies, and out-of-date documentation. #include <stddisclm.h>
Technical Details
Message-ID:
<199512120550.QAA02834@gauss.adelaide.maptek.com.au>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<9512120442.AA00637@fafnir.fafnir.com>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit X-Google-Thread: 113d02,4725038155a86b4d,start X-Google-Attributes: gid113d02,public From: Rusty.Russell@adelaide.maptek.com.au (Rusty, Paul , Russell) Subject: Re: Poor loop optimization - 2.7.2 (long) Date: 1995/12/12 Message-ID: <199512120550.QAA02834@gauss.adelaide.maptek.com.au> X-Deja-AN: 122048548 distribution: gnu sender: daemon@cis.ohio-state.edu references: <9512120442.AA00637@fafnir.fafnir.com> organization: GNUs Not Usenet newsgroups: gnu.gcc.bug