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] Fix PR36291 more


This patch shaves off another 10s from the compile-time of PR36291
which went down from 150s to 60s with the a-i branch merge.  This
enables us to add variables referenced by global initializers lazily
and thus does not exhibit the quadratic behavior we see in this
testcase.

Bootstrap / regtest on x86_64-unknown-linux-gnu running, I will commit
this once that succeeded.

Thanks,
Richard.

2009-04-08  Richard Guenther  <rguenther@suse.de>

	PR middle-end/36291
	* tree-dfa.c (add_referenced_var): Do not recurse into
	global initializers.
	* tree-ssa-ccp.c (get_symbol_constant_value): Add newly
	exposed variables.
	(fold_const_aggregate_ref): Likewise.

Index: gcc/tree-dfa.c
===================================================================
*** gcc/tree-dfa.c.orig	2009-04-08 15:41:32.000000000 +0200
--- gcc/tree-dfa.c	2009-04-08 15:41:59.000000000 +0200
*************** add_referenced_var (tree var)
*** 600,612 ****
      {
        /* Scan DECL_INITIAL for pointer variables as they may contain
  	 address arithmetic referencing the address of other
! 	 variables.  
! 	 Even non-constant initializers need to be walked, because
! 	 IPA passes might prove that their are invariant later on.  */
        if (DECL_INITIAL (var)
! 	  /* Initializers of external variables are not useful to the
! 	     optimizers.  */
!           && !DECL_EXTERNAL (var))
        	walk_tree (&DECL_INITIAL (var), find_vars_r, NULL, 0);
  
        return true;
--- 600,610 ----
      {
        /* Scan DECL_INITIAL for pointer variables as they may contain
  	 address arithmetic referencing the address of other
! 	 variables.  As we are only interested in directly referenced
! 	 globals or referenced locals restrict this to initializers
! 	 than can refer to local variables.  */
        if (DECL_INITIAL (var)
!           && DECL_CONTEXT (var) == current_function_decl)
        	walk_tree (&DECL_INITIAL (var), find_vars_r, NULL, 0);
  
        return true;
Index: gcc/tree-ssa-ccp.c
===================================================================
*** gcc/tree-ssa-ccp.c.orig	2009-04-08 15:41:57.000000000 +0200
--- gcc/tree-ssa-ccp.c	2009-04-08 15:47:05.000000000 +0200
*************** get_symbol_constant_value (tree sym)
*** 281,287 ****
  	{
  	  STRIP_USELESS_TYPE_CONVERSION (val);
  	  if (is_gimple_min_invariant (val))
! 	    return val;
  	}
        /* Variables declared 'const' without an initializer
  	 have zero as the initializer if they may not be
--- 281,295 ----
  	{
  	  STRIP_USELESS_TYPE_CONVERSION (val);
  	  if (is_gimple_min_invariant (val))
! 	    {
! 	      if (TREE_CODE (val) == ADDR_EXPR)
! 		{
! 		  tree base = get_base_address (TREE_OPERAND (val, 0));
! 		  if (base)
! 		    add_referenced_var (base);
! 		}
! 	      return val;
! 	    }
  	}
        /* Variables declared 'const' without an initializer
  	 have zero as the initializer if they may not be
*************** fold_const_aggregate_ref (tree t)
*** 1243,1248 ****
--- 1251,1262 ----
  	if (tree_int_cst_equal (cfield, idx))
  	  {
  	    STRIP_USELESS_TYPE_CONVERSION (cval);
+ 	    if (TREE_CODE (cval) == ADDR_EXPR)
+ 	      {
+ 		tree base = get_base_address (TREE_OPERAND (cval, 0));
+ 		if (base)
+ 		  add_referenced_var (base);
+ 	      }
  	    return cval;
  	  }
        break;
*************** fold_const_aggregate_ref (tree t)
*** 1286,1291 ****
--- 1300,1311 ----
  	    && ! DECL_BIT_FIELD (cfield))
  	  {
  	    STRIP_USELESS_TYPE_CONVERSION (cval);
+ 	    if (TREE_CODE (cval) == ADDR_EXPR)
+ 	      {
+ 		tree base = get_base_address (TREE_OPERAND (cval, 0));
+ 		if (base)
+ 		  add_referenced_var (base);
+ 	      }
  	    return cval;
  	  }
        break;


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