Related to https://bugs.llvm.org/show_bug.cgi?id=28668.
Checking whether a number has a certain number of trailing / leading zeros means checking whether it is of the form 0001XXXX or XXXX1000, which can be done with an and+icmp.
This is the first step, handling only eq/ne predicates, as that's what the existing code does. I'd like to extend this to handle all predicate types in the next step, which would resolve https://github.com/rust-lang/rust/issues/43024.
We have to check hasOneUse() on the intrinsic, or we'll end up with extra instructions for an example like this:
define i1 @ctlz_eq_other_i32(i32 %x, i32* %p) { %lz = tail call i32 @llvm.ctlz.i32(i32 %x, i1 false) store i32 %lz, i32* %p %cmp = icmp eq i32 %lz, 24 ret i1 %cmp }In cases where the 'and' gets removed, you don't need the one-use restriction, but I'm not sure if it's worth trying to differentiate those from the general case.