Hi,
The issue with PR91532 patch was in following hunk in ifcvt_local_dce:

          if (dse_classify_store (&write, stmt, false, NULL, NULL, latch_vdef)
              == DSE_STORE_DEAD)
            delete_dead_or_redundant_assignment (&gsi, "dead");
          gsi_next (&gsi);
          continue;

which resulted in skipping stmt since
delete_dead_or_redundant_assignment() would call gsi_remove, which
already moved gsi to next stmt and gsi_next(stmt) resulted in skipping
the stmt. For the test-case mentioned in comment 1 in PR, this
resulted in deleting:
_4 = (long int) _3
but the following dead stmt got skipped due to gsi_next:
_6 = _4 < _5
which resulted in the error - "use of _4 should have been replaced".

The patch fixes this by simply putting gsi_next in else, which avoids
the above issue.
Bootstrap+test in progress on x86_64-unknown-linux-gnu.
OK to commit if passes ?

Thanks,
Prathamesh
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr92085-1.c b/gcc/testsuite/gcc.dg/tree-ssa/pr92085-1.c
new file mode 100644
index 00000000000..c18f820a09e
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr92085-1.c
@@ -0,0 +1,20 @@
+/* { dg-do compile } */
+/* { dg-options "-O1 -fexceptions -fnon-call-exceptions -ftree-loop-vectorize -fno-tree-sink --param dse-max-alias-queries-per-store=2 -w" } */
+
+void
+di (int y9, int qw)
+{
+  if ((int) &y9 != 0)
+    {
+      int py;
+      int **fq = &py;
+
+      while (qw < 1)
+        {
+          if ((0 < (**fq ? **fq : (**fq = 1))) / (**fq = y9))
+            ;
+
+          ++qw;
+        }
+    }
+}
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/pr92085-2.c b/gcc/testsuite/gcc.dg/tree-ssa/pr92085-2.c
new file mode 100644
index 00000000000..f62585c2f0f
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/pr92085-2.c
@@ -0,0 +1,29 @@
+/* { dg-do compile } */
+/* { dg-options "-O1 -ftree-loop-vectorize -fno-tree-dce -fno-tree-sink -w" } */
+
+int a8;
+
+void
+c1 (int oz, int dk, int ub)
+{
+  int *hd = 0;
+  long int *th = &dk;
+
+  while (ub < 1)
+    {
+      oz || dk;
+      ++ub;
+    }
+
+  while (oz < 2)
+    {
+      long int *lq = &oz;
+
+      (*hd < (*lq = *th)) < oz;
+
+      if (oz == 0)
+        *th = a8 = oz;
+
+      *lq = 0;
+    }
+}
diff --git a/gcc/tree-if-conv.c b/gcc/tree-if-conv.c
index af49813b0d1..7dab1378e98 100644
--- a/gcc/tree-if-conv.c
+++ b/gcc/tree-if-conv.c
@@ -2976,7 +2976,8 @@ ifcvt_local_dce (class loop *loop)
           if (dse_classify_store (&write, stmt, false, NULL, NULL, latch_vdef)
               == DSE_STORE_DEAD)
             delete_dead_or_redundant_assignment (&gsi, "dead");
-	  gsi_next (&gsi);
+	  else
+	    gsi_next (&gsi);
 	  continue;
 	}
 

Reply via email to