public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH, committed, PR 42237] Fix assignments that copy gimple  register types from and to memory in IPA-SRA
@ 2009-12-01 17:55 Martin Jambor
  0 siblings, 0 replies; only message in thread
From: Martin Jambor @ 2009-12-01 17:55 UTC (permalink / raw)
  To: GCC Patches

Hi,

I have just committed the following patch which fixes PR 42237 and was
approved by Richi in bugzilla.  More inforation is in bugzilla too.

Bootstrapped and tested on x86_64-linux.

Thanks,

Martin


2009-12-01  Martin Jambor  <mjambor@suse.cz>

	PR tree-optimization/42237
	* tree-sra.c (sra_ipa_modify_assign): Split gimple_reg_type assignments
	in between references into two.

	* testsuite/gcc.c-torture/compile/pr42237.c: New test.

Index: mine/gcc/tree-sra.c
===================================================================
--- mine.orig/gcc/tree-sra.c
+++ mine/gcc/tree-sra.c
@@ -3707,12 +3707,22 @@ sra_ipa_modify_assign (gimple *stmt_ptr,
   any |= sra_ipa_modify_expr (lhs_p, gsi, true, data);
   if (any)
     {
+      tree new_rhs = NULL_TREE;
+
       if (!useless_type_conversion_p (TREE_TYPE (*lhs_p), TREE_TYPE (*rhs_p)))
+	new_rhs = fold_build1_loc (gimple_location (stmt), VIEW_CONVERT_EXPR,
+				   TREE_TYPE (*lhs_p), *rhs_p);
+      else if (REFERENCE_CLASS_P (*rhs_p)
+	       && is_gimple_reg_type (TREE_TYPE (*lhs_p))
+	       && !is_gimple_reg (*lhs_p))
+	/* This can happen when an assignment in between two single field
+	   structures is turned into an assignment in between two pointers to
+	   scalars (PR 42237).  */
+	new_rhs = *rhs_p;
+
+      if (new_rhs)
 	{
-	  location_t loc = gimple_location (stmt);
-	  tree vce = fold_build1_loc (loc, VIEW_CONVERT_EXPR,
-				      TREE_TYPE (*lhs_p), *rhs_p);
-	  tree tmp = force_gimple_operand_gsi (gsi, vce, true, NULL_TREE,
+	  tree tmp = force_gimple_operand_gsi (gsi, new_rhs, true, NULL_TREE,
 					       true, GSI_SAME_STMT);
 
 	  gimple_assign_set_rhs_from_tree (gsi, tmp);
Index: mine/gcc/testsuite/gcc.c-torture/compile/pr42237.c
===================================================================
--- /dev/null
+++ mine/gcc/testsuite/gcc.c-torture/compile/pr42237.c
@@ -0,0 +1,32 @@
+struct A
+{
+  int p;
+};
+
+struct B
+{
+  struct A n;
+  struct A m;
+  int x;
+  int y;
+  int z;
+};
+
+extern int g1, g2;
+
+static void __attribute__((noinline)) foo (struct B *b)
+{
+  int t;
+
+  t = b->n.p;
+  g1 = t;
+  b->n.p = t+1;
+  g2 = b->m.p;
+
+  b->m = b->n;
+}
+
+void bar (struct B *b)
+{
+  foo (b);
+}

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2009-12-01 17:42 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-12-01 17:55 [PATCH, committed, PR 42237] Fix assignments that copy gimple register types from and to memory in IPA-SRA Martin Jambor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).