<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 - Missed btc opportunities"
href="https://bugs.llvm.org/show_bug.cgi?id=47193">47193</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Missed btc opportunities
</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>uint16_t toggle16(uint16_t num, uint16_t bit) {
num ^= 1ULL << bit;
return num;
}
uint32_t toggle32(uint32_t num, uint32_t bit) {
num ^= 1ULL << bit;
return num;
}
uint64_t toggle64(uint64_t num, uint32_t bit) {
num ^= 1ULL << bit;
return num;
}
uint64_t case1(unsigned long num, uint64_t bit)
{
num ^= 1U << bit;
return num;
}
uint64_t case2(unsigned long num, uint64_t bit)
{
num ^= 1UL << bit;
return num;
}
Clang:
toggle16: # @toggle16
mov ecx, esi
mov eax, 1
shl rax, cl
xor eax, edi
ret
toggle32: # @toggle32
mov ecx, esi
mov eax, 1
shl rax, cl
xor eax, edi
ret
toggle64: # @toggle64
mov rax, rdi
btc rax, rsi
ret
case1(unsigned long, unsigned long): #
@case1(unsigned long, unsigned long)
mov rcx, rsi
mov eax, 1
shl eax, cl
xor rax, rdi
ret
case2(unsigned long, unsigned long): #
@case2(unsigned long, unsigned long)
mov rax, rdi
btc rax, rsi
ret
MSVC can catch all cases and produce btc.
<a href="https://gcc.godbolt.org/z/oE9qdz">https://gcc.godbolt.org/z/oE9qdz</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>