Fix PR82157

Message ID alpine.LSU.2.20.1709121546240.26836@zhemvz.fhfr.qr
State New
Headers show
Series
  • Fix PR82157
Related show

Commit Message

Richard Biener Sept. 12, 2017, 1:47 p.m.
The following fixes a latent issue in fold_stmt uncovered by
PRE re-org.  We muck with the gsi in inapprorpate ways.

Bootstrapped on x86_64-unknown-linux-gnu, testing in progress.

Richard.

2017-09-12  Richard Biener  <rguenther@suse.de>

	PR tree-optimization/82157
	* tree-ssa-pre.c (remove_dead_inserted_code): Do not remove
	stmts with side-effects.

	* gcc.dg/torture/pr82157.c: New testcase.

Patch

Index: gcc/tree-ssa-pre.c
===================================================================
--- gcc/tree-ssa-pre.c	(revision 252002)
+++ gcc/tree-ssa-pre.c	(working copy)
@@ -4913,6 +4964,8 @@  remove_dead_inserted_code (void)
 	continue;
 
       gimple *t = SSA_NAME_DEF_STMT (def);
+      if (gimple_has_side_effects (t))
+	continue;
 
       /* Add uses to the worklist.  */
       ssa_op_iter iter;
Index: gcc/testsuite/gcc.dg/torture/pr82157.c
===================================================================
--- gcc/testsuite/gcc.dg/torture/pr82157.c	(nonexistent)
+++ gcc/testsuite/gcc.dg/torture/pr82157.c	(working copy)
@@ -0,0 +1,43 @@ 
+/* { dg-do compile } */
+
+int a, b, c, d, e, f, g, h, i, j, k, l, m, n, o, p, q, r, s, t, u, v, w, x, y, z;
+
+int aa ()
+{ 
+  w = f < 0 || e >> f;
+  while (z)
+    h = i && (r && p) | ((l = p) == c % d);
+  k = v + 1 < a;
+  t = -(j < 1) * q;
+  return u;
+}
+
+int ab ()
+{ 
+  for (j = 0; 1; j = 5)
+    if (!s)
+      return d;
+}
+
+void ac ()
+{ 
+  char ad = aa ();
+  ab ();
+  if (x)
+    { 
+      for (m = 0; m < 3; m = a)
+	{ 
+	  y = a && b;
+	  if (g)
+	    break;
+	}
+      n = j;
+    }
+  o = j & ad;
+}
+
+int main ()
+{ 
+  ac ();
+  return 0;
+}