Do not spill variables/registers on the stack
David Brown
david@westcontrol.com
Fri Feb 4 11:45:00 GMT 2011
On 03/02/2011 23:36, Drasko DRASKOVIC wrote:
> Back to the topic, few things crossed my mind :
>
> 1) Register keyword is a "hint" to the compiler, and thus not
> obligatory. We saw that for -O1 and above it is "useless hint", as it
> is always ignored. Is it however always respected by GCC when -O0 ? If
> yes - why is it a hint ? If no, in which cases it is not respected ?
> Only when you assign more vars than you have reg, or GCC might ignore
> it some other times even with -O0 ?
>
> 2) Is this behavior documented anywhere ? Can we find docs that note :
> a) that "regiser" keyword is not ignored only with -O0
> b) when -O0 in which cases it is taken into account and in which cases not.
>
<http://gcc.gnu.org/onlinedocs/gcc/Hints-implementation.html>
To quote:
4.8 Hints
* The extent to which suggestions made by using the register
storage-class specifier are effective (C90 6.5.1, C99 6.7.1).
The register specifier affects code generation only in these ways:
o When used as part of the register variable extension, see
Explicit Reg Vars.
o When -O0 is in use, the compiler allocates distinct stack
memory for all variables that do not have the register storage-class
specifier; if register is specified, the variable may have a shorter
lifespan than the code would indicate and may never be placed in memory.
o On some rare x86 targets, setjmp doesn't save the registers
in all circumstances. In those cases, GCC doesn't allocate any variables
in registers unless they are marked register.
More information about the Gcc-help
mailing list