In certain cases, lowering negations can cause an infinite loop in SelectionDAG on X86.
The following snippet shows that behaviour:
https://godbolt.org/z/5hP45T4hY
What happens is that ADD(XOR(..., -1), 1) is detected as the two's complement and transformed into SUB(0, ...)
However, immediates can not be encoded as the LHS of a SUB on X86.
Therefore it is transformed back into an ADD/XOR pair, which is then again transformed into a SUB and so on.
In that specific case, I still think it is valid to display this as a SUB(0,...) , because it should eventually be lowered as a NEG.
Which seems better than an ADD/XOR pair.
Adding an exception to the X86 specific handling for SUBs with 0 LHS operand fixes this infinite loop.
Can this not be reduced any further?