This mimics the code for the corresponding cmp-select idiom.
This also prevents an infinite loop because isFreeToInvert does not match constant expressions.
So this patch solves the same problem as D108814 and would overwrite it, but my main motivation is to enhance the pattern matching to allow more invertible ops. I'll post that change as a follow-up patch on top of this one.