From: Jakub Jelinek Date: Mon, 25 Jun 2018 17:45:48 +0000 (+0200) Subject: backport: re PR tree-optimization/85257 (wrong code with -O -fno-tree-ccp and reading... X-Git-Tag: releases/gcc-6.5.0~191 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f094d95dbc4698dbdfd4b3b0490679f547cf6d41;p=thirdparty%2Fgcc.git backport: re PR tree-optimization/85257 (wrong code with -O -fno-tree-ccp and reading zeroed vector member) Backported from mainline 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 (offset - 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. From-SVN: r262094 --- diff --git a/gcc/ChangeLog b/gcc/ChangeLog index a2d2fce6d47b..d5e68d916467 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,6 +1,16 @@ 2018-06-25 Jakub Jelinek Backported from mainline + 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 + (offset - 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-06 Jakub Jelinek PR debug/85252 diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 5bb4e2acb470..6cc04ac26985 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -7358,7 +7358,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 07eeb6fb3996..db94bdc3fd9b 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,6 +1,11 @@ 2018-06-25 Jakub Jelinek Backported from mainline + 2018-04-07 Jakub Jelinek + + PR tree-optimization/85257 + * gcc.dg/pr85257.c: New test. + 2018-04-06 Jakub Jelinek PR debug/85252 diff --git a/gcc/testsuite/gcc.dg/pr85257.c b/gcc/testsuite/gcc.dg/pr85257.c new file mode 100644 index 000000000000..75fafd96fd3f --- /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__ ((noinline, noclone)) +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 15838975f371..0c648b2d051a 100644 --- a/gcc/tree-ssa-sccvn.c +++ b/gcc/tree-ssa-sccvn.c @@ -1814,8 +1814,9 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *vr_, int len; len = native_encode_expr (gimple_assign_rhs1 (def_stmt), - buffer, sizeof (buffer)); - if (len > 0) + buffer, sizeof (buffer), + (offset - offset2) / BITS_PER_UNIT); + if (len > 0 && len * BITS_PER_UNIT >= ref->size) { tree type = vr->type; /* Make sure to interpret in a type that has a range @@ -1824,10 +1825,7 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *vr_, && ref->size != TYPE_PRECISION (vr->type)) type = build_nonstandard_integer_type (ref->size, TYPE_UNSIGNED (type)); - tree val = native_interpret_expr (type, - buffer - + ((offset - offset2) - / BITS_PER_UNIT), + tree val = native_interpret_expr (type, buffer, ref->size / BITS_PER_UNIT); /* If we chop off bits because the types precision doesn't match the memory access size this is ok when optimizing