This improves simplifications for pattern icmp (X+Y), (X+Z) -> icmp Y,Z if only one of the operands has NSW set, e.g.:
icmp slt (x + 5), (x +nsw 6)
We can still safely rewrite this to:
icmp slt 5, 6
because we know that the LHS can't overflow if the RHS has NSW set and constant Y <= Z.
This is useful because ScalarEvolutionExpander which is used to generate code for SCEVs in different loop optimisers is not always able to put back NSW flags across control-flow.
I think this works, but I'm worried that it could break if we are not careful.
If we are swapping the operands, should we also swap the predicate, and then check if it is SLT after the swap?