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][4.3] Fix PR36343 (wrong TBAA pruning)


On the trunk this was fixed by the PTA / call-clobbering rewrite.
For the branch I propose to disable TBAA pruning of points-to-sets
with the following patch which we use since some month for openSUSE.

Boostrapped and tested many times on x86_64 and other openSUSE archs.

As the bug was opened by me with an artificial testcase I am waiting
for some feedback on whether this is appropriate for the branch.

Thanks,
Richard.

2008-05-27  Richard Guenther  <rguenther@suse.de>

	PR tree-optimization/36343
	* tree-ssa-structalias.c (struct variable_info): Remove
	directly_dereferenced member.
	(new_var_info): Do not set it.
	(process_constraint_1): Likewise.
	(set_uids_in_ptset): Remove TBAA-pruning code.
	(find_what_p_points_to): Do not pass TBAA-pruning related
	parameters.

	* gcc.c-torture/execute/pr36343.c: New testcase.

Index: gcc/testsuite/gcc.c-torture/execute/pr36343.c
===================================================================
*** gcc/testsuite/gcc.c-torture/execute/pr36343.c	(revision 0)
--- gcc/testsuite/gcc.c-torture/execute/pr36343.c	(revision 0)
***************
*** 0 ****
--- 1,31 ----
+ extern void abort (void);
+ 
+ void __attribute__((noinline))
+ bar (int **p)
+ {
+   float *q = (float *)p;
+   *q = 0.0;
+ }
+ 
+ float __attribute__((noinline))
+ foo (int b)
+ {
+   int *i = 0;
+   float f = 1.0;
+   int **p;
+   if (b)
+     p = &i;
+   else
+     p = (int **)&f;
+   bar (p);
+   if (b)
+     return **p;
+   return f;
+ }
+ 
+ int main()
+ {
+   if (foo(0) != 0.0)
+     abort ();
+   return 0;
+ }
Index: gcc/tree-ssa-structalias.c
===================================================================
*** gcc/tree-ssa-structalias.c	(revision 135974)
--- gcc/tree-ssa-structalias.c	(working copy)
*************** struct variable_info
*** 227,237 ****
    /* A link to the variable for the next field in this structure.  */
    struct variable_info *next;
  
-   /* True if the variable is directly the target of a dereference.
-      This is used to track which variables are *actually* dereferenced
-      so we can prune their points to listed. */
-   unsigned int directly_dereferenced:1;
- 
    /* True if this is a variable created by the constraint analysis, such as
       heap variables and constraints we had to break up.  */
    unsigned int is_artificial_var:1;
