https://gcc.gnu.org/bugzilla/show_bug.cgi?id=109011
--- Comment #14 from Jakub Jelinek <jakub at gcc dot gnu.org> --- (In reply to Hongtao.liu from comment #13) > It looks like ffs is *just* ctz with defined behavior for zero, so we can > handle it exactly the same as ctz in the same pattern match((bitsize - .CLZ > ((x - 1) & ~x)) or .POPCOUNT ((x - 1) & ~x)) when CLZ_DEFINED_VALUE_AT_ZERO > 2. No, ffs(x) is ctz(x) + 1 for all x != 0, and 0 for x == 0. But yes, we can generally handle it similarly. Let me attach a patch.