On Fri, May 29, 2020 at 5:56 AM Naveen Hurugalawadi via Gcc-patches <gcc-patches@gcc.gnu.org> wrote: > > Hi, > > Please find attached the patch that addresses PR94882. > > Bootstrapped and regression tested on x86_64-pc-linux-gnu.
Is the pattern correct for saturating arithmetic? Some related patterns test !TYPE_SATURATING. I guess that the pattern is still correct for (unsigned)((x & y) - (x | y)) + -1u which would be one more variant to test. That is, the need to spell out three different cases (do they all appear for signed integer?) hints at lack of canonicalization (for the fear of undefined overflow I guess). Also raises the question whether the pattern should be guarded with !TYPE_OVERFLOW_SANITIZED and/or !TYPE_OVERFLOW_TRAPS + (minus (bit_and @0 @1) (plus:c (bit_ior @0 @1) integer_onep)) the plus does not required :c (constants are canonicalized last) + (bit_not (bit_xor @0 @1))) can you add some cases with unsigned types and types smaller than int (thus with integral promotion applied)? Thanks, Richard. > Thanks, > Naveen > > match.pd: (x & y) - (x | y) - 1 -> ~(x ^ y) simplification [PR94882] > > 2029-05-04 Naveen H S <nave...@marvell.com> > > PR tree-optimization/94882 > > * match.pd (x & y) - (x | y) - 1 -> ~(x ^ y): New simplification. > > * gcc.dg/tree-ssa/pr94882.c: New test. > * gcc.dg/tree-ssa/pr94882-1.c: New test.