missed optimization, would be very helpful

Zack Weinberg zack@rabi.columbia.edu
Sun Jan 31 23:58:00 GMT 1999

On Fri, 1 Jan 1999 04:24:36 +0100, 043633786-0001@t-online.de wrote:
>On Thu, Dec 31, 1998 at 11:03:25PM -0400, Horst von Brand wrote:
>> f(char *p, int *ip)
>> { 
>>    while(*p++)
>>      (*ip)++;
>> }
>Do you want this to become something like
>	movl (%ecx),%esi (well, take anything for %esi)
>	incl %esi
>	movb (%edx),%al
>	incl %edx
>	testb %al,%al
>	jne .L5
>	movl %esi,(%ecx)

That's the right general idea.

>What if you call your function like this

>	f((char *) a, a[17]);

The compiler is allowed to assume you didn't do that.  char * and int * have
different base types, therefore aren't allowed to be "aliased"
(standardese).  Optimizing based on that assumption is enabled by
-fstrict-aliasing, but I get identical code for Horst's sample function on
x86 with and without -fstrict-aliasing.  (1.1.1 or Dec 24 CVS, makes no

I suspect that the actual problem is that the x86 machine description
doesn't consider memory to be "worse" than a register for use in an incl
instruction.  Maybe someone who's been in there recently can comment?


More information about the Gcc mailing list