https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125050
--- Comment #4 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The trunk branch has been updated by Andrew Pinski <[email protected]>: https://gcc.gnu.org/g:33cd7bbb32c5eee4aff7aa06f351aa983be419bc commit r17-669-g33cd7bbb32c5eee4aff7aa06f351aa983be419bc Author: Avinal Kumar <[email protected]> Date: Thu May 21 15:54:12 2026 +0530 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 <[email protected]>
