]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
if-conv: Delete dead stmts backwards in ifcvt_local_dce [PR94283]
authorJakub Jelinek <jakub@redhat.com>
Wed, 25 Mar 2020 07:08:04 +0000 (08:08 +0100)
committerJakub Jelinek <jakub@redhat.com>
Tue, 7 Apr 2020 18:57:48 +0000 (20:57 +0200)
> > This patch caused:
> >
> > gcc /home/marxin/Programming/gcc/gcc/testsuite/gcc.c-torture/compile/990625-2.c -O3 -g -fno-tree-dce -c
> > during GIMPLE pass: ifcvt
> > /home/marxin/Programming/gcc/gcc/testsuite/gcc.c-torture/compile/990625-2.c: In function ‘broken030599’:
> > /home/marxin/Programming/gcc/gcc/testsuite/gcc.c-torture/compile/990625-2.c:2:1: internal compiler error: Segmentation fault
>
> Likely
>
>   /* Delete dead statements.  */
>   gsi = gsi_start_bb (bb);
>   while (!gsi_end_p (gsi))
>     {
>
> needs to instead work back-to-front for debug stmt adjustment to work

Indeed, that seems to work.

2020-03-25  Richard Biener  <rguenther@suse.de>
    Jakub Jelinek  <jakub@redhat.com>

PR debug/94283
* tree-if-conv.c (ifcvt_local_dce): Delete dead statements backwards.

* gcc.dg/pr94283.c: New test.

Co-authored-by: Richard Biener <rguenther@suse.de>
gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr94283.c [new file with mode: 0644]
gcc/tree-if-conv.c

index 95b7cc8f7ca291a35ef6ef4c048ca5ac42e4548f..e52fcf6707b3bf39b516cb3d82d7ef32d49476ae 100644 (file)
@@ -1,6 +1,14 @@
 2020-04-07  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2020-03-25  Richard Biener  <rguenther@suse.de>
+                   Jakub Jelinek  <jakub@redhat.com>
+
+       PR debug/94283
+       * tree-if-conv.c (ifcvt_local_dce): Delete dead statements backwards.
+
+2020-04-07  Jakub Jelinek  <jakub@redhat.com>
+
        2020-03-24  Jakub Jelinek  <jakub@redhat.com>
 
        PR debug/94283
index 30ce191dfef8c04ee6879c592ae8aed83a6f2dff..a36c7d85fae5cfc264a306e35bd7d2b4b6a521ef 100644 (file)
@@ -1,6 +1,11 @@
 2020-04-07  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2020-03-25  Jakub Jelinek  <jakub@redhat.com>
+
+       PR debug/94283
+       * gcc.dg/pr94283.c: New test.
+
        2020-03-24  Jakub Jelinek  <jakub@redhat.com>
 
        PR debug/94283
diff --git a/gcc/testsuite/gcc.dg/pr94283.c b/gcc/testsuite/gcc.dg/pr94283.c
new file mode 100644 (file)
index 0000000..ac162d6
--- /dev/null
@@ -0,0 +1,16 @@
+/* PR debug/94283 */
+/* { dg-do compile } */
+/* { dg-options "-O3 -fno-tree-dce -fcompare-debug" } */
+
+void
+foo (int *n)
+{
+  for (int i = 0; i < 32; i++)
+    {
+      int x = 0;
+      x++;
+      if (i & 4)
+       x++;
+      x++;
+    }
+}
index 8a6e2415d7c9a4d2d11c0fb71d02cb5e5e1ed0e5..699b48b81245c4dfa28087da131b469973934733 100644 (file)
@@ -2969,13 +2969,15 @@ ifcvt_local_dce (basic_block bb)
        }
     }
   /* Delete dead statements.  */
-  gsi = gsi_start_bb (bb);
+  gsi = gsi_last_bb (bb);
   while (!gsi_end_p (gsi))
     {
+      gimple_stmt_iterator gsiprev = gsi;
+      gsi_prev (&gsiprev);
       stmt = gsi_stmt (gsi);
       if (gimple_plf (stmt, GF_PLF_2))
        {
-         gsi_next (&gsi);
+         gsi = gsiprev;
          continue;
        }
       if (dump_file && (dump_flags & TDF_DETAILS))
@@ -2985,6 +2987,7 @@ ifcvt_local_dce (basic_block bb)
        }
       gsi_remove (&gsi, true);
       release_defs (stmt);
+      gsi = gsiprev;
     }
 }