--- 227,232 ----
*************** new_var_info (tree t, unsigned int id, c
*** 364,370 ****
    ret->id = id;
    ret->name = name;
    ret->decl = t;
-   ret->directly_dereferenced = false;
    ret->is_artificial_var = false;
    ret->is_heap_var = false;
    ret->is_special_var = false;
--- 359,364 ----
*************** process_constraint_1 (constraint_t t, bo
*** 2525,2538 ****
    gcc_assert (rhs.var < VEC_length (varinfo_t, varmap));
    gcc_assert (lhs.var < VEC_length (varinfo_t, varmap));
  
-   if (!from_call)
-     {
-       if (lhs.type == DEREF)
- 	get_varinfo (lhs.var)->directly_dereferenced = true;
-       if (rhs.type == DEREF)
- 	get_varinfo (rhs.var)->directly_dereferenced = true;
-     }
- 
    if (!use_field_sensitive)
      {
        t->rhs.offset = 0;
--- 2519,2524 ----
*************** shared_bitmap_add (bitmap pt_vars)
*** 4728,4747 ****
     the from set.  */
  
  static void
! set_uids_in_ptset (tree ptr, bitmap into, bitmap from, bool is_derefed,
! 		   bool no_tbaa_pruning)
  {
    unsigned int i;
    bitmap_iterator bi;
-   alias_set_type ptr_alias_set;
  
    gcc_assert (POINTER_TYPE_P (TREE_TYPE (ptr)));
-   ptr_alias_set = get_alias_set (TREE_TYPE (TREE_TYPE (ptr)));
  
    EXECUTE_IF_SET_IN_BITMAP (from, 0, i, bi)
      {
        varinfo_t vi = get_varinfo (i);
-       alias_set_type var_alias_set;
  
        /* The only artificial variables that are allowed in a may-alias
  	 set are heap variables.  */
--- 4714,4729 ----
     the from set.  */
  
  static void
! set_uids_in_ptset (tree ptr, bitmap into, bitmap from)
  {
    unsigned int i;
    bitmap_iterator bi;
  
    gcc_assert (POINTER_TYPE_P (TREE_TYPE (ptr)));
  
    EXECUTE_IF_SET_IN_BITMAP (from, 0, i, bi)
      {
        varinfo_t vi = get_varinfo (i);
  
        /* The only artificial variables that are allowed in a may-alias
  	 set are heap variables.  */
*************** set_uids_in_ptset (tree ptr, bitmap into
*** 4793,4833 ****
  		      && vi->size <= SFT_OFFSET (sft) - vi->offset)
  		    break;
  
! 		  var_alias_set = get_alias_set (sft);
! 		  if (no_tbaa_pruning
! 		      || (!is_derefed && !vi->directly_dereferenced)
! 		      || alias_sets_conflict_p (ptr_alias_set, var_alias_set))
! 		    {
! 		      bitmap_set_bit (into, DECL_UID (sft));
! 		      
! 		      /* Pointed-to SFTs are needed by the operand scanner
! 			 to adjust offsets when adding operands to memory
! 			 expressions that dereference PTR.  This means
! 			 that memory partitioning may not partition
! 			 this SFT because the operand scanner will not
! 			 be able to find the other SFTs next to this
! 			 one.  But we only need to do this if the pointed
! 			 to type is aggregate.  */
! 		      if (SFT_BASE_FOR_COMPONENTS_P (sft))
! 			SFT_UNPARTITIONABLE_P (sft) = true;
! 		    }
  		}
  	    }
  	  else
! 	    {
! 	      /* Otherwise, just add VI->DECL to the alias set.
! 		 Don't type prune artificial vars.  */
! 	      if (vi->is_artificial_var)
! 		bitmap_set_bit (into, DECL_UID (vi->decl));
! 	      else
! 		{
! 		  var_alias_set = get_alias_set (vi->decl);
! 		  if (no_tbaa_pruning
! 		      || (!is_derefed && !vi->directly_dereferenced)
! 		      || alias_sets_conflict_p (ptr_alias_set, var_alias_set))
! 		    bitmap_set_bit (into, DECL_UID (vi->decl));
! 		}
! 	    }
  	}
      }
  }
--- 4775,4796 ----
  		      && vi->size <= SFT_OFFSET (sft) - vi->offset)
  		    break;
  
! 		  bitmap_set_bit (into, DECL_UID (sft));
! 
! 		  /* Pointed-to SFTs are needed by the operand scanner
! 		     to adjust offsets when adding operands to memory
! 		     expressions that dereference PTR.  This means
! 		     that memory partitioning may not partition
! 		     this SFT because the operand scanner will not
! 		     be able to find the other SFTs next to this
! 		     one.  But we only need to do this if the pointed
! 		     to type is aggregate.  */
! 		  if (SFT_BASE_FOR_COMPONENTS_P (sft))
! 		    SFT_UNPARTITIONABLE_P (sft) = true;
  		}
  	    }
  	  else
! 	    bitmap_set_bit (into, DECL_UID (vi->decl));
  	}
      }
  }
*************** find_what_p_points_to (tree p)
*** 5034,5042 ****
  	      pi->pt_global_mem = 1;
  	    }
  
! 	  set_uids_in_ptset (p, finished_solution, vi->solution,
! 			     vi->directly_dereferenced,
! 			     vi->no_tbaa_pruning);
  	  result = shared_bitmap_lookup (finished_solution);
  
  	  if (!result)
--- 4997,5003 ----
  	      pi->pt_global_mem = 1;
  	    }
  
! 	  set_uids_in_ptset (p, finished_solution, vi->solution);
  	  result = shared_bitmap_lookup (finished_solution);
  
  	  if (!result)


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