This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Aliasing: look through pointer's def stmt


Hello,

I noticed that in some cases we were failing to find aliasing information because we were only looking at an SSA_NAME variable, missing the fact that it was really an ADDR_EXPR. The attached patch passes bootstrap+testsuite, does it make sense? (I am a bit afraid of losing some type information for instance)

I didn't investigate the 2 tests where I had to remove dg-bogus, because removing dg-bogus sounds like a bonus...

2013-10-25  Marc Glisse  <marc.glisse@inria.fr>

gcc/
	* tree-ssa-alias.c (ao_ref_init_from_ptr_and_size): Look for an
	ADDR_EXPR in the defining statement.

gcc/testsuite/
	* gcc.dg/tree-ssa/alias-23.c: New file.
	* gcc.dg/vect/vect-ivdep-1.c: Remove dg-bogus.
	* gfortran.dg/vect/vect-do-concurrent-1.f90: Likewise.

--
Marc Glisse
Index: gcc/testsuite/gcc.dg/tree-ssa/alias-23.c
===================================================================
--- gcc/testsuite/gcc.dg/tree-ssa/alias-23.c	(revision 0)
+++ gcc/testsuite/gcc.dg/tree-ssa/alias-23.c	(working copy)
@@ -0,0 +1,18 @@
+/* { dg-do compile } */
+/* { dg-options "-O2 -fdump-tree-optimized" } */
+
+typedef struct A { int i; double d; } A;
+
+void f1 (const char *c)
+{
+  A *s = (A*) __builtin_malloc (sizeof (A));
+  double *p = &s->d;
+  s->i = 42;
+  __builtin_memcpy (p, c, sizeof (double));
+  int j = s->i;
+  if (j != 42) __builtin_abort();
+}
+
+/* { dg-final { scan-tree-dump-not "abort" "optimized" } } */
+/* { dg-final { cleanup-tree-dump "optimized" } } */
+

Property changes on: gcc/testsuite/gcc.dg/tree-ssa/alias-23.c
___________________________________________________________________
Added: svn:eol-style
## -0,0 +1 ##
+native
\ No newline at end of property
Added: svn:keywords
## -0,0 +1 ##
+Author Date Id Revision URL
\ No newline at end of property
Index: gcc/testsuite/gcc.dg/vect/vect-ivdep-1.c
===================================================================
--- gcc/testsuite/gcc.dg/vect/vect-ivdep-1.c	(revision 204044)
+++ gcc/testsuite/gcc.dg/vect/vect-ivdep-1.c	(working copy)
@@ -8,12 +8,11 @@
 void foo(int n, int *a, int *b, int *c, int *d, int *e) {
   int i, j;
 #pragma GCC ivdep
   for (i = 0; i < n; ++i) {
     a[i] = b[i] + c[i];
   }
 }
 
 /* { dg-message "loop vectorized" "" { target *-*-* } 0 } */
 /* { dg-bogus "version" "" { target *-*-* } 0 } */
-/* { dg-bogus "alias" "" { target *-*-* } 0 } */
 /* { dg-final { cleanup-tree-dump "vect" } } */
Index: gcc/testsuite/gfortran.dg/vect/vect-do-concurrent-1.f90
===================================================================
--- gcc/testsuite/gfortran.dg/vect/vect-do-concurrent-1.f90	(revision 204044)
+++ gcc/testsuite/gfortran.dg/vect/vect-do-concurrent-1.f90	(working copy)
@@ -6,12 +6,11 @@ subroutine test(n, a, b, c)
   integer, value :: n
   real, contiguous,  pointer :: a(:), b(:), c(:)
   integer :: i
   do concurrent (i = 1:n)
     a(i) = b(i) + c(i)
   end do
 end subroutine test
 
 ! { dg-message "loop vectorized" "" { target *-*-* } 0 }
 ! { dg-bogus "version" "" { target *-*-* } 0 }
-! { dg-bogus "alias" "" { target *-*-* } 0 }
 ! { dg-final { cleanup-tree-dump "vect" } }
Index: gcc/tree-ssa-alias.c
===================================================================
--- gcc/tree-ssa-alias.c	(revision 204044)
+++ gcc/tree-ssa-alias.c	(working copy)
@@ -561,20 +561,29 @@ ao_ref_alias_set (ao_ref *ref)
 /* Init an alias-oracle reference representation from a gimple pointer
    PTR and a gimple size SIZE in bytes.  If SIZE is NULL_TREE the the
    size is assumed to be unknown.  The access is assumed to be only
    to or after of the pointer target, not before it.  */
 
 void
 ao_ref_init_from_ptr_and_size (ao_ref *ref, tree ptr, tree size)
 {
   HOST_WIDE_INT t1, t2;
   ref->ref = NULL_TREE;
+  if (TREE_CODE (ptr) == SSA_NAME)
+    {
+      gimple stmt = SSA_NAME_DEF_STMT (ptr);
+      if (gimple_assign_single_p (stmt)
+	  && !gimple_has_volatile_ops (stmt)
+	  && gimple_assign_rhs_code (stmt) == ADDR_EXPR)
+	ptr = gimple_assign_rhs1 (stmt);
+    }
+
   if (TREE_CODE (ptr) == ADDR_EXPR)
     ref->base = get_ref_base_and_extent (TREE_OPERAND (ptr, 0),
 					 &ref->offset, &t1, &t2);
   else
     {
       ref->base = build2 (MEM_REF, char_type_node,
 			  ptr, null_pointer_node);
       ref->offset = 0;
     }
   if (size

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]