This is the mail archive of the gcc@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]

Re: gcc behavior re const optimization


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....

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]