public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug rtl-optimization/15556] New: Idiom for "xchg %ah,%al" not recognized
@ 2004-05-21 19:22 cesarb at nitnet dot com dot br
2004-05-21 19:29 ` [Bug target/15556] " pinskia at gcc dot gnu dot org
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: cesarb at nitnet dot com dot br @ 2004-05-21 19:22 UTC (permalink / raw)
To: gcc-bugs
When compiling:
#define regparm __attribute__((regparm(3)))
unsigned short regparm a(unsigned short x) { return (x << 8) | (x >> 8); }
unsigned short regparm b(unsigned short x) { return (x >> 8) | (x << 8); }
With:
gcc -W -Wall -O3 -ffast-math -fomit-frame-pointer -fexpensive-optimizations
-save-temps -march=athlon -c
The result is:
.file "testcase.c"
.text
.align 4
.p2align 4,,15
.globl a
.type a, @function
a:
movzwl %ax, %edx
shrw $8, %ax
sall $8, %edx
orl %edx, %eax
movzwl %ax, %eax
ret
.size a, .-a
.p2align 4,,15
.globl b
.type b, @function
b:
movl %eax, %edx
movzwl %ax, %eax
sall $8, %eax
shrw $8, %dx
orl %eax, %edx
movzwl %dx, %eax
ret
.size b, .-b
.ident "GCC: (GNU) 3.5.0 20040512 (experimental)"
.section .note.GNU-stack,"",@progbits
What I expected for both a and b is:
xchg %ah, %al
ret
or maybe:
xchg %al, %ah
ret
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,ada,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 20040512 (experimental)
--
Summary: Idiom for "xchg %ah,%al" not recognized
Product: gcc
Version: 3.5.0
Status: UNCONFIRMED
Severity: enhancement
Priority: P2
Component: rtl-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
GCC build triplet: i686-pc-linux-gnu
GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15556
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug target/15556] Idiom for "xchg %ah,%al" not recognized
2004-05-21 19:22 [Bug rtl-optimization/15556] New: Idiom for "xchg %ah,%al" not recognized cesarb at nitnet dot com dot br
@ 2004-05-21 19:29 ` pinskia at gcc dot gnu dot org
2004-05-22 3:02 ` giovannibajo at libero dot it
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-05-21 19:29 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-05-20 19:36 -------
Confirmed.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |NEW
Component|rtl-optimization |target
Ever Confirmed| |1
Keywords| |missed-optimization
Last reconfirmed|0000-00-00 00:00:00 |2004-05-20 19:36:08
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15556
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug target/15556] Idiom for "xchg %ah,%al" not recognized
2004-05-21 19:22 [Bug rtl-optimization/15556] New: Idiom for "xchg %ah,%al" not recognized cesarb at nitnet dot com dot br
2004-05-21 19:29 ` [Bug target/15556] " pinskia at gcc dot gnu dot org
@ 2004-05-22 3:02 ` giovannibajo at libero dot it
2004-05-22 3:07 ` [Bug tree-optimization/15556] Idiom for rotations of 16bit values " pinskia at gcc dot gnu dot org
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: giovannibajo at libero dot it @ 2004-05-22 3:02 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From giovannibajo at libero dot it 2004-05-21 01:05 -------
Notice that if you use 32bit words, it works:
------------------------------------------------------------------
#define regparm __attribute__((regparm(3)))
unsigned regparm a(unsigned x) { return (x << 24) | (x >> 8); }
unsigned regparm b(unsigned x) { return (x >> 24) | (x << 8); }
------------------------------------------------------------------
_Z1aj:
.LFB2:
rorl $8, %eax
ret
_Z1bj:
.LFB3:
rorl $24, %eax
ret
Since the optimization is done in fold-const (look for "bit_rotate"), maybe the
bug is there, rather than in target-specific code.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15556
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug tree-optimization/15556] Idiom for rotations of 16bit values not recognized
2004-05-21 19:22 [Bug rtl-optimization/15556] New: Idiom for "xchg %ah,%al" not recognized cesarb at nitnet dot com dot br
2004-05-21 19:29 ` [Bug target/15556] " pinskia at gcc dot gnu dot org
2004-05-22 3:02 ` giovannibajo at libero dot it
@ 2004-05-22 3:07 ` pinskia at gcc dot gnu dot org
2004-07-23 2:41 ` bernie at develer dot com
2004-10-22 0:32 ` pinskia at gcc dot gnu dot org
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-05-22 3:07 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-05-21 01:50 -------
Confirmed this should be done on the tree level. Note the pretty-print for the tree dump does not
dump right: " return x <<< ??? >>> 24;"
--
What |Removed |Added
----------------------------------------------------------------------------
Component|target |tree-optimization
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15556
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug tree-optimization/15556] Idiom for rotations of 16bit values not recognized
2004-05-21 19:22 [Bug rtl-optimization/15556] New: Idiom for "xchg %ah,%al" not recognized cesarb at nitnet dot com dot br
` (2 preceding siblings ...)
2004-05-22 3:07 ` [Bug tree-optimization/15556] Idiom for rotations of 16bit values " pinskia at gcc dot gnu dot org
@ 2004-07-23 2:41 ` bernie at develer dot com
2004-10-22 0:32 ` pinskia at gcc dot gnu dot org
4 siblings, 0 replies; 6+ messages in thread
From: bernie at develer dot com @ 2004-07-23 2:41 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From bernie at develer dot com 2004-07-23 02:41 -------
The commonly used byte-swapping idiom also produces
sub-optimal code (GCC 3.4.1 on x86):
unsigned short swab16(unsigned short x)
{
return (x >> 8) | (x << 8);
}
swab16:
movzwl 4(%esp), %edx
movl %edx, %eax
shrw $8, %ax
sall $8, %edx
orl %edx, %eax
movzwl %ax, %eax
ret
Assing a few useless masks helps GCC produce
somewhat better code:
unsigned short swab16(unsigned short x)
{
return ((x >> 8) & 0x00FF) | ((x << 8) & 0xFF00);
}
swab16:
movl 4(%esp), %eax
rolw $8, %ax
movzwl %ax, %eax
ret
A single xchg instruction would suffice on x86.
Both the Linux kernel and glibc are using inline
asm to workaround this missing optimization.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15556
^ permalink raw reply [flat|nested] 6+ messages in thread
* [Bug tree-optimization/15556] Idiom for rotations of 16bit values not recognized
2004-05-21 19:22 [Bug rtl-optimization/15556] New: Idiom for "xchg %ah,%al" not recognized cesarb at nitnet dot com dot br
` (3 preceding siblings ...)
2004-07-23 2:41 ` bernie at develer dot com
@ 2004-10-22 0:32 ` pinskia at gcc dot gnu dot org
4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2004-10-22 0:32 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2004-10-22 00:32 -------
These are all fixed on the mainline:
The first two examples:
a:
rolw $8, %ax
movzwl %ax, %eax
ret
.size a, .-a
.p2align 4,,15
.globl b
.type b, @function
b:
rolw $8, %ax
movzwl %ax, %eax
ret
For swab16:
swab16:
movl 4(%esp), %eax
rolw $8, %ax
movzwl %ax, %eax
ret
--
What |Removed |Added
----------------------------------------------------------------------------
Status|NEW |RESOLVED
Resolution| |FIXED
Target Milestone|--- |4.0.0
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=15556
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2004-10-22 0:32 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2004-05-21 19:22 [Bug rtl-optimization/15556] New: Idiom for "xchg %ah,%al" not recognized cesarb at nitnet dot com dot br
2004-05-21 19:29 ` [Bug target/15556] " pinskia at gcc dot gnu dot org
2004-05-22 3:02 ` giovannibajo at libero dot it
2004-05-22 3:07 ` [Bug tree-optimization/15556] Idiom for rotations of 16bit values " pinskia at gcc dot gnu dot org
2004-07-23 2:41 ` bernie at develer dot com
2004-10-22 0:32 ` pinskia at gcc dot gnu dot org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).