From 983acf87d6ce85034448b8f654de457c50617090 Mon Sep 17 00:00:00 2001 From: Jan Hubicka Date: Thu, 13 Jun 2019 17:00:41 +0200 Subject: [PATCH] re PR tree-optimization/90869 (Non-disambiguated memory accesses) 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 | 7 ++++++ gcc/testsuite/ChangeLog | 5 ++++ .../g++.dg/tree-ssa/alias-access-path-1.C | 24 +++++++++++++++++++ gcc/tree-ssa-alias.c | 21 ++++++++++++---- 4 files changed, 52 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/g++.dg/tree-ssa/alias-access-path-1.C diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 685c06d76b8..8ca14720788 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2019-06-13 Jan Hubicka + + 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 PR tree-optimization/90856 diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index b1d8ecc6465..62919d5d41e 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2019-06-13 Jan Hubicka + + PR tree-optimization/90869 + * g++.dg/tree-ssa/alias-access-path-1.C: New testcase. + 2019-06-13 Richard Biener 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 index 00000000000..ceb0e70ff68 --- /dev/null +++ b/gcc/testsuite/g++.dg/tree-ssa/alias-access-path-1.C @@ -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" } } */ diff --git a/gcc/tree-ssa-alias.c b/gcc/tree-ssa-alias.c index ebe05544bad..2d2b3b86cfd 100644 --- a/gcc/tree-ssa-alias.c +++ b/gcc/tree-ssa-alias.c @@ -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; } -- 2.30.2