This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
working around "QImode can alias everything" missed optimizations
- To: gcc at gcc dot gnu dot org
- Subject: working around "QImode can alias everything" missed optimizations
- From: Doug Evans <dje at transmeta dot com>
- Date: Fri, 26 May 2000 15:43:55 -0700
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);
}