This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
RFA: gimplify vector constructors that aren't initialiser constants
- From: Richard Sandiford <rsandifo at nildram dot co dot uk>
- To: gcc-patches at gcc dot gnu dot org
- Date: Mon, 29 Oct 2007 21:47:13 +0000
- Subject: RFA: gimplify vector constructors that aren't initialiser constants
This is a second attempt at fixing PR 33614. We currently don't gimplify
the contents of TREE_CONSTANT vector constructors, even if they need
run-time evaluation.
My first attempt at fixing this bug was based on the wrong assumption
that we had two types of vector constructors: those that could be turned
into VECTOR_CSTs and those that need run-time evaluation. Andrew pointed
out that there's a third category: vector constructors that can't be
reduced to a VECTOR_CST but that are legitimate initialiser constants
(e.g. those involving ADDR_EXPRs). We want to continue to treat those
constructors as TREE_CONSTANT.
The patch below therefore adds an initializer_constant_valid_p check
to the code that is trying to keep TREE_CONSTANT constructors. If this
check fails, we turn the constructor into a nonconstant value and
gimplify the contents.
Bootstrapped & regression-tested on x86_64-linux-gnu. Also regression
tested on mipsisa32-elf and mipsisa64-elf. It fixes an ICE in
compile/20050113-1.c for mipsisa32-elf and an ICE the attached
testcase for x86_64-linux-gnu. OK to install?
Richard
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.
Index: gcc/gimplify.c
===================================================================
--- gcc/gimplify.c 2007-10-29 21:31:03.000000000 +0000
+++ gcc/gimplify.c 2007-10-29 21:31:07.000000000 +0000
@@ -3290,8 +3290,9 @@ gimplify_init_constructor (tree *expr_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,
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
Index: gcc/testsuite/gcc.c-torture/compile/pr33614.c
===================================================================
--- /dev/null 2007-10-29 07:32:19.552097000 +0000
+++ gcc/testsuite/gcc.c-torture/compile/pr33614.c 2007-10-29 21:31:09.000000000 +0000
@@ -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;
+}