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: missed optimization, would be very helpful


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)
>.L5:
>	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
difference).

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?

zw


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