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

--- Comment #14 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:a42aa68bf1ad745a6b36ab9beed1fc2e77ac3f88

commit r12-8078-ga42aa68bf1ad745a6b36ab9beed1fc2e77ac3f88
Author: Jakub Jelinek <ja...@redhat.com>
Date:   Mon Apr 11 10:44:28 2022 +0200

    phiopt: Optimize (x != cst1 ? x : cst2) != cst3 [PR104639]

    Here is an attempt to resolve a P1 regression, where due to threading
    changes we no longer optimize
    bool foo(int i) {
        while (i == 4)
            i += 2;
        return i;
    }
    to just return i != 0; by enhancing the phiopt value_replacement
    optimization.  Normally it will optimize x != cst1 ? x : cst1 to x.
    Here we extend it to also optimize x != cst1 ? x : cst2 to x if
    it (phi result) has a single immediate use which is a comparison
    with some INTEGER_CST cst3 and we can prove that we don't care
    whether x is cst1 or cst2 because both compare the same against cst3.

    2022-04-11  Jakub Jelinek  <ja...@redhat.com>

            PR tree-optimization/104639
            * tree-ssa-phiopt.cc: Include tree-ssa-propagate.h.
            (value_replacement): Optimize (x != cst1 ? x : cst2) != cst3
            into x != cst3.

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

Reply via email to