gcc behavior re const optimization
Andrew Morton
morton@nortelnetworks.com
Sun Nov 12 21:35:00 GMT 2000
Vincent Penquerc'h wrote:
>
> I tried reposting this many times, as our provider was listed on ORBS:
>
> > > I just subscribed to this list. I would like to know if this is the
> > > right place to ask for specific optimizations performed by gcc.
>
> [...]
>
> > Should be the right place,
> > just make direct questions.
>
> Well, I've been up to now writing code without using const. I always
> thought I'd start using it when optimizers would make good use of it
> (I won't argue whether this is a good or bad reason to switch :))
I've seen a few instances where constness helped code generation:
foo()
{
const int some_var = 0;
...
if (some_var) {
/* this code is totally removed iff const */
}
...
use(some_array[some_var]); /* skips subscripting iff const */
}
and
foo(const char *cp)
{
const thing *thingp = (const thing *)cp;
/* From now on, the same register is used for both cp and
* thingp iff both are const.
*/
}
Obviously, all this is rather dependent upon compiler version....
More information about the Gcc
mailing list