public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/96881] New: [8/9/10/11 Regression] Clobbers on NULL vs. DCE since r8-1519
@ 2020-09-01 10:54 jakub at gcc dot gnu.org
  2020-09-01 10:55 ` [Bug tree-optimization/96881] " jakub at gcc dot gnu.org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-09-01 10:54 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 96881
           Summary: [8/9/10/11 Regression] Clobbers on NULL vs. DCE since
                    r8-1519
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jakub at gcc dot gnu.org
                CC: jakub at gcc dot gnu.org, marxin at gcc dot gnu.org,
                    rguenth at gcc dot gnu.org, slyfox at gcc dot gnu.org,
                    unassigned at gcc dot gnu.org, webrown.cpp at gmail dot com
        Depends on: 96717, 96722
            Blocks: 96721
  Target Milestone: ---

+++ This bug was initially created as a clone of Bug #96722 +++

struct S { int s; ~S () {} };

void
foo (S *a)
{
  if (a)
    return;
  a->~S ();
}

int
main ()
{
  S s;
  foo (&s);
}

is miscompiled, since r249450 aka
r8-1519-ge59a1c22fb249388e82b4fd004f33615abe36d2e at -O2.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96717
[Bug 96717] -flifetime-dse=2 breaks webkit-gtk-2.28.4
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96721
[Bug 96721] [11 Regression] pseudo-destructor calls on pointers since r11-2238
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96722
[Bug 96722] [8/9/10/11 Regression] Clobbers on NULL since r8-1519

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug tree-optimization/96881] [8/9/10/11 Regression] Clobbers on NULL vs. DCE since r8-1519
  2020-09-01 10:54 [Bug tree-optimization/96881] New: [8/9/10/11 Regression] Clobbers on NULL vs. DCE since r8-1519 jakub at gcc dot gnu.org
@ 2020-09-01 10:55 ` jakub at gcc dot gnu.org
  2020-09-02  7:39 ` rguenth at gcc dot gnu.org
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-09-01 10:55 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
This PR should cover the CDDCE part of PR96722, e.g. as mentioned in
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96722#c6

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug tree-optimization/96881] [8/9/10/11 Regression] Clobbers on NULL vs. DCE since r8-1519
  2020-09-01 10:54 [Bug tree-optimization/96881] New: [8/9/10/11 Regression] Clobbers on NULL vs. DCE since r8-1519 jakub at gcc dot gnu.org
  2020-09-01 10:55 ` [Bug tree-optimization/96881] " jakub at gcc dot gnu.org
@ 2020-09-02  7:39 ` rguenth at gcc dot gnu.org
  2020-09-17 17:58 ` jakub at gcc dot gnu.org
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-09-02  7:39 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Last reconfirmed|                            |2020-09-02
           Assignee|unassigned at gcc dot gnu.org      |rguenth at gcc dot gnu.org
     Ever confirmed|0                           |1
   Target Milestone|---                         |8.5
             Status|UNCONFIRMED                 |ASSIGNED

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
Mine eventually.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug tree-optimization/96881] [8/9/10/11 Regression] Clobbers on NULL vs. DCE since r8-1519
  2020-09-01 10:54 [Bug tree-optimization/96881] New: [8/9/10/11 Regression] Clobbers on NULL vs. DCE since r8-1519 jakub at gcc dot gnu.org
  2020-09-01 10:55 ` [Bug tree-optimization/96881] " jakub at gcc dot gnu.org
  2020-09-02  7:39 ` rguenth at gcc dot gnu.org
@ 2020-09-17 17:58 ` jakub at gcc dot gnu.org
  2020-10-12 12:26 ` rguenth at gcc dot gnu.org
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: jakub at gcc dot gnu.org @ 2020-09-17 17:58 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96881
Bug 96881 depends on bug 96722, which changed state.

Bug 96722 Summary: [8/9 Regression] Clobbers on NULL since r8-1519
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=96722

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug tree-optimization/96881] [8/9/10/11 Regression] Clobbers on NULL vs. DCE since r8-1519
  2020-09-01 10:54 [Bug tree-optimization/96881] New: [8/9/10/11 Regression] Clobbers on NULL vs. DCE since r8-1519 jakub at gcc dot gnu.org
                   ` (2 preceding siblings ...)
  2020-09-17 17:58 ` jakub at gcc dot gnu.org
