<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 - [X86] Missed optimizations for comparison of shift against zero"
href="https://bugs.llvm.org/show_bug.cgi?id=33879">33879</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>[X86] Missed optimizations for comparison of shift against zero
</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>Windows NT
</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>llvm-dev@redking.me.uk
</td>
</tr>
<tr>
<th>CC</th>
<td>craig.topper@gmail.com, llvm-bugs@lists.llvm.org, peter@cordes.ca, spatel+llvm@rotateright.com
</td>
</tr></table>
<p>
<div>
<pre>int test(unsigned i, unsigned j, int a, int b) {
if (0 == (i >> j))
return a;
return b;
}
define i32 @test(i32, i32, i32, i32) {
%5 = lshr i32 %0, %1
%6 = icmp eq i32 %5, 0
%7 = select i1 %6, i32 %2, i32 %3
ret i32 %7
}
llc -mcpu=btver2
test(unsigned int, unsigned int, int, int):
movl %ecx, %eax
movl %esi, %ecx
shrl %cl, %edi
testl %edi, %edi
cmovnel %eax, %edx
movl %edx, %eax
retq
1 - we could remove the final move if the CMOVNE was changed/commuted to CMOVE
2 - why aren't we using the ZF flag result from SHR instead of the extra TEST?
gcc gets (1) right, but still doesn't do (2)
test(unsigned int, unsigned int, int, int):
movl %ecx, %eax
movl %esi, %ecx
shrl %cl, %edi
testl %edi, %edi
cmove %edx, %eax
ret
Also note, that more recently we use the BMI2 shifts instead which don't update
the flags at all.</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>