This patch is for PR43053, the following pattern:
%cmp1 = icmp slt i32 %num, C1 %s1 = select i1 %cmp1, i32 %num, i32 C1 %cmp2 = icmp sgt i32 %s1, C2 %r = select i1 %cmp2, i32 %s1, i32 C2 ; C2 = C1 - 1
can be folded into
%cmp3 = icmp sgt %num, C2 %r = select i1 %cmp3, C1, C2
It'd be better if we could use m_APInt here to support vectors (including handling undef element cases).