https://bugs.llvm.org/show_bug.cgi?id=46954
Bug ID: 46954
Summary: Suboptimal __builtin_parity/popcount codegen for
generic x86
Product: libraries
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: Backend: X86
Assignee: unassignedb...@nondot.org
Reporter: david.bolvan...@gmail.com
CC: craig.top...@gmail.com, llvm-bugs@lists.llvm.org,
llvm-...@redking.me.uk, spatel+l...@rotateright.com
unsigned int foo(unsigned int x, unsigned int y)
{
return __builtin_parity(x ^ y);
}
Clang
foo(unsigned int, unsigned int): # @foo(unsigned
int, unsigned int)
xor edi, esi
mov ecx, edi
shr ecx, 16
xor ecx, edi
mov edx, ecx
shr edx, 8
xor eax, eax
xor dl, cl
setnp al
ret
GCC:
foo(unsigned int, unsigned int):
mov eax, edi
xor eax, esi
mov edx, eax
shr edx, 16
xor eax, edx
xor al, ah
setnp al
movzx eax, al
ret
Eliminate extra shr?
*******************************************
unsigned int fooll(unsigned int x, unsigned int y)
{
return __builtin_parityll(x ^ y);
}
GCC produces same code.
Clang produces:
foo(unsigned int, unsigned int): # @foo(unsigned
int, unsigned int)
xor edi, esi
mov rax, rdi
shr rax
and eax, 1431655765
sub rdi, rax
movabs rax, 3689348814741910323
mov rcx, rdi
and rcx, rax
shr rdi, 2
and rdi, rax
add rdi, rcx
mov rax, rdi
shr rax, 4
add rax, rdi
movabs rcx, 76296276040158991
and rcx, rax
movabs rax, 72340172838076673
imul rax, rcx
shr rax, 56
and eax, 1
ret
unsigned long fooll(unsigned long x, unsigned long y)
{
return __builtin_parityll(x ^ y);
}
Codegene: https://godbolt.org/z/G9zbGr
--
You are receiving this mail because:
You are on the CC list for the bug.
_______________________________________________
llvm-bugs mailing list
llvm-bugs@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs