When an instruction is only used in a select or phi operand, we might be able to make use of additional information from the select/branch condition. For example in
%sub = call i16 @llvm.usub.sat.i16(i16 %x, i16 10) %cmp = icmp uge i16 %x, 10 %sel = select i1 %cmp, i16 %sub, i16 42
the usub.sat is only used in a select where %x uge 10 is known to hold, so we can fold it based on that knowledge.
This addresses the regression reported at https://reviews.llvm.org/D140798#4039748, but also provides a solution to a recurring problem we've had, where we fail to make use of range information after a branch+phi has been converted into a select. Our current solution to this is to hope that IPSCCP can perform the fold before that happens, but handling this in LVI is a somewhat more general solution.
Currently we only make use of this for the willNotOverflow() fold, but I plan to adjust other folds to use the new API as well.