This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Using `const int' values to size stack arrays
Daniel Towner wrote:
Absolutely. My port of gcc generates code which initialises a memory
variable with the value 12, and then in the body of the code which
handles the variable length array, loads that value into a register, and
does all the appropriate arithmetic on it (some example code is shown
below). Can the code not be optimised at the instruction level, so that
it would recognise that the memory value will always be 12, so the load
from memory will always be 12, and hence copy propogation could remove
large chunks of code?
The main requirement for such an optimisation seems to be whether the
optimiser can recognise that the load from memory will always be a
constant value. If the original symbol was declared as `const int', or
`static const int', and that int is written to memory, can its value
ever be different to 12? I think that it is allowed to change if the
variable was marked as volatile, but in the other cases I would have
thought it could have been optimised?
This is certainly a possible optimization, but a bit of a marginal one,
since it only comes into play with a GNU C extension that we know is
very little used.