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: Jeffrey A Law <law at cygnus dot com>
- Date: Fri, 11 Feb 2000 16:05:30 -0700
- cc: "'dvv at egcs dot dvv dot ru'" <dvv at egcs dot dvv dot ru>, "'gcc at gcc dot gnu dot org'" <gcc at gcc dot gnu dot org>
- Reply-To: law at cygnus dot com
In message <2473C7ACA21ED211854F08002BB768C40551D066@OZ>you write:
> Good point about the optimization suggested! I was talking about the best
> optimization, i. e. transform the program to:
>
> printf("882236160\n");
>
> on the i686, and appropriately on other platforms.
>
> Is it correct to summarize that if there are no function calls between
> repeated references to a non-volatile global variable, then it can be
> optimized to work as well as a local variable. Otherwise, global variables
> require extra instructions for access?
No, that is not a safe assumption.
For example, local variables are subject to register allocation (ie, they
can be easily held in a register). The same is not generally true for globals,
so they often end up in memory.
jeff