See below: two register->register moves which are not needed. # cat byteorder.c typedef unsigned long long u64; typedef unsigned u32;
static inline u64 swab64(u64 val) { union { struct { u32 a,b; } s; u64 u; } v; v.u = val; asm("bswapl %0 ; bswapl %1" : "=r" (v.s.b), "=r" (v.s.a) : "0" (v.s.a), "1" (v.s.b)); return v.u; } extern u64 w; void f() { w = swab64(w); } # gcc -O3 byteorder.c -S # cat byteorder.s .file "byteorder.c" .text .p2align 2,,3 .globl f .type f, @function f: pushl %ebp movl %esp, %ebp pushl %esi pushl %ebx movl w, %esi movl w+4, %edx movl %esi, %ebx movl %edx, %esi #APP bswapl %ebx ; bswapl %esi #NO_APP movl %ebx, w+4 popl %ebx movl %esi, w popl %esi leave ret .size f, .-f .section .note.GNU-stack,"",@progbits .ident "GCC: (GNU) 3.4.3" # gcc -O3 byteorder.c -S; cat byteorder.s; gcc -v .file "byteorder.c" .text .p2align 2,,3 .globl f .type f, @function f: pushl %ebp movl %esp, %ebp pushl %esi pushl %ebx movl w, %eax movl w+4, %edx movl %eax, %ebx movl %edx, %esi #APP bswapl %ebx ; bswapl %esi #NO_APP movl %esi, w movl %ebx, w+4 popl %ebx popl %esi leave ret .size f, .-f .ident "GCC: (GNU) 4.0.0" .section .note.GNU-stack,"",@progbits Using built-in specs. Target: i386-pc-linux-gnu Configured with: ../gcc-4.0.0.src/configure --prefix=/usr/app/gcc-4.0.0 --exec-prefix=/usr/app/gcc-4.0.0 --bindir=/usr/bin --sbindir=/usr/sbin --libexecdir=/usr/app/gcc-4.0.0/libexec --datadir=/usr/app/gcc-4.0.0/share --sysconfdir=/etc --sharedstatedir=/usr/app/gcc-4.0.0/var/com --localstatedir=/usr/app/gcc-4.0.0/var --libdir=/usr/lib --includedir=/usr/include --infodir=/usr/info --mandir=/usr/man --with-slibdir=/usr/app/gcc-4.0.0/lib --with-local-prefix=/usr/local --with-gxx-include-dir=/usr/app/gcc-4.0.0/include/g++-v3 --enable-languages=c,c++ --with-system-zlib --disable-nls --enable-threads=posix i386-pc-linux-gnu Thread model: posix gcc version 4.0.0 -- Summary: Extra register moves generated Product: gcc Version: 4.0.0 Status: UNCONFIRMED Severity: normal Priority: P2 Component: rtl-optimization AssignedTo: unassigned at gcc dot gnu dot org ReportedBy: vda at port dot imtp dot ilyichevsk dot odessa dot ua CC: gcc-bugs at gcc dot gnu dot org GCC build triplet: i386-pc-linux-gnu GCC host triplet: i386-pc-linux-gnu GCC target triplet: i386-pc-linux-gnu http://gcc.gnu.org/bugzilla/show_bug.cgi?id=21202