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


Zack Weinberg <zack@rabi.columbia.edu> said:
> In a loop of the form
> 
> while (condition) (*int_ptr)++;
> 
> gcc generates a read-mod-write cycle to the memory location *int_ptr at each
> iteration of the loop.  Modern chips really don't like that; I got a ~30%
> speedup on one piece of code by rewriting it to bump a register and write
> the memory location at the end.  The pointer isn't volatile, so I believe
> there is nothing stopping gcc from doing this optimization.
> 
> This is egcs-1.1.1; it might've been fixed more recently but I can't test
> that since the Dec 24 CVS is unreliable on my system.

It's still there with egcs-19981226. On i586:

f(char *p, int *ip)
{ 
   while(*p++)
     (*ip)++;
}

gives:

	.file	"tst2.c"
	.version	"01.01"
gcc2_compiled.:
.text
	.align 4
.globl f
	.type	 f,@function
f:
	pushl %ebp
	movl %esp,%ebp
	movl 8(%ebp),%edx
	movl 12(%ebp),%ecx
	jmp .L7
	.p2align 4,,7
.L5:
	incl (%ecx)
.L7:
	movb (%edx),%al
	incl %edx
	testb %al,%al
	jne .L5
	movl %ebp,%esp
	popl %ebp
	ret
.Lfe1:
	.size	 f,.Lfe1-f
	.ident	"GCC: (GNU) egcs-2.92.33 19981226 (gcc2 ss-980609 experimental)"

Happy hacking in 1999!
-- 
Horst von Brand                             vonbrand@sleipnir.valparaiso.cl
Casilla 9G, Viņa del Mar, Chile                               +56 32 672616


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