https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101610
Bug ID: 101610
Summary: CST - (x ^ (CST-1)) can be optimized to x + 1 if x <
CST and CST is a power of 2
Product: gcc
Version: 12.0
Status: UNCONFIRMED
Keywords: missed-optimization
Severity: enhancement
Priority: P3
Component: tree-optimization
Assignee: unassigned at gcc dot gnu.org
Reporter: pinskia at gcc dot gnu.org
Target Milestone: ---
Take:
unsigned long f(unsigned long x)
{
if (x >= 64)__builtin_unreachable();
x = x ^ 63;
unsigned long y = (unsigned long )x;
unsigned long z = 64 - y;
return z;
}
This should just be:
unsigned long long f1(unsigned long x)
{
return x + 1;
}