This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug optimization/15184] New: Direct access to byte inside word not working with -march=pentiumpro
- From: "cesarb at nitnet dot com dot br" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: 27 Apr 2004 23:38:30 -0000
- Subject: [Bug optimization/15184] New: Direct access to byte inside word not working with -march=pentiumpro
- Reply-to: gcc-bugzilla at gcc dot gnu dot org
When compiling:
// gcc -Wall -std=c99 -O3 -ffast-math -fomit-frame-pointer -march=pentiumpro
// Works: gcc -Wall -std=c99 -O3 -ffast-math -fomit-frame-pointer -march=i486
#define regparm __attribute__((__regparm__(3)))
extern unsigned int x;
extern unsigned short y;
void regparm fl(unsigned char c)
{
x = (x & 0xFFFFFF00) | (unsigned int)c;
}
void regparm fu(unsigned char c)
{
x = (x & 0xFFFF00FF) | ((unsigned int)c << 8);
}
void regparm gl(unsigned char c)
{
y = (y & 0xFF00) | (unsigned short)c;
}
void regparm gu(unsigned char c)
{
y = (y & 0x00FF) | ((unsigned short)c << 8);
}
With:
gcc -Wall -std=c99 -O3 -ffast-math -fomit-frame-pointer -march=pentiumpro
The result is:
.file "testcase.c"
.text
.align 4
.p2align 4,,15
.globl fl
.type fl, @function
fl:
movb %al, x
ret
.size fl, .-fl
.p2align 4,,15
.globl fu
.type fu, @function
fu:
movb %al, x+1
ret
.size fu, .-fu
.p2align 4,,15
.globl gl
.type gl, @function
gl:
movb %al, %dl
movzwl y, %eax
movzbw %dl, %dx
andl $-256, %eax
orl %edx, %eax
movw %ax, y
ret
.size gl, .-gl
.p2align 4,,15
.globl gu
.type gu, @function
gu:
movzbl y, %edx
sall $8, %eax
orl %eax, %edx
movw %dx, y
ret
.size gu, .-gu
.ident "GCC: (GNU) 3.5.0 20040425 (experimental)"
.section .note.GNU-stack,"",@progbits
Notice that the optimization to directly change the byte inside the word
does not work with unsigned short (it uses a lot of instructions instead
of a simple "movb %al, y+1". Is it just me or some of them are
redundant? Like moving from al to dl and then zero extending to dx
instead of doing it at once?).
The problem seems to happen only with -march=pentiumpro. Here is the
result with i486 or athlon:
.file "testcase.c"
.text
.align 4
.p2align 4,,15
.globl fl
.type fl, @function
fl:
movb %al, x
ret
.size fl, .-fl
.p2align 4,,15
.globl fu
.type fu, @function
fu:
movb %al, x+1
ret
.size fu, .-fu
.p2align 4,,15
.globl gl
.type gl, @function
gl:
movb %al, y
ret
.size gl, .-gl
.p2align 4,,15
.globl gu
.type gu, @function
gu:
movb %al, y+1
ret
.size gu, .-gu
.ident "GCC: (GNU) 3.5.0 20040425 (experimental)"
.section .note.GNU-stack,"",@progbits
Which is exactly the expected result.
Even if a Pentium PRO is slower with words, the optimization uses byte
accesses (exactly the same thing it did with longs, even on pentiumpro),
so it should be used even on pentiumpro.
Reading specs from /usr/lib/gcc-snapshot/lib/gcc/i486-linux/3.5.0/specs
Configured with: ../src/configure -v --enable-languages=c,c++,java,f77,objc,treelang --prefix=/usr/lib/gcc-snapshot --enable-shared --with-system-zlib --enable-nls --enable-threads=posix --without-included-gettext --disable-werror --enable-__cxa_atexit --enable-clocale=gnu --enable-libstdcxx-debug --enable-java-gc=boehm --enable-java-awt=gtk i486-linux
Thread model: posix
gcc version 3.5.0 20040425 (experimental)
--
Summary: Direct access to byte inside word not working with -
march=pentiumpro
Product: gcc
Version: 3.5.0
Status: UNCONFIRMED
Severity: normal
Priority: P2
Component: optimization
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: cesarb at nitnet dot com dot br
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15184