https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90838
Jakub Jelinek <jakub at gcc dot gnu.org> changed: What |Removed |Added ---------------------------------------------------------------------------- CC| |jakub at gcc dot gnu.org --- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> --- __builtin_ctzll is undefined for 0, while the above is well defined and returns 0. https://graphics.stanford.edu/~seander/bithacks.html#ZerosOnRightModLookup has two different table lookups for 32-bit ctz. https://doc.lagout.org/security/Hackers%20Delight.pdf has others. So, if we want to pattern discover this, it might be best to just look for x & -x and some arithmetics on that to turn it into a table lookup index and then just for all the possible values of x & -x (i.e. bitsize(x) + 1) compute the arithmetics (multiplication, modulo, shift, ...) and check the table content at that spot, whether it matches the corresponding ctz value, or remember the value for 0.