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] Rename nondestructive_fold_binary_to_constant


When source files start defining macros purely to avoid typing overly
long function names, you know that things are getting bad.  In this
case, tree-ssa-loop-niter.c and tree-ssa-loop-ivopts.c both define
EXEC_BINARY and EXEC_UNARY macros to avoid typing the function names
nondestructive_fold_{binary,unary}_to_constant.  The proposed solution
is to shorten the function names by removing the "nondestructive_"
prefix, as all of GCC's fold functions are supposed/intended to be
non-destructive.  Indeed, --enable-checking=fold even checks this.

The following patch has been tested on i686-pc-linux-gnu with a full
"make bootstrap", all default languages, and regression tested with
a top-level "make -k check" with no new failures.

Ok for mainline?  Any objections?



2004-11-21  Roger Sayle  <roger@eyesopen.com>

	* fold-const.c (nondestructive_fold_binary_to_constant): Rename
	to fold_binary_to_constant.
	(nondestructive_fold_unary_to_constant): Likewise, rename to
	fold_unary_to_constant.
	(fold_relational_hi_lo): Update call to fold_binary_to_constant.
	* tree.h (nondestructive_fold_binary_to_constant): Update prototype.
	(nondestructive_fold_unary_to_constant): Likewise.
	* tree-ssa-ccp.c (ccp_fold): Update calls to fold_unary_to_constant
	and fold_binary_to_constant.
	* tree-ssa-loop-niter.c (EXEC_BINARY, EXEC_UNARY): Delete macros.
	(inverse, number_of_iterations_cond): Replace uses of EXEC_BINARY
	and EXEC_UNARY with calls to fold_*nary_to_constant.
	* tree-ssa-loop-ivopts.c (EXEC_BINARY, EXEC_UNARY): Delete macros.
	(idx_find_step): Replace uses of EXEC_BINARY with calls to
	fold_binary_to_constant.


Index: fold-const.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.475
diff -c -3 -p -r1.475 fold-const.c
*** fold-const.c	18 Nov 2004 12:09:36 -0000	1.475
--- fold-const.c	21 Nov 2004 19:13:33 -0000
*************** fold_relational_hi_lo (enum tree_code *c
*** 10052,10062 ****
  			    fold_convert (st0, op0),
  			    fold_convert (st1, integer_zero_node));

! 	      retval
! 		= nondestructive_fold_binary_to_constant (TREE_CODE (exp),
! 							  TREE_TYPE (exp),
! 							  TREE_OPERAND (exp, 0),
! 							  TREE_OPERAND (exp, 1));

  	      /* If we are in gimple form, then returning EXP would create
  		 non-gimple expressions.  Clearing it is safe and insures
--- 10052,10061 ----
  			    fold_convert (st0, op0),
  			    fold_convert (st1, integer_zero_node));

! 	      retval = fold_binary_to_constant (TREE_CODE (exp),
! 						TREE_TYPE (exp),
! 						TREE_OPERAND (exp, 0),
! 						TREE_OPERAND (exp, 1));

  	      /* If we are in gimple form, then returning EXP would create
  		 non-gimple expressions.  Clearing it is safe and insures
*************** fold_relational_hi_lo (enum tree_code *c
*** 10087,10094 ****
     simpler than the generic fold routine.  */

  tree
