re PR tree-optimization/90869 (Non-disambiguated memory accesses)
authorJan Hubicka <hubicka@ucw.cz>
Thu, 13 Jun 2019 15:00:41 +0000 (17:00 +0200)
committerJan Hubicka <hubicka@gcc.gnu.org>
Thu, 13 Jun 2019 15:00:41 +0000 (15:00 +0000)
PR tree-optimize/90869
* tree-ssa-alias.c (indirect_ref_may_alias_decl_p): Watch for view
converts in MEM_REF referencing decl rather than view converts
from decl type to MEM_REF type.

* g++.dg/tree-ssa/alias-access-path-1.C: New testcase.

From-SVN: r272247

gcc/ChangeLog
gcc/testsuite/ChangeLog
gcc/testsuite/g++.dg/tree-ssa/alias-access-path-1.C [new file with mode: 0644]
gcc/tree-ssa-alias.c

index 685c06d76b857d289d408548b47c1e77cb7096d6..8ca14720788b9f598345deb24a3bf4f5c60e2a59 100644 (file)
@@ -1,3 +1,10 @@
+2019-06-13  Jan Hubicka  <hubicka@ucw.cz>
+
+       PR tree-optimization/90869
+       * tree-ssa-alias.c (indirect_ref_may_alias_decl_p): Watch for view
+       converts in MEM_REF referencing decl rather than view converts
+       from decl type to MEM_REF type.
+
 2019-06-13  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/90856
index b1d8ecc6465eb95346870659c177b0f85f438942..62919d5d41ef1dd9e54cc0988fa6c69f3d7d757a 100644 (file)
@@ -1,3 +1,8 @@
+2019-06-13  Jan Hubicka  <hubicka@ucw.cz>
+
+       PR tree-optimization/90869
+       * g++.dg/tree-ssa/alias-access-path-1.C: New testcase.
+
 2019-06-13  Richard Biener  <rguenther@suse.de>
 
        PR tree-optimization/90856
diff --git a/gcc/testsuite/g++.dg/tree-ssa/alias-access-path-1.C b/gcc/testsuite/g++.dg/tree-ssa/alias-access-path-1.C
new file mode 100644 (file)
index 0000000..ceb0e70
--- /dev/null
@@ -0,0 +1,24 @@
+/* { dg-do compile } */
+/* { dg-options "-O3 -fdump-tree-fre1" } */
+
+struct a {int a1; int a2;};
+struct b:a {};
+
+struct b bvar,*bptr2;
+int
+test(void)
+{
+  struct a *bptr = &bvar;
+  bptr->a2=0;
+  bptr2->a1=1;
+  return bptr->a2;
+}
+int
+test2(void)
+{
+  struct b *bptr = &bvar;
+  bptr->a2=0;
+  bptr2->a1=1;
+  return bptr->a2;
+}
+/* { dg-final { scan-tree-dump-times "return 0" 2 "fre1" } } */
index ebe05544bad09e0e61df3c075f13b62b8deada8a..2d2b3b86cfdafacb1e9ac8695c0cbb0dc8e0aab3 100644 (file)
@@ -1370,11 +1370,16 @@ indirect_ref_may_alias_decl_p (tree ref1 ATTRIBUTE_UNUSED, tree base1,
   poly_offset_int doffset2 = offset2;
   if (TREE_CODE (dbase2) == MEM_REF
       || TREE_CODE (dbase2) == TARGET_MEM_REF)
-    doffset2 -= mem_ref_offset (dbase2) << LOG2_BITS_PER_UNIT;
+    {
+      doffset2 -= mem_ref_offset (dbase2) << LOG2_BITS_PER_UNIT;
+      tree ptrtype2 = TREE_TYPE (TREE_OPERAND (dbase2, 1));
+      /* If second reference is view-converted, give up now.  */
+      if (same_type_for_tbaa (TREE_TYPE (dbase2), TREE_TYPE (ptrtype2)) != 1)
+       return true;
+    }
 
-  /* If either reference is view-converted, give up now.  */
-  if (same_type_for_tbaa (TREE_TYPE (base1), TREE_TYPE (ptrtype1)) != 1
-      || same_type_for_tbaa (TREE_TYPE (dbase2), TREE_TYPE (base2)) != 1)
+  /* If first reference is view-converted, give up now.  */
+  if (same_type_for_tbaa (TREE_TYPE (base1), TREE_TYPE (ptrtype1)) != 1)
     return true;
 
   /* If both references are through the same type, they do not alias
@@ -1408,7 +1413,13 @@ indirect_ref_may_alias_decl_p (tree ref1 ATTRIBUTE_UNUSED, tree base1,
                                      offset1, max_size1,
                                      ref2,
                                      ref2_alias_set, base2_alias_set,
-                                     offset2, max_size2, true);
+                                     offset2, max_size2, 
+                                     /* Only if the other reference is actual
+                                        decl we can safely check only toplevel
+                                        part of access path 1.  */
+                                     same_type_for_tbaa (TREE_TYPE (dbase2),
+                                                         TREE_TYPE (base2))
+                                     == 1);
 
   return true;
 }