The exact patterns, that this patch will enable to be detected, are the following:
a+1 >s b ? a+x : b+x -> smax(a, b)+x
a+1 >s b ? b+x : a+x -> smin(a, b)+x
a+1 >u b ? a+x : b+x -> umax(a, b)+x
a+1 >u b ? b+x : a+x -> umin(a, b)+x
Computations of this form are currently emitted, for example, by the LLVM code generator of the Julia language. This change also resolves the following bug that has been reported for Polly: https://llvm.org/bugs/show_bug.cgi?id=28126. Special thanks go to Michael Kruse for his detailed hints on how to address this problem.
This fall through doesn't work. The a <s (b+1) case is only correct with strict comparisons (ICMP_SLT), but the code below would also allow it with ICMP_SLE.