<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 - Failure to detect bswap at the end of a bitreverse sequence"
href="https://bugs.llvm.org/show_bug.cgi?id=40058">40058</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>Failure to detect bswap at the end of a bitreverse sequence
</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>Scalar Optimizations
</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>llvm-bugs@lists.llvm.org
</td>
</tr></table>
<p>
<div>
<pre>We should recognize that these two sequences end in a bswap.
unsigned long lreverse(unsigned long x) // swap all bits
{
x = ((x & 0xAAAAAAAAUL) >> 1)
| ((x & ~0xAAAAAAAAUL) << 1);
x = ((x & 0xCCCCCCCCUL) >> 2)
| ((x & ~0xCCCCCCCCUL) << 2);
x = ((x & 0xF0F0F0F0UL) >> 4)
| ((x & ~0xF0F0F0F0UL) << 4);
x = ((x & 0xFF00FF00UL) >> 8)
| ((x & ~0xFF00FF00UL) << 8);
x = ((x & 0xFFFF0000UL) >> 16)
| ((x & ~0xFFFF0000UL) << 16);
return x;
}
unsigned long long llreverse(unsigned long long x)
{
x = ((x & 0xAAAAAAAAAAAAAAAAULL) >> 1)
| ((x & ~0xAAAAAAAAAAAAAAAAULL) << 1);
x = ((x & 0xCCCCCCCCCCCCCCCCULL) >> 2)
| ((x & ~0xCCCCCCCCCCCCCCCCULL) << 2);
x = ((x & 0xF0F0F0F0F0F0F0F0ULL) >> 4)
| ((x & ~0xF0F0F0F0F0F0F0F0ULL) << 4);
x = ((x & 0xFF00FF00FF00FF00ULL) >> 8)
| ((x & ~0xFF00FF00FF00FF00ULL) << 8);
x = ((x & 0xFFFF0000FFFF0000ULL) >> 16)
| ((x & ~0xFFFF0000FFFF0000ULL) << 16);
x = ((x & 0xFFFFFFFF00000000ULL) >> 32)
| ((x & ~0xFFFFFFFF00000000ULL) << 32);
return x;
}
<a href="https://godbolt.org/z/K0FuOg">https://godbolt.org/z/K0FuOg</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>