<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 - Use cmp+sbb instead of test+set for select of constants"
href="https://bugs.llvm.org/show_bug.cgi?id=43671">43671</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Use cmp+sbb instead of test+set for select of constants
</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>Motivation cases:
int foo(unsigned a) {
return a ? -1 : 1;
}
unsigned foo(unsigned a) {
return a ? 10 : 8;
}
Seems like, for some cases x ? A : B the GCC's code:
foo(unsigned int):
cmp edi, 1
sbb eax, eax
and eax, -2
add eax, 10
ret
Block RThroughput: 1.2
is better than Clang trunk's:
foo(unsigned int):
xor eax, eax
test edi, edi
setne al
add eax, eax
add eax, 8
ret
Block RThroughput: 1.3
I dont know the generalized rule here, but it seems like cmp+sbb is better when
A - B (or B - A) is 2, but also cmp+sbb is better in this case:
int foo(unsigned a) {
return a ? -1 : -9;
}
If we ignore cases when A or B is 0/1 (some other transformation kicks in;
codegen is good), it seems like cmp+sbb codegen is never worse than current
test+set+add codegen.
Current codegen: <a href="https://godbolt.org/z/GSa0wc">https://godbolt.org/z/GSa0wc</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>