@ 2020-10-12 12:26 ` rguenth at gcc dot gnu.org
  2021-05-14  9:53 ` [Bug tree-optimization/96881] [9/10/11/12 " jakub at gcc dot gnu.org
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-10-12 12:26 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug tree-optimization/96881] [9/10/11/12 Regression] Clobbers on NULL vs. DCE since r8-1519
  2020-09-01 10:54 [Bug tree-optimization/96881] New: [8/9/10/11 Regression] Clobbers on NULL vs. DCE since r8-1519 jakub at gcc dot gnu.org
                   ` (3 preceding siblings ...)
  2020-10-12 12:26 ` rguenth at gcc dot gnu.org
@ 2021-05-14  9:53 ` jakub at gcc dot gnu.org
  2021-06-01  8:18 ` rguenth at gcc dot gnu.org
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: jakub at gcc dot gnu.org @ 2021-05-14  9:53 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|8.5                         |9.4

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 8 branch is being closed.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug tree-optimization/96881] [9/10/11/12 Regression] Clobbers on NULL vs. DCE since r8-1519
  2020-09-01 10:54 [Bug tree-optimization/96881] New: [8/9/10/11 Regression] Clobbers on NULL vs. DCE since r8-1519 jakub at gcc dot gnu.org
                   ` (4 preceding siblings ...)
  2021-05-14  9:53 ` [Bug tree-optimization/96881] [9/10/11/12 " jakub at gcc dot gnu.org
@ 2021-06-01  8:18 ` rguenth at gcc dot gnu.org
  2022-02-15 12:32 ` rguenth at gcc dot gnu.org
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-06-01  8:18 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|9.4                         |9.5

--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 9.4 is being released, retargeting bugs to GCC 9.5.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug tree-optimization/96881] [9/10/11/12 Regression] Clobbers on NULL vs. DCE since r8-1519
  2020-09-01 10:54 [Bug tree-optimization/96881] New: [8/9/10/11 Regression] Clobbers on NULL vs. DCE since r8-1519 jakub at gcc dot gnu.org
                   ` (5 preceding siblings ...)
  2021-06-01  8:18 ` rguenth at gcc dot gnu.org
