re PR tree-optimization/71055 (FAIL: gcc.dg/torture/pr53663-1.c -Os execution...
authorRichard Biener <rguenther@suse.de>
Wed, 11 May 2016 14:04:32 +0000 (14:04 +0000)
committerRichard Biener <rguenth@gcc.gnu.org>
Wed, 11 May 2016 14:04:32 +0000 (14:04 +0000)
2016-05-11  Richard Biener  <rguenther@suse.de>

PR tree-optimization/71055
* tree-ssa-sccvn.c (vn_reference_lookup_3): When native-interpreting
sth with precision not equal to access size verify we don't chop
off bits.

* gcc.dg/torture/pr71055.c: New testcase.

From-SVN: r236122

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/torture/pr71055.c [new file with mode: 0644]
gcc/tree-ssa-sccvn.c

index 233273270430e1053f3aa980b5fe79cdc31d9cc8..740a3f4fc2b0d910f22eda40bc06aa5244c99f30 100644 (file)
@@ -1,3 +1,10 @@
+2016-05-11  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/71055
+       * tree-ssa-sccvn.c (vn_reference_lookup_3): When native-interpreting
+       sth with precision not equal to access size verify we don't chop
+       off bits.
+
 2016-05-11  Richard Biener  <rguenther@suse.de>
 
        PR debug/71057
index 4f7f0f86788e75b152dac1911b923963679458ff..91703474055341ab3964b3797a4d1f2607b046ea 100644 (file)
@@ -1,3 +1,8 @@
+2016-05-11  Richard Biener  <rguenther@suse.de>
+
+       PR tree-optimization/71055
+       * gcc.dg/torture/pr71055.c: New testcase.
+
 2016-05-11  Richard Biener  <rguenther@suse.de>
 
        PR debug/71057
diff --git a/gcc/testsuite/gcc.dg/torture/pr71055.c b/gcc/testsuite/gcc.dg/torture/pr71055.c
new file mode 100644 (file)
index 0000000..7fe5a71
--- /dev/null
@@ -0,0 +1,18 @@
+/* { dg-do run } */
+
+extern void abort (void);
+union U { int i; _Bool b; char c; };
+void __attribute__((noinline,noclone))
+foo (union U *u)
+{
+  if (u->c != 0)
+    abort ();
+}
+int main()
+{
+  union U u;
+  u.i = 10;
+  u.b = 0;
+  foo (&u);
+  return 0;
+}
index 63441178deaa28b84fb51771fd9ad79232bd899e..1567fb96afb4a392335914714ab485091a2e37d5 100644 (file)
@@ -1907,14 +1907,34 @@ vn_reference_lookup_3 (ao_ref *ref, tree vuse, void *vr_,
                                    buffer, sizeof (buffer));
          if (len > 0)
            {
-             tree val = native_interpret_expr (vr->type,
+             tree type = vr->type;
+             /* Make sure to interpret in a type that has a range
+                covering the whole access size.  */
+             if (INTEGRAL_TYPE_P (vr->type)
+                 && 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),
                                                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
+                reads but not when called from the DSE code during
+                elimination.  */
+             if (val
+                 && type != vr->type)
+               {
+                 if (! int_fits_type_p (val, vr->type))
+                   val = NULL_TREE;
+                 else
+                   val = fold_convert (vr->type, val);
+               }
+
              if (val)
                return vn_reference_lookup_or_insert_for_pieces
-                        (vuse, vr->set, vr->type, vr->operands, val);
+                        (vuse, vr->set, vr->type, vr->operands, val);
            }
        }
     }