[llvm-bugs] [Bug 48692] New: Failure to optimize integer conversion pattern
via llvm-bugs
llvm-bugs at lists.llvm.org
Thu Jan 7 14:33:59 PST 2021
https://bugs.llvm.org/show_bug.cgi?id=48692
Bug ID: 48692
Summary: Failure to optimize integer conversion pattern
Product: libraries
Version: trunk
Hardware: PC
OS: Linux
Status: NEW
Severity: enhancement
Priority: P
Component: Scalar Optimizations
Assignee: unassignedbugs at nondot.org
Reporter: gabravier at gmail.com
CC: llvm-bugs at lists.llvm.org
int64_t f(int64_t x)
{
return ((x << 48 >> 48) & -65536) | (x & 65535);
}
This can be optimized to `return (x << 48 >> 48);` (i.e. `(int16_t)x`), see
also Alive2 test here: https://alive2.llvm.org/ce/z/L7z-JQ
Should be generalizable to shifts/and patterns of any size.
Note: I originally found this while investigating how GCC and LLVM optimize
this piece of code:
union reg {
uint64_t r;
uint16_t x;
};
reg cbw(reg dest)
{
dest.r = (int16_t)dest.x;
return dest;
}
Which (on little endian targets) GCC optimizes to `return (int16_t)x` and LLVM
optimizes to the sample code I gave above.
--
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/20210107/67cb2e6b/attachment.html>
More information about the llvm-bugs
mailing list