https://gcc.gnu.org/bugzilla/show_bug.cgi?id=101039
--- Comment #5 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Jeff Law <[email protected]>: https://gcc.gnu.org/g:6c9deef7effbf410e5d4061c4ea6f53e1dca0bad commit r17-5558-g6c9deef7effbf410e5d4061c4ea6f53e1dca0bad Author: Alexey Lapshin <[email protected]> Date: Sun Oct 25 08:03:34 2026 -0600 [PATCH v3] match.pd: fold floating compare-and-negate idioms to abs PR tree-optimization/101039 folded A CMP 0 ? A : -A after that form was expanded into an if, by matching it in match.pd (r12-2041). The true arm there is A and the false arm is -A. The swapped form still does not fold for floating point. Integers reach the existing pattern by inverting the comparison. A floating comparison that may trap on NaNs cannot be inverted: the inverse of < is UNGE, and UNGE does not raise invalid. Fold A </<= 0 ? -A : A to ABS (A) and A >/>= 0 ? -A : A to -ABS (A) when signed zeros need not be preserved. ABS does not raise invalid, so the ordered compare is removed only when the operand cannot be a NaN, or when the invalid exception is not observable. A conversion from an integer cannot be a NaN. A NaN selects either arm, and both arms are NaNs. Vectors are folded only when the target can do ABS (and NEGATE for the -ABS form). gcc: * match.pd (A </<= 0 ? -A : A, A >/>= 0 ? -A : A): New patterns. gcc/testsuite/ * gcc.dg/tree-ssa/abs-5.c: New test. * gcc.dg/tree-ssa/abs-6.c: New test. * gcc.dg/tree-ssa/phi-opt-53.c: New test.
