This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Global variables are slower?
- To: Anjul Srivastava <anjul dot srivastava at sanchez dot com>
- Subject: Re: Global variables are slower?
- From: dvv at egcs dot dvv dot ru (Dima Volodin)
- Date: Fri, 11 Feb 2000 22:53:06 GMT
- Cc: "'gcc at gcc dot gnu dot org'" <gcc at gcc dot gnu dot org>
- Organization: Huh?
- References: <2473C7ACA21ED211854F08002BB768C40551D062@OZ>
On Fri, 11 Feb 2000 17:40:14 -0500, you wrote:
>Thank you for your prompt responses Dima and Jeffrey.
>
>Apparently the extra instruction(s) cannot optimized out on i686. This is
>the simple overhead, in addition to the slowdown because the compiler cannot
>optimize the cases listed by Jeffrey (dead assignment removal, etc.)
>
>The program is (yes, I should have used volatile, but I am sure that gcc
>cannot optimize this case to the extent a human can):
>
>#include <stdio.h>
>
>int i; int main() { int a,j; a=0;
>for(j=0;j<1000;j++) for(i=0;i<1000000;i++) a+=i;
>printf("%d\n",a); return 0; }
In your example a compiler can deduce that i doesn't have to be updated
in memory until at least the call to printf(). The version of gcc I'm
using (2.95.2) doesn't do it, but it doesn't mean that compilers cannot
do it at all. This kind of optimization may or may not appear in future
versions of gcc depending on how important the gcc developers think this
kind of optimization is.
Dima