[PATCH] Optimize strlen/strcmp/strncmp/strncpy/fputs on ?: or comma expressions

Jakub Jelinek jakub@redhat.com
Tue Jun 24 06:38:00 GMT 2003


On Mon, Jun 23, 2003 at 03:43:20PM -0700, Aaron Lehmann wrote:
> On Mon, Jun 23, 2003 at 03:19:16PM +0200, Jakub Jelinek wrote:
> > Hi!
> > 
> > This is something I've noticed in Roger's sample code.
> > j = strlen (i++ ? "foo" : "bar");
> > can be optimized into
> > i++; j = 3;
> > and similarly other functions.
> 
> How many times does this optimization trigger during a bootstrap?

In --enable-languages=c,c++,java,objc,f77 bootstrap it was optimized
21 times. I expect more in the future, since e.g. sprintf might use
this function as well and there are several cases where this occurs.

> Does anybody actually write code like that?

Maybe not that often with side-effects in controlling expression,
but certainly a conditional expression occurs quite often in strcpy
and other functions. But I'm quite certain I can dig up examples
of side-effects in controlling expression as well, it would just take
more time (ie. a distro build world).

	Jakub



More information about the Gcc-patches mailing list