Hi all,
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.
Example:
%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.
Thanks,
Andrea
@llvm.cttz.* and @llvm.ctlz.* both accept vector types as arguments. You may want to switch from m_ConstantInt to m_APInt because it will match against a splatted ConstantVector as well.
You could go even further and use m_SpecificInt(II->getType()->getScalarSizeInBits()) to save you a check later on.