https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96685

--- Comment #7 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Jakub Jelinek <ja...@gcc.gnu.org>:

https://gcc.gnu.org/g:0bd675183d94e6bca100c3aaaf87ee9676fb3c26

commit r11-5958-g0bd675183d94e6bca100c3aaaf87ee9676fb3c26
Author: Jakub Jelinek <ja...@redhat.com>
Date:   Sat Dec 12 14:49:57 2020 +0100

    match.pd: Add ~(X - Y) -> ~X + Y simplification [PR96685]

    This patch adds the ~(X - Y) -> ~X + Y simplification requested
    in the PR (plus also ~(X + C) -> ~X + (-C) for constants C that can
    be safely negated.

    The first two simplify blocks is what has been requested in the PR
    and that makes the first testcase pass.
    Unfortunately, that change also breaks the second testcase, because
    while the same expressions appearing in the same stmt and split
    across multiple stmts has been folded (not really) before, with
    this optimization fold-const.c optimizes ~X + Y further into
    (Y - X) - 1 in fold_binary_loc associate: code, but we have nothing
    like that in GIMPLE and so end up with different expressions.

    The last simplify is an attempt to deal with just this case,
    had to rule out there the Y == -1U case, because then we
    reached infinite recursion as ~X + -1U was canonicalized by
    the pattern into (-1U - X) + -1U but there is a canonicalization
    -1 - A -> ~A that turns it back.  Furthermore, had to make it #if
    GIMPLE only, because it otherwise resulted in infinite recursion
    when interacting with the associate: optimization.
    The end result is that we pass all 3 testcases and thus canonizalize
    the 3 possible forms of writing the same thing.

    2020-12-12  Jakub Jelinek  <ja...@redhat.com>

            PR tree-optimization/96685
            * match.pd (~(X - Y) -> ~X + Y): New optimization.
            (~X + Y -> (Y - X) - 1): Likewise.

            * gcc.dg/tree-ssa/pr96685-1.c: New test.
            * gcc.dg/tree-ssa/pr96685-2.c: New test.
            * gcc.dg/tree-ssa/pr96685-3.c: New test.

Reply via email to