@ 2022-02-15 12:32 ` rguenth at gcc dot gnu.org
  2022-02-18  7:50 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-02-15 12:32 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> ---
The CD-DCE issue is that we do not mark CLOBBERs as necessary but in the end
choose to keep them, even if we elided its control dependences.  The following
fixes that in the simplest conservative way.

This is really wrong-code.  Testcase

struct S { int s; ~S () {} } s;

void __attribute__((noinline))
foo (int flag)
{
  s.s = 1;
  if (!flag) // dependend on which path CDDCE preserves the CLOBBER gets elided
anyway
    return;
  s.~S();
}

int
main ()
{
  foo (0);
  if (s.s != 1)
    __builtin_abort ();
}


diff --git a/gcc/tree-ssa-dce.cc b/gcc/tree-ssa-dce.cc
index f1034878eaf..c78d7c6ccc7 100644
--- a/gcc/tree-ssa-dce.cc
+++ b/gcc/tree-ssa-dce.cc
@@ -1272,7 +1272,7 @@ maybe_optimize_arith_overflow (gimple_stmt_iterator *gsi,
    contributes nothing to the program, and can be deleted.  */

 static bool
-eliminate_unnecessary_stmts (void)
+eliminate_unnecessary_stmts (bool aggressive)
 {
   bool something_changed = false;
   basic_block bb;
@@ -1366,7 +1366,9 @@ eliminate_unnecessary_stmts (void)
                          break;
                        }
                    }
-                 if (!dead)
+                 if (!dead
+                     && (!aggressive
+                         || bitmap_bit_p (visited_control_parents,
bb->index)))
                    {
                      bitmap_clear (debug_seen);
                      continue;
@@ -1876,7 +1878,7 @@ perform_tree_ssa_dce (bool aggressive)
   propagate_necessity (aggressive);
   BITMAP_FREE (visited);

-  something_changed |= eliminate_unnecessary_stmts ();
+  something_changed |= eliminate_unnecessary_stmts (aggressive);
   something_changed |= cfg_altered;

   /* We do not update postdominators, so free them unconditionally.  */

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug tree-optimization/96881] [9/10/11/12 Regression] Clobbers on NULL vs. DCE since r8-1519
  2020-09-01 10:54 [Bug tree-optimization/96881] New: [8/9/10/11 Regression] Clobbers on NULL vs. DCE since r8-1519 jakub at gcc dot gnu.org
                   ` (6 preceding siblings ...)
  2022-02-15 12:32 ` rguenth at gcc dot gnu.org
@ 2022-02-18  7:50 ` cvs-commit at gcc dot gnu.org
  2022-05-27  9:43 ` [Bug tree-optimization/96881] [10/11 " rguenth at gcc dot gnu.org
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-02-18  7:50 UTC (permalink / raw)
  To: gcc-bugs

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 <rguenth@gcc.gnu.org>:

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

commit r12-7292-g422d1d378e52418d821781ad756cf3eafc3fa9a2
Author: Richard Biener <rguenther@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  <rguenther@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.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug tree-optimization/96881] [10/11 Regression] Clobbers on NULL vs. DCE since r8-1519
  2020-09-01 10:54 [Bug tree-optimization/96881] New: [8/9/10/11 Regression] Clobbers on NULL vs. DCE since r8-1519 jakub at gcc dot gnu.org
                   ` (7 preceding siblings ...)
  2022-02-18  7:50 ` cvs-commit at gcc dot gnu.org
@ 2022-05-27  9:43 ` rguenth at gcc dot gnu.org
  2022-06-28 10:41 ` jakub at gcc dot gnu.org
  2023-07-07 10:37 ` [Bug tree-optimization/96881] [11 " rguenth at gcc dot gnu.org
  10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-05-27  9:43 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|9.5                         |10.4

--- Comment #7 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 9 branch is being closed

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug tree-optimization/96881] [10/11 Regression] Clobbers on NULL vs. DCE since r8-1519
  2020-09-01 10:54 [Bug tree-optimization/96881] New: [8/9/10/11 Regression] Clobbers on NULL vs. DCE since r8-1519 jakub at gcc dot gnu.org
                   ` (8 preceding siblings ...)
  2022-05-27  9:43 ` [Bug tree-optimization/96881] [10/11 " rguenth at gcc dot gnu.org
@ 2022-06-28 10:41 ` jakub at gcc dot gnu.org
  2023-07-07 10:37 ` [Bug tree-optimization/96881] [11 " rguenth at gcc dot gnu.org
  10 siblings, 0 replies; 12+ messages in thread
From: jakub at gcc dot gnu.org @ 2022-06-28 10:41 UTC (permalink / raw)
  To: gcc-bugs

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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|10.4                        |10.5

--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
GCC 10.4 is being released, retargeting bugs to GCC 10.5.

^ permalink raw reply	[flat|nested] 12+ messages in thread

* [Bug tree-optimization/96881] [11 Regression] Clobbers on NULL vs. DCE since r8-1519
  2020-09-01 10:54 [Bug tree-optimization/96881] New: [8/9/10/11 Regression] Clobbers on NULL vs. DCE since r8-1519 jakub at gcc dot gnu.org
                   ` (9 preceding siblings ...)
  2022-06-28 10:41 ` jakub at gcc dot gnu.org
@ 2023-07-07 10:37 ` rguenth at gcc dot gnu.org
  10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-07-07 10:37 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|10.5                        |11.5

--- Comment #9 from Richard Biener <rguenth at gcc dot gnu.org> ---
GCC 10 branch is being closed.

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2023-07-07 10:38 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-01 10:54 [Bug tree-optimization/96881] New: [8/9/10/11 Regression] Clobbers on NULL vs. DCE since r8-1519 jakub at gcc dot gnu.org
2020-09-01 10:55 ` [Bug tree-optimization/96881] " jakub at gcc dot gnu.org
2020-09-02  7:39 ` rguenth at gcc dot gnu.org
2020-09-17 17:58 ` jakub at gcc dot gnu.org
2020-10-12 12:26 ` rguenth at gcc dot gnu.org
2021-05-14  9:53 ` [Bug tree-optimization/96881] [9/10/11/12 " jakub at gcc dot gnu.org
2021-06-01  8:18 ` rguenth at gcc dot gnu.org
2022-02-15 12:32 ` rguenth at gcc dot gnu.org
2022-02-18  7:50 ` cvs-commit at gcc dot gnu.org
2022-05-27  9:43 ` [Bug tree-optimization/96881] [10/11 " rguenth at gcc dot gnu.org
2022-06-28 10:41 ` jakub at gcc dot gnu.org
2023-07-07 10:37 ` [Bug tree-optimization/96881] [11 " rguenth at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).