[llvm-bugs] [Bug 40058] New: Failure to detect bswap at the end of a bitreverse sequence
via llvm-bugs
llvm-bugs at lists.llvm.org
Mon Dec 17 16:04:13 PST 2018
https://bugs.llvm.org/show_bug.cgi?id=40058
Bug ID: 40058
Summary: Failure to detect bswap at the end of a bitreverse
sequence
Product: libraries
Version: trunk
Hardware: PC
OS: Windows NT
Status: NEW
Severity: enhancement
Priority: P
Component: Scalar Optimizations
Assignee: unassignedbugs at nondot.org
Reporter: craig.topper at gmail.com
CC: llvm-bugs at lists.llvm.org
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;
}
https://godbolt.org/z/K0FuOg
--
You are receiving this mail because:
You are on the CC list for the bug.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/llvm-bugs/attachments/20181218/c9564ee4/attachment.html>
More information about the llvm-bugs
mailing list