[Bug tree-optimization/56223] Integer ABS is not recognized for more complicated pattern
"cvs-commit at gcc dot gnu.org via Gcc-bugs" <[email protected]> Wed, 05 Aug 2026 07:54:06 +0000
| Newsgroups | gmane.comp.gcc.bugs |
|---|---|
| Message-ID | <[email protected]/bugzilla/> |
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=56223 --- Comment #13 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Naveen H.S <[email protected]>: https://gcc.gnu.org/g:36990bb0d14c4840d0250f000559d7a2a569fbc9 commit r17-2972-g36990bb0d14c4840d0250f000559d7a2a569fbc9 Author: Naveen <[email protected]> Date: Wed Aug 5 00:52:53 2026 -0700 tree-optimization: Recognize add/sub absolute-value idiom [PR56223] Recognize conditional addition and subtraction patterns equivalent to Y + abs (X) and Y - abs (X). For signed integral types, perform the addition or subtraction in the corresponding unsigned type and convert the result back to the original type. This avoids introducing signed overflow and preserves wrapping semantics including when X is TYPE_MIN_VALUE. Do not perform the transformation when signed overflow traps or is sanitized. gcc/ChangeLog: PR tree-optimization/56223 * match.pd (X >=/> 0 ? Y + X : Y - X): New simplification. (X <=/< 0 ? Y - X : Y + X): Likewise. gcc/testsuite/ChangeLog: PR tree-optimization/56223 * gcc.dg/tree-ssa/pr56223.c: New test. * gcc.dg/tree-ssa/pr56223-2.c: New test. * gcc.dg/tree-ssa/pr56223-3.c: New test. * gcc.dg/tree-ssa/pr56223-4.c: New test. Signed-off-by: Naveen <[email protected]>