The ffs function can be converted to ctz if the operand is known not
to be zero, as is the case for example in

    while (x != 0) {
       bit = ffs(x) - 1;
       ...
       x &= ~(1 << bit);
    }

CSE can already do this on x86, but the attached patch implements this
folding in VRP in a target-independent way.

Bootstrapped/regtested x86_64-pc-linux-gnu, ok?

Paolo

Attachment: fold-ffs.patch
Description: Binary data

Reply via email to