https://gcc.gnu.org/bugzilla/show_bug.cgi?id=94920
--- Comment #2 from CVS Commits <cvs-commit at gcc dot gnu.org> --- The trunk branch has been updated by Sam Feifer <sfei...@gcc.gnu.org>: https://gcc.gnu.org/g:633e9920589ddfaf2d6da1c24ce99b18a2638db4 commit r13-1785-g633e9920589ddfaf2d6da1c24ce99b18a2638db4 Author: Sam Feifer <sfei...@redhat.com> Date: Thu Jul 21 16:31:41 2022 -0400 match.pd: Add new abs pattern [PR94920] This patch is intended to fix a missed optimization in match.pd. It optimizes (x >= 0 ? x : 0) + (x <= 0 ? -x : 0) to just abs(x). Additionally, the pattern (x <= 0 ? -x : 0) now gets optimized to max(-x, 0), which helps with the other simplification rule. Tests are also included to be added to the testsuite. Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? PR tree-optimization/94920 gcc/ChangeLog: * match.pd (x >= 0 ? x : 0) + (x <= 0 ? -x : 0): New simplification. (x <= 0 ? -x : 0): New simplification. gcc/testsuite/ChangeLog: * g++.dg/pr94920-1.C: New test. * g++.dg/pr94920.C: New test. * gcc.dg/pr94920-2.c: New test.