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

--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Richard Biener <rgue...@gcc.gnu.org>:

https://gcc.gnu.org/g:422d1d378e52418d821781ad756cf3eafc3fa9a2

commit r12-7292-g422d1d378e52418d821781ad756cf3eafc3fa9a2
Author: Richard Biener <rguent...@suse.de>
Date:   Tue Feb 15 13:32:22 2022 +0100

    tree-optimization/96881 - CD-DCE and CLOBBERs

    CD-DCE does not consider CLOBBERs as necessary in the attempt
    to not prevent DCE of SSA defs it uses.  A side-effect of that
    is that it also removes all its control dependences if they are
    not made necessary by other means.  When we later try to preserve
    as many CLOBBERs as possible we have to make sure we also
    preserved the controlling conditions, otherwise a CLOBBER can
    now appear on a path where it was not executed before, leading
    to wrong code as seen in the testcase.

    I've tried to continue to handle both direct and indirect
    CLOBBERs optimistically, allowing CD-DCE to remove control
    flow that just controls CLOBBERs but that regresses for
    example the stack coalescing test g++.dg/opt/pr80032.C.
    The pattern there is
      if (pred) D.2512 = CLOBBER; else D.2512 = CLOBBER;
    basically we have all paths leading to the same clobber but
    we could safely cut some branches which we do not realize
    early enough.  This regression can be mitigated by no longer
    considering direct CLOBBERs optimistically - the original
    motivation for the CD-DCE handling wasn't removal of control
    flow but SSA defs of the address.

    Handling indirect vs. direct clobbers differently feels
    somewhat wrong, still the patch goes with this solution.

    2022-02-15  Richard Biener  <rguent...@suse.de>

            PR tree-optimization/96881
            * tree-ssa-dce.cc (mark_stmt_if_obviously_necessary): Comment
            CLOBBER handling.
            (control_parents_preserved_p): New function.
            (eliminate_unnecessary_stmts): Check that we preserved control
            parents before retaining a CLOBBER.
            (perform_tree_ssa_dce): Pass down aggressive flag
            to eliminate_unnecessary_stmts.

            * g++.dg/torture/pr96881-1.C: New testcase.
            * g++.dg/torture/pr96881-2.C: Likewise.

Reply via email to