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]

Suboptimal code (gcc 2.95.1, i386-unknown-openbsd)


Fiddling with optimization...

#define VAL 10
void f(char *s)
	{
	char *u = s;

	while (u < s+VAL)
		*u++='a';
	}


Using -O3, I get:

	.file	"a.c"
gcc2_compiled.:
___gnu_compiled_c:
.text
	.align 2,0x90
.globl _f
	.type	_f , @function
_f:
	pushl %ebp
	movl %esp,%ebp
	movl 8(%ebp),%eax
	leal 10(%eax),%edx
	cmpl %edx,%eax
	jae L4
	.align 2,0x90
L5:
	movb $97,(%eax)
	incl %eax
	cmpl %edx,%eax
	jb L5
L4:
	leave
	ret
	.size	_f , . - _f

Notice the comparison and jump to L4 that will never occur.

Is gcc required to assume that pointer arithmetic may wrap around,
or is it just some optimization it misses ?

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