This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[committed] Fix forwprop (PR tree-optimization/47265, PR tree-optimization/47443)


Hi!

As discussed in the PR and on IRC, forward_propagate_addr_expr currently
sometimes recurses and the recursion might update_stmt on other stmts
and that might affect the iteration using FOR_EACH_IMM_USE in the
outer forward_propagate_addr_expr.  This patch fixes it by only returning
true (thus, allowing the def_stmt to be removed) if there are no longer any
non-debug uses.

Bootstrapped/regtested on x86_64-linux and i686-linux, preapproved by richi
on IRC, committed to trunk.

2011-01-25  Jakub Jelinek  <jakub@redhat.com>

	PR tree-optimization/47265
	PR tree-optimization/47443
	* tree-ssa-forwprop.c (forward_propagate_addr_expr): Return false
	if name still has some uses.

	* gcc.c-torture/compile/pr47265.c: New test.
	* gcc.dg/pr47443.c: New test.

--- gcc/tree-ssa-forwprop.c.jj	2011-01-25 12:58:36.000000000 +0100
+++ gcc/tree-ssa-forwprop.c	2011-01-25 16:55:02.705433320 +0100
@@ -1114,7 +1114,7 @@ forward_propagate_addr_expr (tree name, 
 	}
     }
 
-  return all;
+  return all && has_zero_uses (name);
 }
 
 /* Forward propagate the comparison defined in STMT like
--- gcc/testsuite/gcc.dg/pr47443.c.jj	2011-01-25 13:50:49.316388845 +0100
+++ gcc/testsuite/gcc.dg/pr47443.c	2011-01-25 13:49:56.000000000 +0100
@@ -0,0 +1,14 @@
+/* PR tree-optimization/47443 */
+/* { dg-do compile } */
+/* { dg-options "-O -fstack-check=generic" } */
+
+static inline bar (char *c, int i)
+{
+  return c + i > c;
+}
+
+int foo ()
+{
+  char c[100];
+  return (bar (c, 1));
+}
--- gcc/testsuite/gcc.c-torture/compile/pr47265.c.jj	2011-01-25 13:48:42.563388835 +0100
+++ gcc/testsuite/gcc.c-torture/compile/pr47265.c	2011-01-25 13:48:17.000000000 +0100
@@ -0,0 +1,20 @@
+/* PR tree-optimization/47265 */
+
+struct S
+{
+  char a[3];
+  char b[3];
+};
+
+void
+bar (char *dst, const char *src, unsigned n)
+{
+  while (n--)
+    *dst++ = *src ? *src++ : ' ';
+}
+
+void
+foo (struct S *s)
+{
+  bar (s->a, s->b, 3);
+}

	Jakub


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]