Somewhat-related changes to expr.c & tree.c

Richard Kenner kenner@vlsi1.ultra.nyu.edu
Fri Oct 20 14:01:00 GMT 2000


This is a set of somewhat-related changes.  The largest change is to
mark more things as TREE_READONLY to avoid making SAVE_EXPRs unnecessarily.
Most of the other changes are things that fall out from that, except
for the change to build_index_type which avoid overflow problems for
zero-length arrays (and should have been in that patch but I forgot
about it then).

Fri Oct 20 17:05:49 2000  Richard Kenner  <kenner@vlsi1.ultra.nyu.edu>

	* expr.c (expand_expr, case SAVE_EXPR): Set RTX_UNCHANGING_P on
	returned MEM.
	(expand_expr_unaligned, case ARRAY_REF): Check that index is
	a constant before comparing it; use tree_low_cst.
	* tree.c (save_expr): Set TREE_READONLY.
	(substitute_expr): Return inside of NON_LVALUE_EXPR.
	(build, build1): Set TREE_READONLY if all operands are.
	(build_index_type): If upper bound is a negative number, lower
	bound is zero and sizetype is unsigned, use upper bound of one and
	lower of zero.

*** expr.c	2000/10/18 21:33:39	1.269
--- expr.c	2000/10/20 20:37:18
*************** expand_expr (exp, target, tmode, modifie
*** 6223,6227 ****
  	    temp = const0_rtx;
  	  else
! 	    temp = assign_temp (type, 3, 0, 0);
  
  	  SAVE_EXPR_RTL (exp) = temp;
--- 6223,6231 ----
  	    temp = const0_rtx;
  	  else
! 	    {
! 	      temp = assign_temp (type, 3, 0, 0);
! 	      if (GET_CODE (temp) == MEM)
! 		RTX_UNCHANGING_P (temp) = 1;
! 	    }
  
  	  SAVE_EXPR_RTL (exp) = temp;
*************** expand_expr_unaligned (exp, palign)
*** 8684,8687 ****
--- 8688,8692 ----
  
  	if (TREE_CODE (array) == CONSTRUCTOR && ! TREE_SIDE_EFFECTS (array)
+ 	    && host_integerp (index, 0)
  	    && 0 > compare_tree_int (index,
  				     list_length (CONSTRUCTOR_ELTS
*************** expand_expr_unaligned (exp, palign)
*** 8691,8695 ****
  
  	    for (elem = CONSTRUCTOR_ELTS (TREE_OPERAND (exp, 0)),
! 		 i = TREE_INT_CST_LOW (index);
  		 elem != 0 && i != 0; i--, elem = TREE_CHAIN (elem))
  	      ;
--- 8696,8700 ----
  
  	    for (elem = CONSTRUCTOR_ELTS (TREE_OPERAND (exp, 0)),
! 		 i = tree_low_cst (index, 0);
  		 elem != 0 && i != 0; i--, elem = TREE_CHAIN (elem))
  	      ;
*** tree.c	2000/10/13 06:26:29	1.164
--- tree.c	2000/10/20 20:37:41
*************** save_expr (expr)
*** 1728,1731 ****
--- 1728,1732 ----
       eliminated as dead.  */
    TREE_SIDE_EFFECTS (t) = 1;
+   TREE_READONLY (t) = 1;
    return t;
  }
*************** substitute_in_expr (exp, f, r)
*** 2174,2177 ****
--- 2175,2181 ----
  	    return exp;
  
+ 	  if (code == NON_LVALUE_EXPR)
+ 	    return op0;
+ 
  	  new = fold (build1 (code, TREE_TYPE (exp), op0));
  	  break;
*************** build VPARAMS ((enum tree_code code, tre
*** 2489,2496 ****
    TREE_TYPE (t) = tt;
  
!   /* Below, we automatically set TREE_SIDE_EFFECTS and TREE_RAISED for
!      the result based on those same flags for the arguments.  But, if
!      the arguments aren't really even `tree' expressions, we shouldn't
!      be trying to do this.  */
    fro = first_rtl_op (code);
  
--- 2493,2500 ----
    TREE_TYPE (t) = tt;
  
!   /* Below, we automatically set TREE_SIDE_EFFECTS and TREE_READONLY for the
!      result based on those same flags for the arguments.  But if the
!      arguments aren't really even `tree' expressions, we shouldn't be trying
!      to do this.  */
    fro = first_rtl_op (code);
  
*************** build VPARAMS ((enum tree_code code, tre
*** 2500,2514 ****
--- 2504,2525 ----
        register tree arg0 = va_arg (p, tree);
        register tree arg1 = va_arg (p, tree);
+ 
        TREE_OPERAND (t, 0) = arg0;
        TREE_OPERAND (t, 1) = arg1;
+       TREE_READONLY (t) = 1;
        if (arg0 && fro > 0)
  	{
  	  if (TREE_SIDE_EFFECTS (arg0))
  	    TREE_SIDE_EFFECTS (t) = 1;
+ 	  if (!TREE_READONLY (arg0))
+ 	    TREE_READONLY (t) = 0;
  	}
+ 
        if (arg1 && fro > 1)
  	{
  	  if (TREE_SIDE_EFFECTS (arg1))
  	    TREE_SIDE_EFFECTS (t) = 1;
+ 	  if (!TREE_READONLY (arg1))
+ 	    TREE_READONLY (t) = 0;
  	}
      }
*************** build VPARAMS ((enum tree_code code, tre
*** 2516,2529 ****
      {
        register tree arg0 = va_arg (p, tree);
  
!       /* Call build1 for this!  */
        if (TREE_CODE_CLASS (code) != 's')
  	abort ();
        TREE_OPERAND (t, 0) = arg0;
-       if (fro > 0)
- 	{
- 	  if (arg0 && TREE_SIDE_EFFECTS (arg0))
- 	    TREE_SIDE_EFFECTS (t) = 1;
- 	}
      }
    else
--- 2527,2539 ----
      {
        register tree arg0 = va_arg (p, tree);
+ 
+       /* The only one-operand cases we handle here are those with side-effects.
+ 	 Others are handled with build1.  So don't bother checked if the
+ 	 arg has side-effects since we'll already have set it.
  
! 	 ??? This really should use build1 too.  */
        if (TREE_CODE_CLASS (code) != 's')
  	abort ();
        TREE_OPERAND (t, 0) = arg0;
      }
    else
*************** build VPARAMS ((enum tree_code code, tre
*** 2532,2535 ****
--- 2542,2546 ----
  	{
  	  register tree operand = va_arg (p, tree);
+ 
  	  TREE_OPERAND (t, i) = operand;
  	  if (operand && fro > i)
*************** build1 (code, type, node)
*** 2579,2587 ****
  
    TREE_SET_CODE (t, code);
    TREE_TYPE (t) = type;
    TREE_COMPLEXITY (t) = 0;
    TREE_OPERAND (t, 0) = node;
!   if (node && first_rtl_op (code) != 0 && TREE_SIDE_EFFECTS (node))
!     TREE_SIDE_EFFECTS (t) = 1;
  
    switch (code)
--- 2590,2602 ----
  
    TREE_SET_CODE (t, code);
+ 
    TREE_TYPE (t) = type;
    TREE_COMPLEXITY (t) = 0;
    TREE_OPERAND (t, 0) = node;
!   if (node && first_rtl_op (code) != 0)
!     {
!       TREE_SIDE_EFFECTS (t) = TREE_SIDE_EFFECTS (node);
!       TREE_READONLY (t) = TREE_READONLY (node);
!     }
  
    switch (code)
*************** build1 (code, type, node)
*** 2598,2601 ****
--- 2613,2617 ----
  	 operands are.  */
        TREE_SIDE_EFFECTS (t) = 1;
+       TREE_READONLY (t) = 0;
        break;
  
*************** build_index_type (maxval)
*** 3803,3812 ****
  {
    register tree itype = make_node (INTEGER_TYPE);
  
    TREE_TYPE (itype) = sizetype;
    TYPE_PRECISION (itype) = TYPE_PRECISION (sizetype);
-   TYPE_MIN_VALUE (itype) = size_zero_node;
  
!   TYPE_MAX_VALUE (itype) = convert (sizetype, maxval);
  
    TYPE_MODE (itype) = TYPE_MODE (sizetype);
--- 3819,3841 ----
  {
    register tree itype = make_node (INTEGER_TYPE);
+   int no_hash = 0;
  
    TREE_TYPE (itype) = sizetype;
    TYPE_PRECISION (itype) = TYPE_PRECISION (sizetype);
  
!   /* If sizetype is unsigned and the upper bound is negative, use a
!      lower bound of one and an upper bound of zero.  */
!   if (TREE_UNSIGNED (sizetype) && TREE_CODE (maxval) == INTEGER_CST
!       && tree_int_cst_sgn (maxval) < 0)
!     {
!       TYPE_MIN_VALUE (itype) = size_one_node;
!       TYPE_MAX_VALUE (itype) = size_zero_node;
!       no_hash = 1;
!     }
!   else
!     {
!       TYPE_MIN_VALUE (itype) = size_zero_node;
!       TYPE_MAX_VALUE (itype) = convert (sizetype, maxval);
!     }
  
    TYPE_MODE (itype) = TYPE_MODE (sizetype);
*************** build_index_type (maxval)
*** 3816,3820 ****
    TYPE_USER_ALIGN (itype) = TYPE_USER_ALIGN (sizetype);
  
!   if (host_integerp (maxval, 1))
      return type_hash_canon (tree_low_cst (maxval, 1), itype);
    else
--- 3845,3849 ----
    TYPE_USER_ALIGN (itype) = TYPE_USER_ALIGN (sizetype);
  
!   if (!no_hash && host_integerp (maxval, 1))
      return type_hash_canon (tree_low_cst (maxval, 1), itype);
    else


More information about the Gcc-patches mailing list