]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
Fix -fcompare-debug issue in delete_insn_and_edges [PR94618]
authorJakub Jelinek <jakub@redhat.com>
Fri, 17 Apr 2020 08:33:27 +0000 (10:33 +0200)
committerJakub Jelinek <jakub@redhat.com>
Fri, 17 Apr 2020 08:33:27 +0000 (10:33 +0200)
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.

gcc/ChangeLog
gcc/cfgrtl.c
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/opt/pr94618.C [new file with mode: 0644]

index 80b0534ba51f3b60c4d12a9a8c5d4ef5e45067dd..8bce0ea61469f517d486cf7b9f456075f70de9eb 100644 (file)
@@ -1,5 +1,10 @@
 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.
+
        PR tree-optimization/94621
        * tree-inline.c (remap_type_1): Don't dereference NULL TYPE_DOMAIN.
        Move id->adjust_array_error_bounds check first in the condition.
index fb551e3efc0cd5cb31f401cf78a549f7c447a5d8..e6ea687ef31729774e4b3fe3b9fbcb89a934300f 100644 (file)
@@ -230,10 +230,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));
index 64181e4e532f0dc57c9f74264a7d4d011b01ba0e..dd2cb04916f95d4177397feccf862f52cfdee6b6 100644 (file)
@@ -1,5 +1,8 @@
 2020-04-17  Jakub Jelinek  <jakub@redhat.com>
 
+       PR rtl-optimization/94618
+       * g++.dg/opt/pr94618.C: New test.
+
        PR tree-optimization/94621
        * gcc.c-torture/compile/pr94621.c: New test.
 
diff --git a/gcc/testsuite/g++.dg/opt/pr94618.C b/gcc/testsuite/g++.dg/opt/pr94618.C
new file mode 100644 (file)
index 0000000..e6a81d2
--- /dev/null
@@ -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 ();
+}