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]

[PATCH] Fix tree forwprop a second time (PR middle-end/38200)


Hi!

My earlier patch to forward_propagate_addr_expr_1 contained a thinko,
as for x = &a; *x = b; replacement with a = b; we know a's address
has been taken, so a = (a's type) b; is invalid GIMPLE (a = b;
generated previously was also invalid GIMPLE if the type conversion
wasn't useless).  The following patch thus never adds a cast,
just checks if the conversion is useless.  For
x = &a;
x->j = b;
transforming it to
a.j = b;
doesn't change LHS nor RHS side, so this checking isn't needed.

Ok if bootstrap+regtest succeeds on x86_64-linux?

2008-11-21  Jakub Jelinek  <jakub@redhat.com>

	PR middle-end/38200
	* tree-ssa-forwprop.c (forward_propagate_addr_expr_1): Only
	propagate x = &a into *x = b if conversion from b to a's type is
	useless.

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

--- gcc/tree-ssa-forwprop.c.jj	2008-11-18 19:24:09.000000000 +0100
+++ gcc/tree-ssa-forwprop.c	2008-11-21 15:19:55.000000000 +0100
@@ -719,30 +719,18 @@ forward_propagate_addr_expr_1 (tree name
      propagate the ADDR_EXPR into the use of NAME and fold the result.  */
   if (TREE_CODE (lhs) == INDIRECT_REF
       && TREE_OPERAND (lhs, 0) == name
-      && may_propagate_address_into_dereference (def_rhs, lhs))
+      && may_propagate_address_into_dereference (def_rhs, lhs)
+      && (lhsp != gimple_assign_lhs_ptr (use_stmt)
+	  || useless_type_conversion_p (TREE_TYPE (TREE_OPERAND (def_rhs, 0)),
+					TREE_TYPE (rhs))))
     {
-      bool valid = true;
-      if (lhsp == gimple_assign_lhs_ptr (use_stmt)
-	  && !useless_type_conversion_p (TREE_TYPE (TREE_OPERAND (def_rhs, 0)),
-					 TREE_TYPE (rhs))
-	  && !CONVERT_EXPR_CODE_P (rhs_code))
-	{
-	  if (rhs_code == SSA_NAME)
-	    gimple_assign_set_rhs_code (use_stmt, NOP_EXPR);
-	  else
-	    valid = false;
-	}
-      if (valid)
-	{
-	  *lhsp = unshare_expr (TREE_OPERAND (def_rhs, 0));
-	  fold_stmt_inplace (use_stmt);
-	  tidy_after_forward_propagate_addr (use_stmt);
+      *lhsp = unshare_expr (TREE_OPERAND (def_rhs, 0));
+      fold_stmt_inplace (use_stmt);
+      tidy_after_forward_propagate_addr (use_stmt);
 
-	  /* Continue propagating into the RHS if this was not the only
-	     use.  */
-	  if (single_use_p)
-	    return true;
-	}
+      /* Continue propagating into the RHS if this was not the only use.  */
+      if (single_use_p)
+	return true;
     }
 
   /* Strip away any outer COMPONENT_REF, ARRAY_REF or ADDR_EXPR
--- gcc/testsuite/gcc.dg/pr38200.c.jj	2008-11-21 15:21:52.000000000 +0100
+++ gcc/testsuite/gcc.dg/pr38200.c	2008-11-21 15:07:25.000000000 +0100
@@ -0,0 +1,16 @@
+/* PR middle-end/38200 */
+/* { dg-do compile } */
+/* { dg-options "-O2 -fno-strict-aliasing" } */
+
+typedef int (*callptr) (void);
+int foo (void **x);
+void foo2 (callptr *);
+int (*foo_ptr) (void **x) = foo;
+
+void
+bar (void)
+{
+  void *ptr;
+  foo2 ((callptr *) &ptr);
+  *(void **) &foo_ptr = ptr;
+}

	Jakub


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