This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
if (x > ((2^x)-1)) optimization
- From: Jason Duerstock <jason dot duerstock at gmail dot com>
- To: gcc at gcc dot gnu dot org
- Date: Sat, 22 Jun 2019 09:55:50 -0400
- Subject: if (x > ((2^x)-1)) optimization
I was starting at the assembly from some of the Python source, and
came across this (simplified) comparison:
if (x > 2305843009213693951) {...}
This is the same as:
if (x > 0x1fffffffffffffff) {...}
This is equivalent to:
if (x >> 61) {...}
More generally, we can rewrite
if ( x > ((1 << z) -1)) { ...}
as
if ( x >> z ) { ... }
This does not appear to currently be a gcc optimization. What is
involved in adding it?
Jason