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]

working around "QImode can alias everything" missed optimizations


version: current cvs sources as of around noon today
target: i386-linux

If you make `buf' in this program a short*, gcc -O2 -fomit-frame-pointer
optimizes `foo' just fine.  If `buf' is a char*, gcc does poorly
(I'm guessing because it can't know that buf may point to itself
and QImode values are allowed to alias anything).

So how do I work around this?
How do I rewrite this code so that I get something like the following?

foo:
	movl	4(%esp), %edx
	movl	(%edx), %eax
	movw	$1, (%eax)
	movw	$2, 1(%eax)
	movw	$3, 2(%eax)
	addl	$3, %eax
	movl	%eax, (%edx)
	ret

typedef struct {
    char* buf;
} tc_t;

static inline void
emit_1 (tc_t* tc, int c)
{
    *tc->buf = c;
    ++tc->buf;
}

void
foo (tc_t* p)
{
    emit_1 (p, 1);
    emit_1 (p, 2);
    emit_1 (p, 3);
}

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