[PATCH, PR 40432] In sra_modify_assign, force gimple operand also when creating a VCE

Martin Jambor mjambor@suse.cz
Tue Jun 16 09:58:00 GMT 2009


Hi,

this patch fixes PR 40432.  The problem is that we also may need to
force gimple operand when we create a V_C_E as the new RHS.

Bootstrapped and tested on x86_64-linux.

OK for trunk?

Thanks,

Martin


2009-06-15  Martin Jambor  <mjambor@suse.cz>

	PR tree-optimization/40432
	* tree-sra.c (sra_modify_assign): When creating VIEW_CONVERT_EXPR,
	check whether we need to force gimple register operand.

	* testsuite/gcc.c-torture/compile/pr40432.c: New file.

Index: mine/gcc/tree-sra.c
===================================================================
--- mine.orig/gcc/tree-sra.c	2009-06-14 22:05:35.000000000 +0200
+++ mine/gcc/tree-sra.c	2009-06-14 22:43:08.000000000 +0200
@@ -2097,7 +2097,11 @@ sra_modify_assign (gimple *stmt, gimple_
 		rhs = expr;
 	    }
 	  if (!useless_type_conversion_p (TREE_TYPE (lhs), TREE_TYPE (rhs)))
-	    rhs = fold_build1 (VIEW_CONVERT_EXPR, TREE_TYPE (lhs), rhs);
+	    {
+	      rhs = fold_build1 (VIEW_CONVERT_EXPR, TREE_TYPE (lhs), rhs);
+	      if (!is_gimple_reg (lhs))
+		force_gimple_rhs = true;
+	    }
 	}
 
       if (force_gimple_rhs)
Index: mine/gcc/testsuite/gcc.c-torture/compile/pr40432.c
===================================================================
--- /dev/null	1970-01-01 00:00:00.000000000 +0000
+++ mine/gcc/testsuite/gcc.c-torture/compile/pr40432.c	2009-06-15 00:28:52.000000000 +0200
@@ -0,0 +1,17 @@
+/* Test that SRA produces valid gimple when handling both type punning by means
+   of VCE and creating an access to a union.  */
+
+union U {
+  struct something *sth;
+  void *nothing;
+};
+
+void
+foo (union U *target, void *p)
+{
+  union U u;
+
+  u.nothing = p;
+  *target = u;
+  return;
+}



More information about the Gcc-patches mailing list