[LLVMbugs] [Bug 14366] New: Poor code generation for a simple inline assembly
bugzilla-daemon at llvm.org
bugzilla-daemon at llvm.org
Fri Nov 16 12:39:31 PST 2012
http://llvm.org/bugs/show_bug.cgi?id=14366
Bug #: 14366
Summary: Poor code generation for a simple inline assembly
Product: libraries
Version: trunk
Platform: PC
OS/Version: FreeBSD
Status: NEW
Severity: enhancement
Priority: P
Component: Common Code Generator Code
AssignedTo: unassignedbugs at nondot.org
ReportedBy: jkim at FreeBSD.org
CC: llvmbugs at cs.uiuc.edu
Classification: Unclassified
Consider this:
% cat test.c
static __inline unsigned long
bsfq(unsigned long x)
{
unsigned long r;
__asm __volatile("bsfq %1,%0" : "=r" (r) : "rm" (x));
return (r);
}
int
ffsl(long x)
{
return (x == 0 ? x : (int)bsfq((unsigned long)x) + 1);
}
Clang generates really poor code:
% clang -O2 -c test.c
% objdump -d test.o
test.o: file format elf64-x86-64-freebsd
Disassembly of section .text:
0000000000000000 <ffsl>:
0: 48 85 ff test %rdi,%rdi
3: 74 21 je 26 <ffsl+0x26>
5: 48 89 7c 24 f8 mov %rdi,-0x8(%rsp)
a: 48 0f bc 4c 24 f8 bsf -0x8(%rsp),%rcx
10: 48 c1 e1 20 shl $0x20,%rcx
14: 48 b8 00 00 00 00 01 mov $0x100000000,%rax
1b: 00 00 00
1e: 48 01 c8 add %rcx,%rax
21: 48 c1 e8 20 shr $0x20,%rax
25: c3 retq
26: 31 c0 xor %eax,%eax
28: c3 retq
Of course, GCC 4.2 does much better job. ;-)
% gcc -O2 -c test.c
% objdump -d test.o
test.o: file format elf64-x86-64-freebsd
Disassembly of section .text:
0000000000000000 <ffsl>:
0: 31 c0 xor %eax,%eax
2: 48 85 ff test %rdi,%rdi
5: 74 07 je e <ffsl+0xe>
7: 48 0f bc c7 bsf %rdi,%rax
b: 83 c0 01 add $0x1,%eax
e: f3 c3 repz retq
FYI, this problem was discussed here (warning: little lengthy):
http://docs.freebsd.org/cgi/mid.cgi?20121116181327.B1135
--
Configure bugmail: http://llvm.org/bugs/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are on the CC list for the bug.
More information about the llvm-bugs
mailing list