This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH][alias-improvements] Fix glitch get_deref_alias_set patch
- From: Richard Guenther <rguenther at suse dot de>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sun, 11 Jan 2009 19:30:51 +0100 (CET)
- Subject: [PATCH][alias-improvements] Fix glitch get_deref_alias_set patch
The patch that introduced get_deref_alias_set causes us to always fall
back to the base indirect-ref alias set. This was of course not intended.
The following fixes it and adds a testcase for the missed-optimization.
Bootstrapped and tested on x86_64-unknown-linux-gnu, applied to the
branch. This brings tramp3d performance back to trunk level. Yay.
Richard.
2009-01-11 Richard Guenther <rguenther@suse.de>
* tree-ssa-structalias.c (set_uids_in_ptset): Use get_deref_alias_set.
* alias.c (get_deref_alias_set_1): Split out from
(get_deref_alias_set): Fall back to access type alias-set here.
(get_alias_set): Use get_deref_alias_set_1.
* gcc.dg/tree-ssa/alias-20.c: New testcase.
Index: gcc/tree-ssa-structalias.c
===================================================================
*** gcc/tree-ssa-structalias.c (revision 143251)
--- gcc/tree-ssa-structalias.c (working copy)
*************** set_uids_in_ptset (tree ptr, bitmap into
*** 4789,4795 ****
{
alias_set_type var_alias_set, mem_alias_set;
var_alias_set = get_alias_set (vi->decl);
! mem_alias_set = get_alias_set (TREE_TYPE (TREE_TYPE (ptr)));
if (!may_alias_p (SSA_NAME_VAR (ptr), mem_alias_set,
vi->decl, var_alias_set))
{
--- 4794,4800 ----
{
alias_set_type var_alias_set, mem_alias_set;
var_alias_set = get_alias_set (vi->decl);
! mem_alias_set = get_deref_alias_set (ptr);
if (!may_alias_p (SSA_NAME_VAR (ptr), mem_alias_set,
vi->decl, var_alias_set))
{
Index: gcc/alias.c
===================================================================
*** gcc/alias.c (revision 143251)
--- gcc/alias.c (working copy)
*************** component_uses_parent_alias_set (const_t
*** 483,492 ****
}
/* Return the alias set for the memory pointed to by T, which may be
! either a type or an expression. */
! alias_set_type
! get_deref_alias_set (tree t)
{
/* If we're not doing any alias analysis, just assume everything
aliases everything else. */
--- 483,493 ----
}
/* Return the alias set for the memory pointed to by T, which may be
! either a type or an expression. Return -1 if there is nothing
! special about dereferencing T. */
! static alias_set_type
! get_deref_alias_set_1 (tree t)
{
/* If we're not doing any alias analysis, just assume everything
aliases everything else. */
*************** get_deref_alias_set (tree t)
*** 551,558 ****
|| TYPE_REF_CAN_ALIAS_ALL (t))
return 0;
/* Fall back to the alias-set of the pointed-to type. */
! return get_alias_set (TREE_TYPE (t));
}
/* Return the alias set for T, which may be either a type or an
--- 552,577 ----
|| TYPE_REF_CAN_ALIAS_ALL (t))
return 0;
+ return -1;
+ }
+
+ /* Return the alias set for the memory pointed to by T, which may be
+ either a type or an expression. */
+
+ alias_set_type
+ get_deref_alias_set (tree t)
+ {
+ alias_set_type set = get_deref_alias_set_1 (t);
+
/* Fall back to the alias-set of the pointed-to type. */
! if (set == -1)
! {
! if (! TYPE_P (t))
! t = TREE_TYPE (t);
! set = get_alias_set (TREE_TYPE (t));
! }
!
! return set;
}
/* Return the alias set for T, which may be either a type or an
*************** get_alias_set (tree t)
*** 596,602 ****
}
if (INDIRECT_REF_P (inner))
! return get_deref_alias_set (TREE_OPERAND (inner, 0));
/* Otherwise, pick up the outermost object that we could have a pointer
to, processing conversions as above. */
--- 615,625 ----
}
if (INDIRECT_REF_P (inner))
! {
! set = get_deref_alias_set_1 (TREE_OPERAND (inner, 0));
! if (set != -1)
! return set;
! }
/* Otherwise, pick up the outermost object that we could have a pointer
to, processing conversions as above. */
Index: gcc/testsuite/gcc.dg/tree-ssa/alias-20.c
===================================================================
*** gcc/testsuite/gcc.dg/tree-ssa/alias-20.c (revision 0)
--- gcc/testsuite/gcc.dg/tree-ssa/alias-20.c (revision 0)
***************
*** 0 ****
--- 1,24 ----
+ /* { dg-do compile } */
+ /* { dg-options "-O -fstrict-aliasing -fdump-tree-optimized" } */
+
+ struct S { float f; int i; };
+ struct R { int x; int i; };
+
+ /* Strict-aliasing rules say that int and float do not alias. */
+ int bar(struct S *s, int *i)
+ {
+ *i = 0;
+ s->f = 1.0;
+ return *i;
+ }
+
+ /* Strict-aliasing rules say that S and R do not alias. */
+ int foo(struct S *s, struct R *r)
+ {
+ r->i = 0;
+ s->f = 1.0;
+ return r->i;
+ }
+
+ /* { dg-final { scan-tree-dump-times "return 0;" 2 "optimized" } } */
+ /* { dg-final { cleanup-tree-dump "optimized" } } */