Hi! This PR is the fold-const.c counterpart of the match.pd PR85195, we first check if the result type is either the element type or vector type with the same element type, and then for extraction of a single element simply assume that the result must be the element type; it could be single element vector with that element type too though.
Fixed thusly, bootstrapped/regtested on x86_64-linux and i686-linux, ok for trunk? 2018-04-19 Jakub Jelinek <ja...@redhat.com> PR tree-optimization/85467 * fold-const.c (fold_ternary_loc) <case BIT_FIELD_REF>: Use VECTOR_TYPE_P macro. If type is vector type, VIEW_CONVERT_EXPR the VECTOR_CST element to type. * gcc.dg/pr85467.c: New test. --- gcc/fold-const.c.jj 2018-04-11 12:20:53.000000000 +0200 +++ gcc/fold-const.c 2018-04-19 14:34:30.410710684 +0200 @@ -11631,7 +11631,7 @@ fold_ternary_loc (location_t loc, enum t case BIT_FIELD_REF: if (TREE_CODE (arg0) == VECTOR_CST && (type == TREE_TYPE (TREE_TYPE (arg0)) - || (TREE_CODE (type) == VECTOR_TYPE + || (VECTOR_TYPE_P (type) && TREE_TYPE (type) == TREE_TYPE (TREE_TYPE (arg0)))) && tree_fits_uhwi_p (op1) && tree_fits_uhwi_p (op2)) @@ -11653,7 +11653,12 @@ fold_ternary_loc (location_t loc, enum t if (TREE_CODE (arg0) == VECTOR_CST) { if (n == 1) - return VECTOR_CST_ELT (arg0, idx); + { + tem = VECTOR_CST_ELT (arg0, idx); + if (VECTOR_TYPE_P (type)) + tem = fold_build1 (VIEW_CONVERT_EXPR, type, tem); + return tem; + } tree_vector_builder vals (type, n, 1); for (unsigned i = 0; i < n; ++i) --- gcc/testsuite/gcc.dg/pr85467.c.jj 2018-04-19 14:52:53.629273520 +0200 +++ gcc/testsuite/gcc.dg/pr85467.c 2018-04-19 14:51:57.348243306 +0200 @@ -0,0 +1,30 @@ +/* PR tree-optimization/85467 */ +/* { dg-do compile } */ +/* { dg-options "-O2 -fno-tree-ccp --param=sccvn-max-scc-size=10" } */ + +#define TEST(N, T) \ +typedef T V##N __attribute__ ((__vector_size__ (sizeof (T)))); \ + \ +V##N \ +bar##N (V##N u, V##N v) \ +{ \ + do \ + v *= (T)((V##N){}[0] ? u[v[0]] : 0); \ + while ((V##N){}[0]); \ + return v; \ +} \ + \ +void \ +foo##N (void) \ +{ \ + bar##N ((V##N){}, (V##N){}); \ +} + +TEST (1, char) +TEST (2, short) +TEST (3, int) +TEST (4, long) +TEST (5, long long) +#ifdef __SIZEOF_INT128__ +TEST (6, __int128) +#endif Jakub