public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/vendors/redhat/heads/gcc-8-branch)] Fix -fcompare-debug issue in delete_insn_and_edges [PR94618]
@ 2020-09-17 17:22 Jakub Jelinek
  0 siblings, 0 replies; only message in thread
From: Jakub Jelinek @ 2020-09-17 17:22 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:79e1b78500c4e962daea493767597a791037eaf0

commit 79e1b78500c4e962daea493767597a791037eaf0
Author: Jakub Jelinek <jakub@redhat.com>
Date:   Fri Apr 17 10:33:27 2020 +0200

    Fix -fcompare-debug issue in delete_insn_and_edges [PR94618]
    
    delete_insn_and_edges calls purge_dead_edges whenever deleting the last insn
    in a bb, whatever it is.  If it called it only for mandatory last insns
    in the basic block (that may not be followed by DEBUG_INSNs, dunno if that
    is control_flow_insn_p or something more complex), that wouldn't be a
    problem, but as it calls it on any last insn and can actually do something
    in the bb, if such an insn is followed by one more more DEBUG_INSNs and
    nothing else in the same bb, we don't call purge_dead_edges with -g and do
    call it with -g0.
    
    On the testcase, there are two reg-to-reg moves with REG_EH_REGION notes
    (previously memory accesses but simplified and yet not optimized), and the
    second is followed by DEBUG_INSNs; the second move is delete_insn_and_edges
    and after removing it, for -g0 purge_dead_edges removes the REG_EH_REGION
    from the now last insn in the bb (the first reg-to-reg move), while
    for -g it isn't called and things diverge from that quickly on.
    
    Fixed by calling purdge_dead_edges even if we remove the last real insn
    followed only by DEBUG_INSNs in the same bb.
    
    2020-04-17  Jakub Jelinek  <jakub@redhat.com>
    
            PR rtl-optimization/94618
            * cfgrtl.c (delete_insn_and_edges): Set purge not just when
            insn is the BB_END of its block, but also when it is only followed
            by DEBUG_INSNs in its block.
    
            * g++.dg/opt/pr94618.C: New test.
    
    (cherry picked from commit c41884a09206be0e21cad7eea71b9754daa969d4)

Diff:
---
 gcc/cfgrtl.c                       | 18 ++++++++++++++----
 gcc/testsuite/g++.dg/opt/pr94618.C | 25 +++++++++++++++++++++++++
 2 files changed, 39 insertions(+), 4 deletions(-)

diff --git a/gcc/cfgrtl.c b/gcc/cfgrtl.c
index bf1504d082f..d15f94ec6dc 100644
--- a/gcc/cfgrtl.c
+++ b/gcc/cfgrtl.c
@@ -224,10 +224,20 @@ delete_insn_and_edges (rtx_insn *insn)
 {
   bool purge = false;
 
-  if (INSN_P (insn)
-      && BLOCK_FOR_INSN (insn)
-      && BB_END (BLOCK_FOR_INSN (insn)) == insn)
-    purge = true;
+  if (INSN_P (insn) && BLOCK_FOR_INSN (insn))
+    {
+      basic_block bb = BLOCK_FOR_INSN (insn);
+      if (BB_END (bb) == insn)
+	purge = true;
+      else if (DEBUG_INSN_P (BB_END (bb)))
+	for (rtx_insn *dinsn = NEXT_INSN (insn);
+	     DEBUG_INSN_P (dinsn); dinsn = NEXT_INSN (dinsn))
+	  if (BB_END (bb) == dinsn)
+	    {
+	      purge = true;
+	      break;
+	    }
+    }
   delete_insn (insn);
   if (purge)
     return purge_dead_edges (BLOCK_FOR_INSN (insn));
diff --git a/gcc/testsuite/g++.dg/opt/pr94618.C b/gcc/testsuite/g++.dg/opt/pr94618.C
new file mode 100644
index 00000000000..e6a81d2c5ab
--- /dev/null
+++ b/gcc/testsuite/g++.dg/opt/pr94618.C
@@ -0,0 +1,25 @@
+// PR rtl-optimization/94618
+// { dg-do compile { target c++11 } }
+// { dg-options "-O2 -fnon-call-exceptions -fcompare-debug" }
+
+struct S
+{
+  int a, b, c;
+  int foo () noexcept { return a; }
+  int bar () noexcept { return b; }
+  void baz (int);
+  void qux () { if (c) for (int x = foo (); x != bar (); ) baz (x); }
+};
+
+struct T
+{
+  S s;
+  void foo ();
+};
+
+void
+T::foo ()
+{
+  s.qux ();
+  s.qux ();
+}


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-09-17 17:22 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-09-17 17:22 [gcc(refs/vendors/redhat/heads/gcc-8-branch)] Fix -fcompare-debug issue in delete_insn_and_edges [PR94618] Jakub Jelinek

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).