This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: missed optimization, would be very helpful
- To: Philipp Rumpf <prumpf at jcsbs dot lanobis dot de>
- Subject: Re: missed optimization, would be very helpful
- From: Zack Weinberg <zack at rabi dot columbia dot edu>
- Date: Sun, 03 Jan 1999 20:52:27 -0500
- cc: egcs at egcs dot cygnus dot com
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