From 9f1da821e6de1d5068d8c03cd46d1b05aab799f1 Mon Sep 17 00:00:00 2001
From: Richard Sandiford <rsandifo@nildram.co.uk>
Date: Mon, 29 Oct 2007 22:01:24 +0000
Subject: [PATCH] re PR tree-optimization/33614 (ICE on semi-constant vector
 CONSTRUCTORs)

gcc/
	PR tree-optimization/33614
	* gimplify.c (gimplify_init_constructor): Gimplify vector constructors
	if they can't be reduced to VECTOR_CSTs and aren't legitimate
	initializer constants.

gcc/testsuite/
	PR tree-optimization/33614
	* gcc.c-torture/compile/pr33614.c: New test.

From-SVN: r129739
---
 gcc/ChangeLog                                 |  7 +++++++
 gcc/gimplify.c                                | 13 +++++++++----
 gcc/testsuite/ChangeLog                       |  5 +++++
 gcc/testsuite/gcc.c-torture/compile/pr33614.c |  9 +++++++++
 4 files changed, 30 insertions(+), 4 deletions(-)
 create mode 100644 gcc/testsuite/gcc.c-torture/compile/pr33614.c

diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 9899775fb38..a8d26816d8c 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,10 @@
+2007-10-29  Richard Sandiford  <rsandifo@nildram.co.uk>
+
+	PR tree-optimization/33614
+	* gimplify.c (gimplify_init_constructor): Gimplify vector constructors
+	if they can't be reduced to VECTOR_CSTs and aren't legitimate
+	initializer constants.
+
 2007-10-29  Richard Guenther  <rguenther@suse.de>
 
 	PR tree-optimization/33870
diff --git a/gcc/gimplify.c b/gcc/gimplify.c
index 038337732b5..5c11bad3a08 100644
--- a/gcc/gimplify.c
+++ b/gcc/gimplify.c
@@ -3290,8 +3290,9 @@ gimplify_init_constructor (tree *expr_p, tree *pre_p,
 	    tree value;
 
 	    /* Even when ctor is constant, it might contain non-*_CST
-	      elements (e.g. { 1.0/0.0 - 1.0/0.0, 0.0 }) and those don't
-	      belong into VECTOR_CST nodes.  */
+	       elements, such as addresses or trapping values like
+	       1.0/0.0 - 1.0/0.0.  Such expressions don't belong
+	       in VECTOR_CST nodes.  */
 	    FOR_EACH_CONSTRUCTOR_VALUE (elts, ix, value)
 	      if (!CONSTANT_CLASS_P (value))
 		{
@@ -3305,10 +3306,14 @@ gimplify_init_constructor (tree *expr_p, tree *pre_p,
 		break;
 	      }
 
-	    /* Don't reduce a TREE_CONSTANT vector ctor even if we can't
+	    /* Don't reduce an initializer constant even if we can't
 	       make a VECTOR_CST.  It won't do anything for us, and it'll
 	       prevent us from representing it as a single constant.  */
-	    break;
+	    if (initializer_constant_valid_p (ctor, type))
+	      break;
+
+	    TREE_CONSTANT (ctor) = 0;
+	    TREE_INVARIANT (ctor) = 0;
 	  }
 
 	/* Vector types use CONSTRUCTOR all the way through gimple
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index bde12e5fd65..db874d34f06 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,8 @@
+2007-10-29  Richard Sandiford  <rsandifo@nildram.co.uk>
+
+	PR tree-optimization/33614
+	* gcc.c-torture/compile/pr33614.c: New test.
+
 2007-10-29  Richard Guenther  <rguenther@suse.de>
 
 	PR tree-optimization/33870
diff --git a/gcc/testsuite/gcc.c-torture/compile/pr33614.c b/gcc/testsuite/gcc.c-torture/compile/pr33614.c
new file mode 100644
index 00000000000..2b835b9ddd1
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/compile/pr33614.c
@@ -0,0 +1,9 @@
+typedef float V2SF __attribute__ ((vector_size (8)));
+
+V2SF
+foo (int x, V2SF a)
+{
+  while (x--)
+    a += (V2SF) {1.0f/0.0f - 1.0f/0.0f, 1.0f/0.0f - 1.0f/0.0f};
+  return a;
+}