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] Merge flow-sensitive info in merge_alias_info


This patch makes us merge flow-sensitive alias info in simple propagation
cases where we previously failed to do so.  I am not sure if this just
increases precision or also fixes correctness, so if it is appropriate
for stage3 or not.

Bootstrapped and tested on x86_64-unknown-linux-gnu, ok for mainline?

Thanks,
Richard.

2007-11-22  Richard Guenther  <rguenther@suse.de>

	* tree-ssa-copy.c (may_propagate_copy): Remove redundant
	checks.
	(merge_alias_info): Do verification only if checking is
	enabled.  Merge flow-sensitive alias information in simple
	cases.
	* tree-ssa-operands.c (get_addr_dereference_operands): Also
	complain about missing NMTs.

	* gcc.dg/tree-ssa/alias-17.c: New testcase.

Index: tree-ssa-operands.c
===================================================================
*** tree-ssa-operands.c	(revision 130328)
--- tree-ssa-operands.c	(working copy)
*************** get_addr_dereference_operands (tree stmt
*** 1643,1658 ****
  	  /* If we are emitting debugging dumps, display a warning if
  	     PTR is an SSA_NAME with no flow-sensitive alias
  	     information.  That means that we may need to compute
! 	     aliasing again.  */
  	  if (dump_file
  	      && TREE_CODE (ptr) == SSA_NAME
! 	      && pi == NULL)
  	    {
  	      fprintf (dump_file,
  		  "NOTE: no flow-sensitive alias info for ");
  	      print_generic_expr (dump_file, ptr, dump_flags);
  	      fprintf (dump_file, " in ");
! 	      print_generic_stmt (dump_file, stmt, dump_flags);
  	    }
  
  	  if (TREE_CODE (ptr) == SSA_NAME)
--- 1643,1660 ----
  	  /* If we are emitting debugging dumps, display a warning if
  	     PTR is an SSA_NAME with no flow-sensitive alias
  	     information.  That means that we may need to compute
! 	     aliasing again or that a propagation pass forgot to
! 	     update the alias information on the pointers.  */
  	  if (dump_file
  	      && TREE_CODE (ptr) == SSA_NAME
! 	      && (pi == NULL
! 		  || pi->name_mem_tag == NULL_TREE))
  	    {
  	      fprintf (dump_file,
  		  "NOTE: no flow-sensitive alias info for ");
  	      print_generic_expr (dump_file, ptr, dump_flags);
  	      fprintf (dump_file, " in ");
! 	      print_generic_stmt (dump_file, stmt, 0);
  	    }
  
  	  if (TREE_CODE (ptr) == SSA_NAME)
Index: testsuite/gcc.dg/tree-ssa/alias-17.c
===================================================================
*** testsuite/gcc.dg/tree-ssa/alias-17.c	(revision 0)
--- testsuite/gcc.dg/tree-ssa/alias-17.c	(revision 0)
***************
*** 0 ****
--- 1,18 ----
+ /* { dg-do compile } */
+ /* { dg-options "-O -fno-early-inlining -fdump-tree-ccp2" } */
+ 
+ int *p;
+ int inline bar(void) { return 0; }
+ int foo(int x)
+ {
+   int i;
+   int *q;
+   if (bar())
+     q = &i;
+   else
+     q = p;
+   return *q + *p;
+ }
+ 
+ /* { dg-final { scan-tree-dump-not "NOTE: no flow-sensitive alias info for" "ccp2" } } */
+ /* { dg-final { cleanup-tree-dump "ccp2" } } */
Index: tree-ssa-copy.c
===================================================================
*** tree-ssa-copy.c	(revision 130328)
--- tree-ssa-copy.c	(working copy)
*************** may_propagate_copy (tree dest, tree orig
*** 129,136 ****
        tree mt_orig = symbol_mem_tag (SSA_NAME_VAR (orig));
        if (mt_dest && mt_orig && mt_dest != mt_orig)
  	return false;
-       else if (!useless_type_conversion_p (type_d, type_o))
- 	return false;
        else if (get_alias_set (TREE_TYPE (type_d)) != 
  	       get_alias_set (TREE_TYPE (type_o)))
  	return false;
--- 129,134 ----
*************** merge_alias_info (tree orig_name, tree n
*** 217,247 ****
        return;
      }
  
!   gcc_assert (POINTER_TYPE_P (TREE_TYPE (orig_name)));
!   gcc_assert (POINTER_TYPE_P (TREE_TYPE (new_name)));
  
  #if defined ENABLE_CHECKING
    gcc_assert (useless_type_conversion_p (TREE_TYPE (orig_name),
  					TREE_TYPE (new_name)));
  
-   /* If the pointed-to alias sets are different, these two pointers
-      would never have the same memory tag.  In this case, NEW should
-      not have been propagated into ORIG.  */
-   gcc_assert (get_alias_set (TREE_TYPE (TREE_TYPE (new_sym)))
- 	      == get_alias_set (TREE_TYPE (TREE_TYPE (orig_sym))));
- #endif
- 
-   /* Synchronize the symbol tags.  If both pointers had a tag and they
-      are different, then something has gone wrong.  Symbol tags can
-      always be merged because they are flow insensitive, all the SSA
-      names of the same base DECL share the same symbol tag.  */
-   if (new_ann->symbol_mem_tag == NULL_TREE)
-     new_ann->symbol_mem_tag = orig_ann->symbol_mem_tag;
-   else if (orig_ann->symbol_mem_tag == NULL_TREE)
-     orig_ann->symbol_mem_tag = new_ann->symbol_mem_tag;
-   else
-     gcc_assert (new_ann->symbol_mem_tag == orig_ann->symbol_mem_tag);
- 
    /* Check that flow-sensitive information is compatible.  Notice that
       we may not merge flow-sensitive information here.  This function
       is called when propagating equivalences dictated by the IL, like
--- 215,227 ----
        return;
      }
  
!   gcc_assert (POINTER_TYPE_P (TREE_TYPE (orig_name))
! 	      && POINTER_TYPE_P (TREE_TYPE (new_name)));
  
  #if defined ENABLE_CHECKING
    gcc_assert (useless_type_conversion_p (TREE_TYPE (orig_name),
  					TREE_TYPE (new_name)));
  
    /* Check that flow-sensitive information is compatible.  Notice that
       we may not merge flow-sensitive information here.  This function
       is called when propagating equivalences dictated by the IL, like
*************** merge_alias_info (tree orig_name, tree n
*** 257,263 ****
  
       Since we cannot distinguish one case from another in this
       function, we can only make sure that if P_i and Q_j have
!      flow-sensitive information, they should be compatible.  */
    if (SSA_NAME_PTR_INFO (orig_name) && SSA_NAME_PTR_INFO (new_name))
      {
        struct ptr_info_def *orig_ptr_info = SSA_NAME_PTR_INFO (orig_name);
--- 237,247 ----
  
       Since we cannot distinguish one case from another in this
       function, we can only make sure that if P_i and Q_j have
!      flow-sensitive information, they should be compatible.
! 
!      As callers of merge_alias_info are supposed to call may_propagate_copy
!      first, the following check is redundant.  Thus, only do it if checking
!      is enabled.  */
    if (SSA_NAME_PTR_INFO (orig_name) && SSA_NAME_PTR_INFO (new_name))
      {
        struct ptr_info_def *orig_ptr_info = SSA_NAME_PTR_INFO (orig_name);
*************** merge_alias_info (tree orig_name, tree n
*** 278,284 ****
  	gcc_assert (bitmap_intersect_p (new_ptr_info->pt_vars,
  					orig_ptr_info->pt_vars));
      }
! }   
  
  
  /* Common code for propagate_value and replace_exp.
--- 262,294 ----
  	gcc_assert (bitmap_intersect_p (new_ptr_info->pt_vars,
  					orig_ptr_info->pt_vars));
      }
! #endif
! 
!   /* Synchronize the symbol tags.  If both pointers had a tag and they
!      are different, then something has gone wrong.  Symbol tags can
!      always be merged because they are flow insensitive, all the SSA
!      names of the same base DECL share the same symbol tag.  */
!   if (new_ann->symbol_mem_tag == NULL_TREE)
!     new_ann->symbol_mem_tag = orig_ann->symbol_mem_tag;
!   else if (orig_ann->symbol_mem_tag == NULL_TREE)
!     orig_ann->symbol_mem_tag = new_ann->symbol_mem_tag;
!   else
!     gcc_assert (new_ann->symbol_mem_tag == orig_ann->symbol_mem_tag);
! 
!   /* Copy flow-sensitive alias information in case that NEW_NAME
!      didn't get a NMT but was set to pt_anything for optimization
!      purposes.  In case ORIG_NAME has a NMT we can safely use its
!      flow-sensitive alias information as a conservative estimate.  */
!   if (SSA_NAME_PTR_INFO (orig_name)
!       && SSA_NAME_PTR_INFO (orig_name)->name_mem_tag
!       && (!SSA_NAME_PTR_INFO (new_name)
! 	  || !SSA_NAME_PTR_INFO (new_name)->name_mem_tag))
!     {
!       struct ptr_info_def *orig_ptr_info = SSA_NAME_PTR_INFO (orig_name);
!       struct ptr_info_def *new_ptr_info = get_ptr_info (new_name);
!       memcpy (new_ptr_info, orig_ptr_info, sizeof (struct ptr_info_def));
!     }
! }
  
  
  /* Common code for propagate_value and replace_exp.


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