From d5a1053a0d44116b1cbd887928276517ed8f458a Mon Sep 17 00:00:00 2001 From: Marc Glisse Date: Thu, 29 Nov 2012 16:40:16 +0100 Subject: [PATCH] re PR c++/53094 (constexpr vector subscripting) 2012-11-29 Marc Glisse PR c++/53094 gcc/ * fold-const.c (fold): Replace a CONSTRUCTOR with a VECTOR_CST. gcc/cp/ * cvt.c (ocp_convert): Call convert_to_vector. gcc/testsuite/ * g++.dg/ext/vector20.C: New testcase. From-SVN: r193938 --- gcc/ChangeLog | 5 +++++ gcc/cp/ChangeLog | 5 +++++ gcc/cp/cvt.c | 2 ++ gcc/fold-const.c | 29 +++++++++++++++++++++++++++++ gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/g++.dg/ext/vector20.C | 7 +++++++ 6 files changed, 53 insertions(+) create mode 100644 gcc/testsuite/g++.dg/ext/vector20.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index b45e6e32db4..8ca3588b3ee 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,8 @@ +2012-11-29 Marc Glisse + + PR c++/53094 + * fold-const.c (fold): Replace a CONSTRUCTOR with a VECTOR_CST. + 2012-11-29 Richard Biener * tree-ssa-pre.c (get_expr_value_id): Do not add expr diff --git a/gcc/cp/ChangeLog b/gcc/cp/ChangeLog index 4f240e9f3b6..d8d958a579c 100644 --- a/gcc/cp/ChangeLog +++ b/gcc/cp/ChangeLog @@ -1,3 +1,8 @@ +2012-11-29 Marc Glisse + + PR c++/53094 + * cvt.c (ocp_convert): Call convert_to_vector. + 2012-11-29 Kai Tietz PR target/53912 diff --git a/gcc/cp/cvt.c b/gcc/cp/cvt.c index 1dc789855cc..4ba7642db20 100644 --- a/gcc/cp/cvt.c +++ b/gcc/cp/cvt.c @@ -690,6 +690,8 @@ ocp_convert (tree type, tree expr, int convtype, int flags, conversion. */ else if (TREE_CODE (type) == COMPLEX_TYPE) return fold_if_not_in_template (convert_to_complex (type, e)); + else if (TREE_CODE (type) == VECTOR_TYPE) + return fold_if_not_in_template (convert_to_vector (type, e)); else if (TREE_CODE (e) == TARGET_EXPR) { /* Don't build a NOP_EXPR of class type. Instead, change the diff --git a/gcc/fold-const.c b/gcc/fold-const.c index e4693cdd16a..071fb8c15ab 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -14387,6 +14387,35 @@ fold (tree expr) return t; } + /* Return a VECTOR_CST if possible. */ + case CONSTRUCTOR: + { + tree type = TREE_TYPE (t); + if (TREE_CODE (type) != VECTOR_TYPE) + return t; + + tree *vec = XALLOCAVEC (tree, TYPE_VECTOR_SUBPARTS (type)); + unsigned HOST_WIDE_INT idx, pos = 0; + tree value; + + FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (t), idx, value) + { + if (!CONSTANT_CLASS_P (value)) + return t; + if (TREE_CODE (value) == VECTOR_CST) + { + for (unsigned i = 0; i < VECTOR_CST_NELTS (value); ++i) + vec[pos++] = VECTOR_CST_ELT (value, i); + } + else + vec[pos++] = value; + } + for (; pos < TYPE_VECTOR_SUBPARTS (type); ++pos) + vec[pos] = build_zero_cst (TREE_TYPE (type)); + + return build_vector (type, vec); + } + case CONST_DECL: return fold (DECL_INITIAL (t)); diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index d270ee0936e..4e623fb7df2 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2012-11-29 Marc Glisse + + PR c++/53094 + * g++.dg/ext/vector20.C: New testcase. + 2012-11-28 Tobias Burnus PR fortran/52161 diff --git a/gcc/testsuite/g++.dg/ext/vector20.C b/gcc/testsuite/g++.dg/ext/vector20.C new file mode 100644 index 00000000000..3d7c39250cf --- /dev/null +++ b/gcc/testsuite/g++.dg/ext/vector20.C @@ -0,0 +1,7 @@ +/* { dg-do compile } */ +/* { dg-options "-std=c++11" } */ + +typedef long vec __attribute__((vector_size (2 * sizeof (long)))); +constexpr vec v = { 3, 4 }; +constexpr vec s = v + v; +constexpr vec w = __builtin_shuffle (v, v);