<html>
<head>
<base href="https://bugs.llvm.org/">
</head>
<body><table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Bug ID</th>
<td><a class="bz_bug_link
bz_status_NEW "
title="NEW - Suboptimal __builtin_parity/popcount codegen for generic x86"
href="https://bugs.llvm.org/show_bug.cgi?id=46954">46954</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Suboptimal __builtin_parity/popcount codegen for generic x86
</td>
</tr>
<tr>
<th>Product</th>
<td>libraries
</td>
</tr>
<tr>
<th>Version</th>
<td>trunk
</td>
</tr>
<tr>
<th>Hardware</th>
<td>PC
</td>
</tr>
<tr>
<th>OS</th>
<td>Linux
</td>
</tr>
<tr>
<th>Status</th>
<td>NEW
</td>
</tr>
<tr>
<th>Severity</th>
<td>enhancement
</td>
</tr>
<tr>
<th>Priority</th>
<td>P
</td>
</tr>
<tr>
<th>Component</th>
<td>Backend: X86
</td>
</tr>
<tr>
<th>Assignee</th>
<td>unassignedbugs@nondot.org
</td>
</tr>
<tr>
<th>Reporter</th>
<td>david.bolvansky@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>craig.topper@gmail.com, llvm-bugs@lists.llvm.org, llvm-dev@redking.me.uk, spatel+llvm@rotateright.com
</td>
</tr></table>
<p>
<div>
<pre>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: <a href="https://godbolt.org/z/G9zbGr">https://godbolt.org/z/G9zbGr</a></pre>
</div>
</p>
<hr>
<span>You are receiving this mail because:</span>
<ul>
<li>You are on the CC list for the bug.</li>
</ul>
</body>
</html>