They should only *need* to get stored if
1. They're live-across-call and there are no callee-save registers to park the values in.
2. They get spilled due to register pressure.
3. Their address gets taken.
4. Their storage class requires storing to memory (e.g. volatile).
And there could be other reasons where it *might* end up on the stack, such as:
5. The compiler isn't able to register allocate the type--this happens most often with
6. Compilation / debug model needs it on the stack.
7. Cost model for the architecture suggests register allocation for the variable isn't a win.
#1 above is actually pretty powerful. Texas Instruments' C6400 DSP architecture has 10
registers that are callee-save and the first 10 arguments of function calls are passed in
registers. The CPU has 64 registers total. All these work together to absorb and eliminate
quite a bit of stack traffic on that architecture.
I'm less familiar w/ GCC, the x86 and x86-64 ABIs and how they work, which prompted my