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] Memory savings in scev analysis


Hello,

instantiate_parameters recursively copies the expression so that it may
change it.  However usually the expression remains unchanged, and we
just waste memory.  This patch makes it copy the expression only if
needed.

Bootstrapped & regtested on i686 and ppc64.

Zdenek

	* tree-scalar-evolution.c (instantiate_parameters_1): Copy the
	expression only if needed.

Index: tree-scalar-evolution.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-scalar-evolution.c,v
retrieving revision 2.13
diff -c -3 -p -r2.13 tree-scalar-evolution.c
*** tree-scalar-evolution.c	12 Nov 2004 13:28:16 -0000	2.13
--- tree-scalar-evolution.c	27 Dec 2004 14:23:52 -0000
*************** instantiate_parameters_1 (struct loop *l
*** 1955,1982 ****
  				      allow_superloop_chrecs);
        op1 = instantiate_parameters_1 (loop, CHREC_RIGHT (chrec),
  				      allow_superloop_chrecs);
!       return build_polynomial_chrec (CHREC_VARIABLE (chrec), op0, op1);
  
      case PLUS_EXPR:
        op0 = instantiate_parameters_1 (loop, TREE_OPERAND (chrec, 0),
  				      allow_superloop_chrecs);
        op1 = instantiate_parameters_1 (loop, TREE_OPERAND (chrec, 1),
  				      allow_superloop_chrecs);
!       return chrec_fold_plus (TREE_TYPE (chrec), op0, op1);
  
      case MINUS_EXPR:
        op0 = instantiate_parameters_1 (loop, TREE_OPERAND (chrec, 0),
  				      allow_superloop_chrecs);
        op1 = instantiate_parameters_1 (loop, TREE_OPERAND (chrec, 1),
  				      allow_superloop_chrecs);
!       return chrec_fold_minus (TREE_TYPE (chrec), op0, op1);
  
      case MULT_EXPR:
        op0 = instantiate_parameters_1 (loop, TREE_OPERAND (chrec, 0),
  				      allow_superloop_chrecs);
        op1 = instantiate_parameters_1 (loop, TREE_OPERAND (chrec, 1),
  				      allow_superloop_chrecs);
!       return chrec_fold_multiply (TREE_TYPE (chrec), op0, op1);
  
      case NOP_EXPR:
      case CONVERT_EXPR:
--- 1992,2031 ----
  				      allow_superloop_chrecs);
        op1 = instantiate_parameters_1 (loop, CHREC_RIGHT (chrec),
  				      allow_superloop_chrecs);
!       if (CHREC_LEFT (chrec) != op0
! 	  || CHREC_RIGHT (chrec) != op1)
! 	chrec = build_polynomial_chrec (CHREC_VARIABLE (chrec), op0, op1);
!       return chrec;
  
      case PLUS_EXPR:
        op0 = instantiate_parameters_1 (loop, TREE_OPERAND (chrec, 0),
  				      allow_superloop_chrecs);
        op1 = instantiate_parameters_1 (loop, TREE_OPERAND (chrec, 1),
  				      allow_superloop_chrecs);
!       if (TREE_OPERAND (chrec, 0) != op0
! 	  || TREE_OPERAND (chrec, 1) != op1)
!       	chrec = chrec_fold_plus (TREE_TYPE (chrec), op0, op1);
!       return chrec;
  
      case MINUS_EXPR:
        op0 = instantiate_parameters_1 (loop, TREE_OPERAND (chrec, 0),
  				      allow_superloop_chrecs);
        op1 = instantiate_parameters_1 (loop, TREE_OPERAND (chrec, 1),
  				      allow_superloop_chrecs);
!       if (TREE_OPERAND (chrec, 0) != op0
! 	  || TREE_OPERAND (chrec, 1) != op1)
!         chrec = chrec_fold_minus (TREE_TYPE (chrec), op0, op1);
!       return chrec;
  
      case MULT_EXPR:
        op0 = instantiate_parameters_1 (loop, TREE_OPERAND (chrec, 0),
  				      allow_superloop_chrecs);
        op1 = instantiate_parameters_1 (loop, TREE_OPERAND (chrec, 1),
  				      allow_superloop_chrecs);
!       if (TREE_OPERAND (chrec, 0) != op0
! 	  || TREE_OPERAND (chrec, 1) != op1)
! 	chrec = chrec_fold_multiply (TREE_TYPE (chrec), op0, op1);
!       return chrec;
  
      case NOP_EXPR:
      case CONVERT_EXPR:
*************** instantiate_parameters_1 (struct loop *l
*** 1986,1991 ****
--- 2035,2043 ----
        if (op0 == chrec_dont_know)
          return chrec_dont_know;
  
+       if (op0 == TREE_OPERAND (chrec, 0))
+ 	return chrec;
+ 
        return chrec_convert (TREE_TYPE (chrec), op0);
  
      case SCEV_NOT_KNOWN:
*************** instantiate_parameters_1 (struct loop *l
*** 2011,2016 ****
--- 2063,2074 ----
  	  || op1 == chrec_dont_know
  	  || op2 == chrec_dont_know)
          return chrec_dont_know;
+ 
+       if (op0 == TREE_OPERAND (chrec, 0)
+ 	  && op1 == TREE_OPERAND (chrec, 1)
+ 	  && op2 == TREE_OPERAND (chrec, 2))
+ 	return chrec;
+ 
        return fold (build (TREE_CODE (chrec),
  			  TREE_TYPE (chrec), op0, op1, op2));
  
*************** instantiate_parameters_1 (struct loop *l
*** 2022,2027 ****
--- 2080,2089 ----
        if (op0 == chrec_dont_know
  	  || op1 == chrec_dont_know)
          return chrec_dont_know;
+ 
+       if (op0 == TREE_OPERAND (chrec, 0)
+ 	  && op1 == TREE_OPERAND (chrec, 1))
+ 	return chrec;
        return fold (build (TREE_CODE (chrec), TREE_TYPE (chrec), op0, op1));
  	    
      case 1:
*************** instantiate_parameters_1 (struct loop *l
*** 2029,2034 ****
--- 2091,2098 ----
  				      allow_superloop_chrecs);
        if (op0 == chrec_dont_know)
          return chrec_dont_know;
+       if (op0 == TREE_OPERAND (chrec, 0))
+ 	return chrec;
        return fold (build1 (TREE_CODE (chrec), TREE_TYPE (chrec), op0));
  
      case 0:


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