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]

[tree-ssa] TREE_ADDRESSABLE versus ARRAY_TYPE


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>
	* stmt.c (expand_decl): Put decl into memory when it has nonconstant
	array ref.
	* 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.
	* tree.h (NONCONSTANT_ARRAY_REF): New flag.
Index: stmt.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/stmt.c,v
retrieving revision 1.267.2.44
diff -c -3 -p -r1.267.2.44 stmt.c
*** stmt.c	3 Jan 2004 23:02:01 -0000	1.267.2.44
--- stmt.c	11 Jan 2004 18:09:22 -0000
*************** expand_decl (tree decl)
*** 4013,4019 ****
        maybe_set_unchanging (DECL_RTL (decl), decl);
  
        /* If something wants our address, try to use ADDRESSOF.  */
!       if (TREE_ADDRESSABLE (decl))
  	put_var_into_stack (decl, /*rescan=*/false);
      }
  
--- 4013,4019 ----
        maybe_set_unchanging (DECL_RTL (decl), decl);
  
        /* If something wants our address, try to use ADDRESSOF.  */
!       if (TREE_ADDRESSABLE (decl) || DECL_NONCONSTANT_ARRAY_REF (decl))
  	put_var_into_stack (decl, /*rescan=*/false);
      }
  
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))
+ 	DECL_NONCONSTANT_ARRAY_REF (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 ----
Index: tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree.h,v
retrieving revision 1.342.2.158
diff -c -3 -p -r1.342.2.158 tree.h
*** tree.h	7 Jan 2004 23:44:16 -0000	1.342.2.158
--- tree.h	11 Jan 2004 18:09:23 -0000
*************** struct tree_common GTY(())
*** 274,279 ****
--- 274,282 ----
         TREE_NOTHROW in
             CALL_EXPR, FUNCTION_DECL
  
+        NONCONSTANT_ARRAY_REF in
+            VAR_DECL, ARRAY_DECL
+ 
     deprecated_flag:
  
  	TREE_DEPRECATED in
*************** extern void tree_operand_check_failed (i
*** 703,708 ****
--- 706,718 ----
  /* In a FUNCTION_DECL, nonzero means a call to the function cannot throw
     an exception.  In a CALL_EXPR, nonzero means the call cannot throw.  */
  #define TREE_NOTHROW(NODE) ((NODE)->common.nothrow_flag)
+ 
+ /* In VAR_DECL or PARAM_DECL nonzero means that there exists array ref
+    with nonconstant offset.  This instruct backend to store the array
+    in memory because it is unable to expandd nonconstant array references
+    to arrays in registers.  The flag is set only after SSA optimizers was
+    performed.  */
+ #define DECL_NONCONSTANT_ARRAY_REF(NODE) (DECL_CHECK(NODE)->common.nothrow_flag)
  
  /* In a CALL_EXPR, means that the address of the return slot is part of the
     argument list.  */


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