003890
2016-11-02  Will Schmidt <will_schmidt@vnet.ibm.com>
003890
003890
	Backport from trunk
003890
	2016-10-26  Will Schmidt <will_schmidt@vnet.ibm.com>
003890
003890
	PR middle-end/72747
003890
	* gimplify.c (gimplify_init_constructor): Move emit of constructor
003890
	assignment to earlier in the if/else logic.
003890
003890
	* c-c++-common/pr72747-1.c: New test.
003890
	* c-c++-common/pr72747-2.c: Likewise.
003890
003890
--- gcc/gimplify.c	(revision 241792)
003890
+++ gcc/gimplify.c	(revision 241793)
003890
@@ -4273,24 +4273,23 @@ gimplify_init_constructor (tree *expr_p,
003890
 
003890
   if (ret == GS_ERROR)
003890
     return GS_ERROR;
003890
-  else if (want_value)
003890
+  /* If we have gimplified both sides of the initializer but have
003890
+     not emitted an assignment, do so now.  */
003890
+  if (*expr_p)
003890
+    {
003890
+      tree lhs = TREE_OPERAND (*expr_p, 0);
003890
+      tree rhs = TREE_OPERAND (*expr_p, 1);
003890
+      gimple init = gimple_build_assign (lhs, rhs);
003890
+      gimplify_seq_add_stmt (pre_p, init);
003890
+    }
003890
+  if (want_value)
003890
     {
003890
       *expr_p = object;
003890
       return GS_OK;
003890
     }
003890
   else
003890
     {
003890
-      /* If we have gimplified both sides of the initializer but have
003890
-	 not emitted an assignment, do so now.  */
003890
-      if (*expr_p)
003890
-	{
003890
-	  tree lhs = TREE_OPERAND (*expr_p, 0);
003890
-	  tree rhs = TREE_OPERAND (*expr_p, 1);
003890
-	  gimple init = gimple_build_assign (lhs, rhs);
003890
-	  gimplify_seq_add_stmt (pre_p, init);
003890
-	  *expr_p = NULL;
003890
-	}
003890
-
003890
+      *expr_p = NULL;
003890
       return GS_ALL_DONE;
003890
     }
003890
 }
003890
--- gcc/testsuite/c-c++-common/pr72747-1.c	(nonexistent)
003890
+++ gcc/testsuite/c-c++-common/pr72747-1.c	(revision 241793)
003890
@@ -0,0 +1,16 @@
003890
+/* { dg-do compile } */
003890
+/* { dg-require-effective-target powerpc_altivec_ok } */
003890
+/* { dg-options "-maltivec -fdump-tree-gimple" } */
003890
+
003890
+/* PR 72747: Test that cascaded definition is happening for constant vectors. */
003890
+
003890
+#include <altivec.h>
003890
+
003890
+int main (int argc, char *argv[])
003890
+{
003890
+	__vector int v1,v2;
003890
+	v1 = v2 = vec_splats ((int) 42);
003890
+	return 0;
003890
+}
003890
+/* { dg-final { scan-tree-dump-times " v2 = { 42, 42, 42, 42 }" 1 "gimple" } } */
003890
+
003890
--- gcc/testsuite/c-c++-common/pr72747-2.c	(nonexistent)
003890
+++ gcc/testsuite/c-c++-common/pr72747-2.c	(revision 241793)
003890
@@ -0,0 +1,18 @@
003890
+/* { dg-do compile } */
003890
+/* { dg-require-effective-target powerpc_altivec_ok } */
003890
+/* { dg-options "-c -maltivec -fdump-tree-gimple" } */
003890
+
003890
+/* PR 72747: test that cascaded definition is happening for non constants. */
003890
+
003890
+void foo ()
003890
+{
003890
+  extern int i;
003890
+  __vector int v,w;
003890
+    v = w = (vector int) { i };
003890
+}
003890
+
003890
+int main (int argc, char *argv[])
003890
+{
003890
+  return 0;
003890
+}
003890
+/* { dg-final { scan-tree-dump-times " w = " 1 "gimple" } } */