[tree-ssa] TREE_ADDRESSABLE versus ARRAY_TYPE

Jan Hubicka hubicka@ucw.cz
Mon Jan 12 10:00:00 GMT 2004


> On Mon, Jan 12, 2004 at 10:40:04AM +0100, Jan Hubicka wrote:
> > For part of compiler TREE_ADDRESABLE flag means "address of this object
> > has been taken" while elsewhere it means "this object must live in
> > memory after RTL expansion".  It seems resonable to split these
> > meanings into different flags.
> 
> I'm comfortable with ARRAY_REF with non-constant index imply 
> addressability.  If Diego *really* cares otherwise...
OK, here is older version of the patch that doesn't implement the
new flag.  It also passed i686-pc-gnu-linux testing for me.

Hi,
at the moment we never promote arrays and clear their TREE_ADDRESABLE flag.
This is one of major causes of regressions caused by my patch to get rid of
ADDRESSOF flag.  The only reason for not clearing the flag is that expanders
attempts to place the array in registers and die miserably as soon as one
attempts to make nonconstant array reference (constant ones are translated into
shits).

The patch discovers special purpose flag for that and avoids the restriction
from aliasing.  Even with the patch removal of ADDRESSOF cause Gerald's
testcase to grow by 200 instruction, but originally it did by 9000
instructions.

Honza

2004-01-11  Jan Hubicka  <jh@suse.cz>
	* tree-dfa.c (find_addressable_vars): Correctly parse
	(addr_expr (array_ref ...)).
	(discover_nonconstant_array_refs_r): New static function.
	(discover_nonconstant_array_refs): New global function. 
	* tree-flow.h (discover_nonconstant_array_refs): Declare.
	* tree-optimize.c (optimize_function_tree): Use
	discover_nonconstant_array_refs.
	* tree-simple.c (needs_to_live_in_memory): Arrays are ok.
Index: tree-dfa.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-dfa.c,v
retrieving revision 1.1.4.209
diff -c -3 -p -r1.1.4.209 tree-dfa.c
*** tree-dfa.c	9 Jan 2004 08:50:42 -0000	1.1.4.209
--- tree-dfa.c	11 Jan 2004 18:09:23 -0000
*************** find_addressable_vars (bitmap addresses_
*** 1469,1477 ****
  	      if (TREE_CODE (t) != ADDR_EXPR)
  		continue;
  
! 	      t = TREE_OPERAND (t, 0);
! 	      if (TREE_CODE (t) == VAR_DECL
! 		  || TREE_CODE (t) == PARM_DECL)
  		bitmap_set_bit (addresses_needed, var_ann (t)->uid);
  	    }
  	}
--- 1469,1477 ----
  	      if (TREE_CODE (t) != ADDR_EXPR)
  		continue;
  
! 	      t = get_base_symbol (TREE_OPERAND (t, 0));
! 	      if (t && (TREE_CODE (t) == VAR_DECL
! 		        || TREE_CODE (t) == PARM_DECL))
  		bitmap_set_bit (addresses_needed, var_ann (t)->uid);
  	    }
  	}
*************** mark_new_vars_to_rename (tree stmt, bitm
*** 2228,2231 ****
--- 2228,2274 ----
    BITMAP_XFREE (vars_in_vops_to_rename);
  }
  
+ /* Helper function for discover_nonconstant_array_refs. 
+    Look for variables inside ARRAY_REF with non-constant operand
+    and mark them as addressable.  */
+ static tree
+ discover_nonconstant_array_refs_r (tree * tp, int *walk_subtrees,
+ 				   void *data ATTRIBUTE_UNUSED)
+ {
+   tree t = *tp;
+   if (TYPE_P (t) || DECL_P (t))
+     *walk_subtrees = 0;
+   else if (TREE_CODE (t) == ARRAY_REF)
+     {
+       while ((TREE_CODE (t) == ARRAY_REF
+ 	      && is_gimple_min_invariant (TREE_OPERAND (t, 1)))
+ 	     || (TREE_CODE (t) == COMPONENT_REF
+ 		 || TREE_CODE (t) == REALPART_EXPR
+ 		 || TREE_CODE (t) == IMAGPART_EXPR))
+ 	t = TREE_OPERAND (t, 0);
+       t = get_base_symbol (t);
+       if (t && DECL_P (t))
+ 	TREE_ADDRESSABLE (t) = 1;
+       *walk_subtrees = 0;
+     }
+   return NULL_TREE;
+ }
+ 
+ /* RTL expansion code is not able to compile array references with variable
+    offsets for arrays stored in single register.
+    Discover such expressions and mark variables as addressable to avoid
+    this scenario.  */
+ void
+ discover_nonconstant_array_refs (void)
+ {
+   basic_block bb;
+   block_stmt_iterator bsi;
+ 
+   FOR_EACH_BB (bb)
+     {
+       for (bsi = bsi_start (bb); !bsi_end_p (bsi); bsi_next (&bsi))
+ 	walk_tree (bsi_stmt_ptr (bsi), discover_nonconstant_array_refs_r,
+ 		   NULL , NULL);
+     }
+ }
  #include "gt-tree-dfa.h"
Index: tree-flow.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-flow.h,v
retrieving revision 1.1.4.179
diff -c -3 -p -r1.1.4.179 tree-flow.h
*** tree-flow.h	7 Jan 2004 23:44:15 -0000	1.1.4.179
--- tree-flow.h	11 Jan 2004 18:09:23 -0000
*************** extern tree get_virtual_var (tree);
*** 471,476 ****
--- 471,477 ----
  extern void create_global_var (void);
  extern void add_referenced_tmp_var (tree var);
  extern void mark_new_vars_to_rename (tree, bitmap);
+ extern void discover_nonconstant_array_refs (void);
  
  /* Flags used when computing reaching definitions and reached uses.  */
  #define TDFA_USE_OPS		1 << 0
Index: tree-optimize.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-optimize.c,v
retrieving revision 1.1.4.105
diff -c -3 -p -r1.1.4.105 tree-optimize.c
*** tree-optimize.c	9 Jan 2004 21:19:27 -0000	1.1.4.105
--- tree-optimize.c	11 Jan 2004 18:09:23 -0000
*************** optimize_function_tree (tree fndecl, tre
*** 287,292 ****
--- 287,294 ----
        /* Rewrite the function out of SSA form.  */
        rewrite_out_of_ssa (fndecl, TDI_optimized);
        ggc_collect ();
+       
+       discover_nonconstant_array_refs ();
  
        /* Flush out flow graph and SSA data.  */
        BITMAP_XFREE (vars_to_rename);
Index: tree-simple.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/Attic/tree-simple.c,v
retrieving revision 1.1.4.68
diff -c -3 -p -r1.1.4.68 tree-simple.c
*** tree-simple.c	10 Jan 2004 03:29:33 -0000	1.1.4.68
--- tree-simple.c	11 Jan 2004 18:09:23 -0000
*************** needs_to_live_in_memory (tree t)
*** 459,465 ****
    if (TREE_STATIC (t)
        || DECL_EXTERNAL (t)
        || DECL_NONLOCAL (t)
-       || TREE_CODE (TREE_TYPE (t)) == ARRAY_TYPE
        || (TREE_CODE (t) == RESULT_DECL
  	  && aggregate_value_p (t, current_function_decl))
        || decl_function_context (t) != current_function_decl)
--- 459,464 ----



More information about the Gcc-patches mailing list