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]

[patch] for PR14784


Hello,

this PR is caused by the fact that we do not realize that
in

type *x;
struct {type *y,...} *z;

x = something;
use (z->y);

the definition x does not alias the use of z->y.  This is because
the pruning code in access_can_touch_variable requires the type of the
pruned variable not to be a pointer.  This however does not make much
sense to me -- the variable stands for itself, not the place it points
to, so there is no reason to handle pointers specially.

One problem that surfaced when I disabled the check is that heapvar
has pointer type, but we do not want it pruned here; this is easy to fix
by checking for it in access_can_touch_variable.

Another problem was PR 29156; that is now fixed.

Bootstrapped & regtested on i686 and x86_64.

Zdenek

	PR tree-optimization/14784
	* tree-flow.h (struct var_ann_d): Add is_heapvar bit.
	* tree-ssa-structalias.c (get_constraint_for,
	intra_create_variable_infos): Set is_heapvar.
	* tree-ssa-operands.c (access_can_touch_variable): Do not handle
	non-heapvar pointer variables specially.

	* gcc.dg/alias-10.c: New test.

Index: testsuite/gcc.dg/alias-10.c
===================================================================
*** testsuite/gcc.dg/alias-10.c	(revision 0)
--- testsuite/gcc.dg/alias-10.c	(revision 0)
***************
*** 0 ****
--- 1,32 ----
+ /* For PR tree-optimization/14784  */
+ 
+ /* { dg-do compile } */
+ /* { dg-options "-O2 -funswitch-loops -fdump-tree-unswitch-details" } */
+ 
+ typedef struct bitmap_element_def
+ {
+   unsigned int indx;
+ } bitmap_element;
+ 
+ typedef struct bitmap_head_def {
+     bitmap_element *first;
+     int using_obstack;
+ } bitmap_head;
+ typedef struct bitmap_head_def *bitmap;
+ 
+ bitmap_element *bitmap_free;
+ 
+ void foo (bitmap head, bitmap_element *elt)
+ {
+   while (1)
+     {
+       /* Alias analysis problems used to prevent us from recognizing
+ 	 that this condition is invariant.  */
+       if (head->using_obstack)
+ 	bitmap_free = elt;
+     }
+ }
+ 
+ 
+ /* { dg-final { scan-tree-dump-times "Unswitching" 1 "unswitch"} } */
+ /* { dg-final { cleanup-tree-dump "unswitch" } } */
Index: tree-flow.h
===================================================================
*** tree-flow.h	(revision 117900)
--- tree-flow.h	(working copy)
*************** struct var_ann_d GTY(())
*** 184,189 ****
--- 184,192 ----
       in the v_may_def list.  */
    unsigned in_v_may_def_list : 1;
  
+   /* True for HEAP and PARM_NOALIAS artificial variables.  */
+   unsigned is_heapvar : 1;
+ 
    /* An artificial variable representing the memory location pointed-to by
       all the pointer symbols that flow-insensitive alias analysis
       (mostly type-based) considers to be aliased.  If the variable is
Index: tree-ssa-structalias.c
===================================================================
*** tree-ssa-structalias.c	(revision 117900)
--- tree-ssa-structalias.c	(working copy)
*************** get_constraint_for (tree t, VEC (ce_s, h
*** 2731,2736 ****
--- 2731,2737 ----
  		  {		    
  		    heapvar = create_tmp_var_raw (ptr_type_node, "HEAP");
  		    DECL_EXTERNAL (heapvar) = 1;
+ 		    get_var_ann (heapvar)->is_heapvar = 1;
  		    if (referenced_vars)
  		      add_referenced_var (heapvar);
  		    heapvar_insert (t, heapvar);
*************** intra_create_variable_infos (void)
*** 4368,4373 ****
--- 4369,4375 ----
  	    {
  	      heapvar = create_tmp_var_raw (TREE_TYPE (TREE_TYPE (t)), 
  					    "PARM_NOALIAS");
+ 	      get_var_ann (heapvar)->is_heapvar = 1;
  	      DECL_EXTERNAL (heapvar) = 1;
  	      if (referenced_vars)
  		add_referenced_var (heapvar);
Index: tree-ssa-operands.c
===================================================================
*** tree-ssa-operands.c	(revision 117900)
--- tree-ssa-operands.c	(working copy)
*************** access_can_touch_variable (tree ref, tre
*** 1149,1159 ****
  	   && flag_strict_aliasing
  	   && TREE_CODE (ref) != INDIRECT_REF
  	   && !MTAG_P (alias)
  	   && (TREE_CODE (base) != INDIRECT_REF
  	       || TREE_CODE (TREE_TYPE (base)) != UNION_TYPE)
  	   && !AGGREGATE_TYPE_P (TREE_TYPE (alias))
  	   && TREE_CODE (TREE_TYPE (alias)) != COMPLEX_TYPE
- 	   && !POINTER_TYPE_P (TREE_TYPE (alias))
  	   /* When the struct has may_alias attached to it, we need not to
  	      return true.  */
  	   && get_alias_set (base))
--- 1149,1159 ----
  	   && flag_strict_aliasing
  	   && TREE_CODE (ref) != INDIRECT_REF
  	   && !MTAG_P (alias)
+ 	   && !var_ann (alias)->is_heapvar
  	   && (TREE_CODE (base) != INDIRECT_REF
  	       || TREE_CODE (TREE_TYPE (base)) != UNION_TYPE)
  	   && !AGGREGATE_TYPE_P (TREE_TYPE (alias))
  	   && TREE_CODE (TREE_TYPE (alias)) != COMPLEX_TYPE
  	   /* When the struct has may_alias attached to it, we need not to
  	      return true.  */
  	   && get_alias_set (base))


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