As discussed in in D128123, converting sub to xor can cause codegen regressions, and it may not be reversible with respect to no-wrap as shown here:
https://alive2.llvm.org/ce/z/vebvhH
The PhaseOrdering test is based on the example provided in the other review.
Generally, we prefer bitwise-logic to math ops in IR even if that means dropping no-wrap flags -- because that allows better bit-tracking. But as noted, we need to improve the backend before easing the conditions here to avoid sub-optimal codegen.
This makes the IR fold the same as SDAG other than avoiding the transform in the presence of nsw/nuw. We probably want to update SDAG too -- either with a similar check as here or with a TLI hook to restrict the fold for targets that prefer sub-from-constant form.