From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 2153) id B676D38618EE; Mon, 7 Jun 2021 07:29:40 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B676D38618EE MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Content-Type: text/plain; charset="utf-8" From: Jakub Jelinek To: gcc-cvs@gcc.gnu.org Subject: [gcc r12-1256] fold-const: Fix up fold_read_from_vector [PR100887] X-Act-Checkin: gcc X-Git-Author: Jakub Jelinek X-Git-Refname: refs/heads/master X-Git-Oldrev: d66a703c8ba86f3ca04cc10c3071696e6d014de6 X-Git-Newrev: e1521b170b44be5cd5d36a98b6b760457b68f566 Message-Id: <20210607072940.B676D38618EE@sourceware.org> Date: Mon, 7 Jun 2021 07:29:40 +0000 (GMT) X-BeenThere: gcc-cvs@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-cvs mailing list List-Unsubscribe: , List-Archive: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 07 Jun 2021 07:29:40 -0000 https://gcc.gnu.org/g:e1521b170b44be5cd5d36a98b6b760457b68f566 commit r12-1256-ge1521b170b44be5cd5d36a98b6b760457b68f566 Author: Jakub Jelinek Date: Mon Jun 7 09:28:31 2021 +0200 fold-const: Fix up fold_read_from_vector [PR100887] The callers of fold_read_from_vector expect that the index they pass is an index of an element in the vector and the function does that most of the time. But we allow CONSTRUCTORs with VECTOR_TYPE to have VECTOR_TYPE elements and in that case every CONSTRUCTOR element represents not just one index (with the exception of V1 vectors), but multiple. So returning zero vector if i >= CONSTRUCTOR_NELTS or returning some CONSTRUCTOR_ELT's value might not be what the callers expect. Fixed by punting if the first element has vector type. Bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? In theory we could instead recurse (and assert that for CONSTRUCTORs of vector elements we have always all elements specified like tree-cfg.c verifies?) after adjusting the index appropriately. 2021-06-07 Jakub Jelinek PR target/100887 * fold-const.c (fold_read_from_vector): Return NULL if trying to read from a CONSTRUCTOR with vector type elements. * gcc.dg/pr100887.c: New test. Diff: --- gcc/fold-const.c | 3 +++ gcc/testsuite/gcc.dg/pr100887.c | 14 ++++++++++++++ 2 files changed, 17 insertions(+) diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 33d64bfbbe8..6e5835aefaf 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -15471,6 +15471,9 @@ fold_read_from_vector (tree arg, poly_uint64 idx) return VECTOR_CST_ELT (arg, i); else if (TREE_CODE (arg) == CONSTRUCTOR) { + if (CONSTRUCTOR_NELTS (arg) + && VECTOR_TYPE_P (TREE_TYPE (CONSTRUCTOR_ELT (arg, 0)->value))) + return NULL_TREE; if (i >= CONSTRUCTOR_NELTS (arg)) return build_zero_cst (TREE_TYPE (TREE_TYPE (arg))); return CONSTRUCTOR_ELT (arg, i)->value; diff --git a/gcc/testsuite/gcc.dg/pr100887.c b/gcc/testsuite/gcc.dg/pr100887.c new file mode 100644 index 00000000000..de6b3effe13 --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr100887.c @@ -0,0 +1,14 @@ +/* PR target/100887 */ +/* { dg-do compile } */ +/* { dg-options "" } */ +/* { dg-additional-options "-mavx512f" { target { i?86-*-* x86_64-*-* } } } */ + +typedef unsigned long long __attribute__((__vector_size__ (2 * sizeof (long long)))) U; +typedef unsigned long long __attribute__((__vector_size__ (4 * sizeof (long long)))) V; +typedef unsigned long long __attribute__((__vector_size__ (8 * sizeof (long long)))) W; + +U +foo (V v) +{ + return __builtin_shufflevector ((W){}, v, 0, 8); +}