This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug target/62166] New: Poor code generation (x86-64)
- From: "adam at consulting dot net.nz" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Mon, 18 Aug 2014 01:57:13 +0000
- Subject: [Bug target/62166] New: Poor code generation (x86-64)
- Auto-submitted: auto-generated
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62166
Bug ID: 62166
Summary: Poor code generation (x86-64)
Product: gcc
Version: unknown
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: target
Assignee: unassigned at gcc dot gnu.org
Reporter: adam at consulting dot net.nz
$ gcc-snapshot.sh --version
gcc (Debian 20140814-1) 4.10.0 20140814 (experimental) [trunk revision 213954]
weird_code_gen.c:
#include <stdint.h>
typedef void (*f_t)(uint64_t rdi, uint64_t rsi, uint64_t rdx, uint64_t rcx);
void weird_code_gen(uint64_t rdi, uint64_t rsi, uint64_t rdx, uint64_t rcx);
f_t dispatch[] = {&weird_code_gen};
void weird_code_gen(uint64_t rdi, uint64_t rsi, uint64_t rdx, uint64_t rcx) {
int64_t s8 = (int8_t) rcx;
uint32_t u8 = (uint8_t) (rcx >> 8);
//asm volatile ("" : "+r" (rcx));
rdx += s8;
rcx >>= 16;
dispatch[u8](rdi, rsi, rdx, rcx);
}
int main(void) {
return 0;
}
$ gcc-snapshot.sh -O3 weird_code_gen.c && objdump -d -m i386:x86-64:intel a.out
|less
00000000004004c0 <weird_code_gen>:
4004c0: 48 89 c8 mov rax,rcx
4004c3: 53 push rbx
4004c4: 0f b6 dd movzx ebx,ch
4004c7: 48 0f be c0 movsx rax,al
4004cb: 48 c1 e9 10 shr rcx,0x10
4004cf: 48 01 c2 add rdx,rax
4004d2: 48 8b 04 dd d8 08 60 mov rax,QWORD PTR [rbx*8+0x6008d8]
4004d9: 00
4004da: 5b pop rbx
4004db: ff e0 jmp rax
Code generation with asm volatile uncommented:
00000000004004c0 <weird_code_gen>:
4004c0: 4c 0f be c1 movsx r8,cl
4004c4: 0f b6 c5 movzx eax,ch
4004c7: 89 c0 mov eax,eax
4004c9: 48 c1 e9 10 shr rcx,0x10
4004cd: 4c 01 c2 add rdx,r8
4004d0: ff 24 c5 d0 08 60 00 jmp QWORD PTR [rax*8+0x6008d0]
The asm volatile workaround fails if u8 is of type uint64_t.