<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 - Bool vs unsigned result gives very different codegen for bit tests"
href="https://bugs.llvm.org/show_bug.cgi?id=36551">36551</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Bool vs unsigned result gives very different codegen for bit tests
</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>Common Code Generator Code
</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, efriedma@codeaurora.org, llvm-bugs@lists.llvm.org, spatel+llvm@rotateright.com
</td>
</tr></table>
<p>
<div>
<pre><a href="https://godbolt.org/g/EFjrMf">https://godbolt.org/g/EFjrMf</a>
Depending on whether we return as a bool or an unsigned, we get quite different
codegen for a !(x & 4) bit-test:
bool foo(int x) {
return !(x & 4);
}
unsigned bar(int x) {
return !(x & 4);
}
clang/gcc comes up with 4 different implementations here:
clang -g0 -O3:
define i1 @_Z3fooi(i32) {
%2 = and i32 %0, 4
%3 = icmp eq i32 %2, 0
ret i1 %3
}
define i32 @_Z3bari(i32) {
%2 = lshr i32 %0, 2
%3 = and i32 %2, 1
%4 = xor i32 %3, 1
ret i32 %4
}
_Z3fooi: # @_Z3fooi
testb $4, %dil
sete %al
retq
_Z3bari: # @_Z3bari
shrl $2, %edi
notl %edi
andl $1, %edi
movl %edi, %eax
retq
gcc -g0 -O3:
_Z3fooi:
movl %edi, %eax
shrl $2, %eax
xorl $1, %eax
andl $1, %eax
ret
_Z3bari:
xorl %eax, %eax
andl $4, %edi
sete %al
ret</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>