! nondestructive_fold_binary_to_constant (enum tree_code code, tree type,
! 					tree op0, tree op1)
  {
    int wins = 1;
    tree subop0;
--- 10086,10092 ----
     simpler than the generic fold routine.  */

  tree
! fold_binary_to_constant (enum tree_code code, tree type, tree op0, tree op1)
  {
    int wins = 1;
    tree subop0;
*************** nondestructive_fold_binary_to_constant (
*** 10382,10389 ****
     the generic fold routine.  */

  tree
! nondestructive_fold_unary_to_constant (enum tree_code code, tree type,
! 				       tree op0)
  {
    /* Make sure we have a suitable constant argument.  */
    if (code == NOP_EXPR || code == FLOAT_EXPR || code == CONVERT_EXPR)
--- 10380,10386 ----
     the generic fold routine.  */

  tree
! fold_unary_to_constant (enum tree_code code, tree type, tree op0)
  {
    /* Make sure we have a suitable constant argument.  */
    if (code == NOP_EXPR || code == FLOAT_EXPR || code == CONVERT_EXPR)
Index: tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree.h,v
retrieving revision 1.657
diff -c -3 -p -r1.657 tree.h
*** tree.h	17 Nov 2004 22:06:00 -0000	1.657
--- tree.h	21 Nov 2004 19:13:34 -0000
*************** extern int operand_equal_p (tree, tree,
*** 3525,3532 ****
  extern tree omit_one_operand (tree, tree, tree);
  extern tree omit_two_operands (tree, tree, tree, tree);
  extern tree invert_truthvalue (tree);
! extern tree nondestructive_fold_unary_to_constant (enum tree_code, tree, tree);
! extern tree nondestructive_fold_binary_to_constant (enum tree_code, tree, tree, tree);
  extern tree fold_read_from_constant_string (tree);
  extern tree int_const_binop (enum tree_code, tree, tree, int);
  extern tree build_fold_addr_expr (tree);
--- 3525,3532 ----
  extern tree omit_one_operand (tree, tree, tree);
  extern tree omit_two_operands (tree, tree, tree, tree);
  extern tree invert_truthvalue (tree);
! extern tree fold_unary_to_constant (enum tree_code, tree, tree);
! extern tree fold_binary_to_constant (enum tree_code, tree, tree, tree);
  extern tree fold_read_from_constant_string (tree);
  extern tree int_const_binop (enum tree_code, tree, tree, int);
  extern tree build_fold_addr_expr (tree);
Index: tree-ssa-ccp.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-ssa-ccp.c,v
retrieving revision 2.50
diff -c -3 -p -r2.50 tree-ssa-ccp.c
*** tree-ssa-ccp.c	17 Nov 2004 02:01:32 -0000	2.50
--- tree-ssa-ccp.c	21 Nov 2004 19:13:34 -0000
*************** ccp_fold (tree stmt)
*** 847,855 ****
  	    op0 = get_value (op0)->const_val;
  	}

!       retval = nondestructive_fold_unary_to_constant (code,
! 		     				      TREE_TYPE (rhs),
! 						      op0);

        /* If we folded, but did not create an invariant, then we can not
  	 use this expression.  */
--- 847,853 ----
  	    op0 = get_value (op0)->const_val;
  	}

!       retval = fold_unary_to_constant (code, TREE_TYPE (rhs), op0);

        /* If we folded, but did not create an invariant, then we can not
  	 use this expression.  */
*************** ccp_fold (tree stmt)
*** 900,908 ****
  	    op1 = val->const_val;
  	}

!       retval = nondestructive_fold_binary_to_constant (code,
! 		     				       TREE_TYPE (rhs),
! 						       op0, op1);

        /* If we folded, but did not create an invariant, then we can not
  	 use this expression.  */
--- 898,904 ----
  	    op1 = val->const_val;
  	}

!       retval = fold_binary_to_constant (code, TREE_TYPE (rhs), op0, op1);

        /* If we folded, but did not create an invariant, then we can not
  	 use this expression.  */
Index: tree-ssa-loop-niter.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-ssa-loop-niter.c,v
retrieving revision 2.16
diff -c -3 -p -r2.16 tree-ssa-loop-niter.c
*** tree-ssa-loop-niter.c	15 Nov 2004 00:18:33 -0000	2.16
--- tree-ssa-loop-niter.c	21 Nov 2004 19:13:35 -0000
*************** Software Foundation, 59 Temple Place - S
*** 43,51 ****

  #define SWAP(X, Y) do { void *tmp = (X); (X) = (Y); (Y) = tmp; } while (0)

- /* Just to shorten the ugly names.  */
- #define EXEC_BINARY nondestructive_fold_binary_to_constant
- #define EXEC_UNARY nondestructive_fold_unary_to_constant

  /*

--- 43,48 ----
*************** inverse (tree x, tree mask)
*** 156,165 ****
        rslt = build_int_cst_type (type, 1);
        for (; ctr; ctr--)
  	{
! 	  rslt = EXEC_BINARY (MULT_EXPR, type, rslt, x);
! 	  x = EXEC_BINARY (MULT_EXPR, type, x, x);
  	}
!       rslt = EXEC_BINARY (BIT_AND_EXPR, type, rslt, mask);
      }

    return rslt;
--- 153,162 ----
        rslt = build_int_cst_type (type, 1);
        for (; ctr; ctr--)
  	{
! 	  rslt = fold_binary_to_constant (MULT_EXPR, type, rslt, x);
! 	  x = fold_binary_to_constant (MULT_EXPR, type, x, x);
  	}
!       rslt = fold_binary_to_constant (BIT_AND_EXPR, type, rslt, mask);
      }

    return rslt;
*************** number_of_iterations_cond (tree type, tr
*** 217,223 ****
        if (code != NE_EXPR)
  	return;

!       step0 = EXEC_BINARY (MINUS_EXPR, type, step0, step1);
        step1 = NULL_TREE;
      }

--- 214,220 ----
        if (code != NE_EXPR)
  	return;

!       step0 = fold_binary_to_constant (MINUS_EXPR, type, step0, step1);
        step1 = NULL_TREE;
      }

*************** number_of_iterations_cond (tree type, tr
*** 311,317 ****
    if (code != NE_EXPR)
      {
        if (zero_p (step0))
! 	step = EXEC_UNARY (NEGATE_EXPR, type, step1);
        else
  	step = step0;
        delta = build2 (MINUS_EXPR, type, base1, base0);
--- 308,314 ----
    if (code != NE_EXPR)
      {
        if (zero_p (step0))
! 	step = fold_unary_to_constant (NEGATE_EXPR, type, step1);
        else
  	step = step0;
        delta = build2 (MINUS_EXPR, type, base1, base0);
*************** number_of_iterations_cond (tree type, tr
*** 320,327 ****

        if (TREE_CODE (delta) == INTEGER_CST)
  	{
! 	  tmp = EXEC_BINARY (MINUS_EXPR, type, step,
! 			     build_int_cst_type (type, 1));
  	  if (was_sharp
  	      && operand_equal_p (delta, tmp, 0))
  	    {
--- 317,324 ----

        if (TREE_CODE (delta) == INTEGER_CST)
  	{
! 	  tmp = fold_binary_to_constant (MINUS_EXPR, type, step,
! 					 build_int_cst_type (type, 1));
  	  if (was_sharp
  	      && operand_equal_p (delta, tmp, 0))
  	    {
*************** number_of_iterations_cond (tree type, tr
*** 342,349 ****
  		may_xform = boolean_true_node;
  	      else
  		{
! 		  bound = EXEC_BINARY (PLUS_EXPR, type, mmin, step);
! 		  bound = EXEC_BINARY (MINUS_EXPR, type, bound, delta);
  		  may_xform = fold (build2 (LE_EXPR, boolean_type_node,
  					   bound, base0));
  		}
--- 339,348 ----
  		may_xform = boolean_true_node;
  	      else
  		{
! 		  bound = fold_binary_to_constant (PLUS_EXPR, type,
! 						   mmin, step);
! 		  bound = fold_binary_to_constant (MINUS_EXPR, type,
! 						   bound, delta);
  		  may_xform = fold (build2 (LE_EXPR, boolean_type_node,
  					   bound, base0));
  		}
*************** number_of_iterations_cond (tree type, tr
*** 354,361 ****
  		may_xform = boolean_true_node;
  	      else
  		{
! 		  bound = EXEC_BINARY (MINUS_EXPR, type, mmax, step);
! 		  bound = EXEC_BINARY (PLUS_EXPR, type, bound, delta);
  		  may_xform = fold (build2 (LE_EXPR, boolean_type_node,
  					   base1, bound));
  		}
--- 353,362 ----
  		may_xform = boolean_true_node;
  	      else
  		{
! 		  bound = fold_binary_to_constant (MINUS_EXPR, type,
! 						   mmax, step);
! 		  bound = fold_binary_to_constant (PLUS_EXPR, type,
! 						   bound, delta);
  		  may_xform = fold (build2 (LE_EXPR, boolean_type_node,
  					   base1, bound));
  		}
*************** number_of_iterations_cond (tree type, tr
*** 401,411 ****
        base1 = fold (build2 (MINUS_EXPR, type, base1, base0));
        base0 = NULL_TREE;
        if (!zero_p (step1))
!   	step0 = EXEC_UNARY (NEGATE_EXPR, type, step1);
        step1 = NULL_TREE;
        if (!tree_expr_nonnegative_p (fold_convert (signed_niter_type, step0)))
  	{
! 	  step0 = EXEC_UNARY (NEGATE_EXPR, type, step0);
  	  base1 = fold (build1 (NEGATE_EXPR, type, base1));
  	}

--- 402,412 ----
        base1 = fold (build2 (MINUS_EXPR, type, base1, base0));
        base0 = NULL_TREE;
        if (!zero_p (step1))
!   	step0 = fold_unary_to_constant (NEGATE_EXPR, type, step1);
        step1 = NULL_TREE;
        if (!tree_expr_nonnegative_p (fold_convert (signed_niter_type, step0)))
  	{
! 	  step0 = fold_unary_to_constant (NEGATE_EXPR, type, step0);
  	  base1 = fold (build1 (NEGATE_EXPR, type, base1));
  	}

*************** number_of_iterations_cond (tree type, tr
*** 416,424 ****
  	 is infinite.  Otherwise, the number of iterations is
  	 (inverse(s/d) * (c/d)) mod (size of mode/d).  */
        bits = num_ending_zeros (step0);
!       d = EXEC_BINARY (LSHIFT_EXPR, niter_type,
! 		       build_int_cst_type (niter_type, 1), bits);
!       s = EXEC_BINARY (RSHIFT_EXPR, niter_type, step0, bits);

        bound = build_low_bits_mask (niter_type,
  				   (TYPE_PRECISION (niter_type)
--- 417,425 ----
  	 is infinite.  Otherwise, the number of iterations is
  	 (inverse(s/d) * (c/d)) mod (size of mode/d).  */
        bits = num_ending_zeros (step0);
!       d = fold_binary_to_constant (LSHIFT_EXPR, niter_type,
! 				   build_int_cst_type (niter_type, 1), bits);
!       s = fold_binary_to_constant (RSHIFT_EXPR, niter_type, step0, bits);

        bound = build_low_bits_mask (niter_type,
  				   (TYPE_PRECISION (niter_type)
*************** number_of_iterations_cond (tree type, tr
*** 447,453 ****
  	{
  	  if (mmax)
  	    {
! 	      bound = EXEC_BINARY (MINUS_EXPR, type, mmax, step0);
  	      assumption = fold (build2 (LE_EXPR, boolean_type_node,
  					 base1, bound));
  	      assumptions = fold (build2 (TRUTH_AND_EXPR, boolean_type_node,
--- 448,454 ----
  	{
  	  if (mmax)
  	    {
! 	      bound = fold_binary_to_constant (MINUS_EXPR, type, mmax, step0);
  	      assumption = fold (build2 (LE_EXPR, boolean_type_node,
  					 base1, bound));
  	      assumptions = fold (build2 (TRUTH_AND_EXPR, boolean_type_node,
*************** number_of_iterations_cond (tree type, tr
*** 468,474 ****
  	     we can again compute number of iterations as (b - (a - s)) / s.  */
  	  if (mmin)
  	    {
! 	      bound = EXEC_BINARY (MINUS_EXPR, type, mmin, step1);
  	      assumption = fold (build2 (LE_EXPR, boolean_type_node,
  					bound, base0));
  	      assumptions = fold (build2 (TRUTH_AND_EXPR, boolean_type_node,
--- 469,475 ----
  	     we can again compute number of iterations as (b - (a - s)) / s.  */
  	  if (mmin)
  	    {
! 	      bound = fold_binary_to_constant (MINUS_EXPR, type, mmin, step1);
  	      assumption = fold (build2 (LE_EXPR, boolean_type_node,
  					bound, base0));
  	      assumptions = fold (build2 (TRUTH_AND_EXPR, boolean_type_node,
Index: tree-ssa-loop-ivopts.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree-ssa-loop-ivopts.c,v
retrieving revision 2.30
diff -c -3 -p -r2.30 tree-ssa-loop-ivopts.c
*** tree-ssa-loop-ivopts.c	14 Nov 2004 23:35:02 -0000	2.30
--- tree-ssa-loop-ivopts.c	21 Nov 2004 19:13:35 -0000
*************** Software Foundation, 59 Temple Place - S
*** 96,104 ****
     this.  */
  #define AVG_LOOP_NITER(LOOP) 5

- /* Just to shorten the ugly names.  */
- #define EXEC_BINARY nondestructive_fold_binary_to_constant
- #define EXEC_UNARY nondestructive_fold_unary_to_constant

  /* Representation of the induction variable.  */
  struct iv
--- 96,101 ----
*************** idx_find_step (tree base, tree *idx, voi
*** 1364,1375 ****
        return false;
      }

!   step = EXEC_BINARY (MULT_EXPR, type, step, iv_step);

    if (!*dta->step_p)
      *dta->step_p = step;
    else
!     *dta->step_p = EXEC_BINARY (PLUS_EXPR, type, *dta->step_p, step);

    return true;
  }
--- 1361,1373 ----
        return false;
      }

!   step = fold_binary_to_constant (MULT_EXPR, type, step, iv_step);

    if (!*dta->step_p)
      *dta->step_p = step;
    else
!     *dta->step_p = fold_binary_to_constant (PLUS_EXPR, type,
! 					    *dta->step_p, step);

    return true;
  }


Roger
--
Roger Sayle,                         E-mail: roger@eyesopen.com
OpenEye Scientific Software,         WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road,     Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507.         Fax: (+1) 505-473-0833


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