This patch teaches the Instruction Combiner how to fold a cttz/ctlz followed by a icmp plus select into a single cttz/ctlz with flag 'is_zero_undef' cleared.
%a = tail call i32 @llvm.cttz.i32(i32 %x, i1 true) %b = icmp ne i32 %x, 0 %c = select i1 %b, i32 %a, i32 32
In this example, the condition value used by the select instruction compares value %x for equality against zero.
Value %x is also used by the call to the llvm intrinsic cttz. So, the select instruction would propagate the sizeof in bits of %x (i.e. 32) if %x is zero.
The entire cttz+icmp+select sequence can be safely folded into:
%c = tail call i32 @llvm.cttz.i32(i32 %x, i1 false)
Added test InstCombine/select-cmp-cttz-ctlz.ll.
Please let me know if ok to submit.