This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: Patch to detect constant functions.
- To: John Wehle <john at feith dot com>
- Subject: Re: Patch to detect constant functions.
- From: Toon Moene <toon at moene dot indiv dot nluug dot nl>
- Date: Wed, 18 Aug 1999 21:53:08 +0200
- CC: gcc-patches at gcc dot gnu dot org, craig at jcb-sc dot com
- Organization: Moene Computational Physics, Maartensdijk, The Netherlands
- References: <199908180457.AAA13885@jwlab.FEITH.COM>
[ cc'd to Craig ]
John Wehle wrote:
> This patch allows gcc to detect and mark functions as constant by using
> the information from the alias analysis to determine if the function
> references memory which isn't local. Knowing that a function is constant
> can help cse and loop. For example using -O2 on a x86 platform to compile:
> int
> subr(int a, int b, int c)
> {
>
> if (! c )
> return subr(a, b, 1);
>
> return a + b / c;
> }
>
> int
> func(int a, int b, int c)
> {
>
> return subr(a, b, c) + subr(a, b, c);
> }
>
Interesting - In Fortran this is *always* possible, because it is not
allowed to depend on side effects of part of an expression (see e.g. the
following interpretation w.r.t. to the FORTRAN 77 Standard:
http://www.fortran.com/fortran/F77_std/sideff.jpg; for the Standard
itself see: http://www.fortran.com/fortran/F77_std/rjcnf.html).
Indeed, the Fortran Frontend contains the following tantalizing comment
in f/com.c (finish_function):
/* TREE_READONLY (fndecl) = 1;
This caused &foo to be of type ptr-to-const-function
which then got a warning when stored in a ptr-to-function variable.
*/
Apparently, this is not used at the moment - Craig, how old is this
comment ? Is it still applicable ?
Another interesting "project" would be to "constify" Fortran intrinsics
- I lost track in f/intrin.c finding out whether this already happens.
--
Toon Moene (toon@moene.indiv.nluug.nl)
Saturnushof 14, 3738 XG Maartensdijk, The Netherlands
Phone: +31 346 214290; Fax: +31 346 214286
GNU Fortran: http://world.std.com/~burley/g77.html