From bbb5358c5949c7770b1aca1834a1f3c03a13046c Mon Sep 17 00:00:00 2001 From: jakub Date: Sat, 7 Apr 2018 07:20:42 +0000 Subject: [PATCH] PR tree-optimization/85257 * fold-const.c (native_encode_vector): If not all elts could fit and off is -1, return 0 rather than offset. * tree-ssa-sccvn.c (vn_reference_lookup_3): Pass (offseti - offset2) / BITS_PER_UNIT as 4th argument to native_encode_expr. Verify len * BITS_PER_UNIT >= maxsizei. Don't adjust buffer in native_interpret_expr call. * gcc.dg/pr85257.c: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@259206 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 10 ++++++++++ gcc/fold-const.c | 2 +- gcc/testsuite/ChangeLog | 5 +++++ gcc/testsuite/gcc.dg/pr85257.c | 20 ++++++++++++++++++++ gcc/tree-ssa-sccvn.c | 10 ++++------ 5 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/gcc.dg/pr85257.c diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 1f0dff3f6ab..85cf26a8800 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,13 @@ +2018-04-07 Jakub Jelinek + + PR tree-optimization/85257 + * fold-const.c (native_encode_vector): If not all elts could fit + and off is -1, return 0 rather than offset. + * tree-ssa-sccvn.c (vn_reference_lookup_3): Pass + (offseti - offset2) / BITS_PER_UNIT as 4th argument to + native_encode_expr. Verify len * BITS_PER_UNIT >= maxsizei. Don't + adjust buffer in native_interpret_expr call. + 2018-04-07 Monk Chiang * config/nds32/constants.md (unspec_volatile_element): Add cache diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 3134f8e6383..3a99b66cf45 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -7307,7 +7307,7 @@ native_encode_vector (const_tree expr, unsigned char *ptr, int len, int off) return 0; offset += res; if (offset >= len) - return offset; + return (off == -1 && i < count - 1) ? 0 : offset; if (off != -1) off = 0; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index dad3874ff95..00ac96fca36 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2018-04-07 Jakub Jelinek + + PR tree-optimization/85257 + * gcc.dg/pr85257.c: New test. + 2018-04-06 Eric Botcazou * g++.dg/opt/pr85196.C: New test. diff --git a/gcc/testsuite/gcc.dg/pr85257.c b/gcc/testsuite/gcc.dg/pr85257.c new file mode 100644 index 00000000000..3bf07b3a5db --- /dev/null +++ b/gcc/testsuite/gcc.dg/pr85257.c @@ -0,0 +1,20 @@ +/* PR tree-optimization/85257 */ +/* { dg-do run { target int128 } } */ +/* { dg-options "-O2 -fno-tree-ccp" } */ + +typedef __int128 V __attribute__ ((__vector_size__ (16 * sizeof (__int128)))); + +__int128 __attribute__ ((noipa)) +foo (void) +{ + V v = { 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 }; + return v[5]; +} + +int +main () +{ + if (foo () != 6) + __builtin_abort (); + return 0; +} diff --git a/gcc/tree-ssa-sccvn.c b/gcc/tree-ssa-sccvn.c index 4e5f3385f9d..1463c1d4116 100644 --- a/gcc/tree-ssa-sccvn.c +++ b/gcc/tree-ssa-sccvn.c @@ -2038,8 +2038,9 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *vr_, if (TREE_CODE (rhs) == SSA_NAME) rhs = SSA_VAL (rhs); len = native_encode_expr (gimple_assign_rhs1 (def_stmt), - buffer, sizeof (buffer)); - if (len > 0) + buffer, sizeof (buffer), + (offseti - offset2) / BITS_PER_UNIT); + if (len > 0 && len * BITS_PER_UNIT >= maxsizei) { tree type = vr->type; /* Make sure to interpret in a type that has a range @@ -2048,10 +2049,7 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *vr_, && maxsizei != TYPE_PRECISION (vr->type)) type = build_nonstandard_integer_type (maxsizei, TYPE_UNSIGNED (type)); - tree val = native_interpret_expr (type, - buffer - + ((offseti - offset2) - / BITS_PER_UNIT), + tree val = native_interpret_expr (type, buffer, maxsizei / BITS_PER_UNIT); /* If we chop off bits because the types precision doesn't match the memory access size this is ok when optimizing -- 2.11.4.GIT