This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: gcc behavior re const optimization
- To: Vincent Penquerc'h <vincent at qubesoft dot com>
- Subject: Re: gcc behavior re const optimization
- From: "Andrew Morton" <morton at nortelnetworks dot com>
- Date: Mon, 13 Nov 2000 05:32:39 +0000
- CC: "Gcc at Gcc dot Gnu. Org" <gcc at gcc dot gnu dot org>
- Organization: Nortel Networks, Wollongong Australia
- References: <DOEPJBFJKJJJOCHIMOPIGEBDCMAA.vincent@calcaphon.com>
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....