]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
backport: re PR tree-optimization/85257 (wrong code with -O -fno-tree-ccp and reading...
authorJakub Jelinek <jakub@redhat.com>
Mon, 25 Jun 2018 17:45:48 +0000 (19:45 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Mon, 25 Jun 2018 17:45:48 +0000 (19:45 +0200)
Backported from mainline
2018-04-07  Jakub Jelinek  <jakub@redhat.com>

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

gcc/ChangeLog
gcc/fold-const.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/pr85257.c [new file with mode: 0644]
gcc/tree-ssa-sccvn.c

index a2d2fce6d47be03877df62a249c1ac27038b8519..d5e68d9164679284251d21cd9796b529c8209793 100644 (file)
@@ -1,6 +1,16 @@
 2018-06-25  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2018-04-07  Jakub Jelinek  <jakub@redhat.com>
+
+       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  <jakub@redhat.com>
 
        PR debug/85252
index 5bb4e2acb470d1a3359aa1c022f6ae94e78fc006..6cc04ac26985cadb7e125458a5aa4259509c589c 100644 (file)
@@ -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;
     }
index 07eeb6fb39964249b82c9acdafc68bfac0587237..db94bdc3fd9b5b7efd930f756d44464bc2b0436d 100644 (file)
@@ -1,6 +1,11 @@
 2018-06-25  Jakub Jelinek  <jakub@redhat.com>
 
        Backported from mainline
+       2018-04-07  Jakub Jelinek  <jakub@redhat.com>
+
+       PR tree-optimization/85257
+       * gcc.dg/pr85257.c: New test.
+
        2018-04-06  Jakub Jelinek  <jakub@redhat.com>
 
        PR debug/85252
diff --git a/gcc/testsuite/gcc.dg/pr85257.c b/gcc/testsuite/gcc.dg/pr85257.c
new file mode 100644 (file)
index 0000000..75fafd9
--- /dev/null
@@ -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;
+}
index 15838975f3717288339999888400a6f7490e5635..0c648b2d051a14f691f56a833aa58de17902f1d9 100644 (file)
@@ -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