match: Handle X != INT_MIN ? -X : INT_MIN [PR125050]

The pattern X != C1 ? -X : C2 currently bails out when C1 is
INT_MIN and the type doesn't wrap, because a signed negation
of INT_MIN is undefined behavior.  But the whole expression is
well-defined: it is equivalent to (signed)(-(unsigned)X).

Handle the wi::only_sign_bit_p case by emitting an unsigned
negate instead of giving up, mirroring what the abs pattern
already does for the same edge case.

	PR tree-optimization/125050

gcc/ChangeLog:

	* match.pd: (X != C1 ? -X : C2): Handle C1 being INT_MIN
	by emitting (signed)(-(unsigned)X) instead of bailing out.

gcc/testsuite/ChangeLog:

	* gcc.dg/fold-condneg-2.c: Update expected optimization.
	* gcc.dg/pr125050.c: New test.
	* gcc.dg/tree-ssa/phi-opt-50.c: New test.
	* gcc.dg/tree-ssa/phi-opt-51.c: New test.

Signed-off-by: Avinal Kumar <avinal.xlvii@gmail.com>
5 files changed