<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 code for branch on ctpop(x) == 1"
href="https://bugs.llvm.org/show_bug.cgi?id=47906">47906</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Suboptimal code for branch on ctpop(x) == 1
</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>All
</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>craig.topper@gmail.com
</td>
</tr>
<tr>
<th>CC</th>
<td>craig.topper@gmail.com, llvm-bugs@lists.llvm.org, llvm-dev@redking.me.uk, pengfei.wang@intel.com, spatel+llvm@rotateright.com
</td>
</tr></table>
<p>
<div>
<pre>This code produces suboptimal code with clang
void bar();
void foo(int x) {
if (x && (x & (x - 1)) == 0)
bar();
}
clang:
foo(int): # @foo(int)
leal -1(%rdi), %eax
testl %eax, %edi
setne %al
testl %edi, %edi
sete %cl
orb %al, %cl
jne .LBB0_1
jmp bar() # TAILCALL
.LBB0_1:
retq
gcc:
foo(int):
test edi, edi
je .L1
lea eax, [rdi-1]
test eax, edi
je .L7
.L1:
ret
.L7:
jmp bar()
The condition is canonicalized to ctpop(x) == 1 in InstCombine. Then expanded
back into two conditionals during SelectionDAG. SelectionDAG doesn't have any
optimizations for changing a branch on 2 setccs ored together into separate
branches. I'm not sure if we could add that or if we should expand the ctpop in
CodeGenPrepare.</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>