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] Merge fold-const.c clean-up from tree-ssa


The following patch forward-ports one of Jeff Law's fold-const.c clean-ups
from the tree-ssa branch.  This again helps synchronize the versions of
fold-const.c on mainline vs. the tree-ssa branch.

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

Ok for mainline?


2003-10-12  Jeff Law  <law@redhat.com>
	    Roger Sayle  <roger@eyesopen.com>

	* tree.c (commutative_tree_code, associative_tree_code): New
	functions.
	(iterative_hash_expr): Use commutative_tree_code.
	* tree.h (commutative_tree_code, associative_tree_code): Delare.
	* fold-const.c (operand_equal_p): Use commutative_tree_code
	rather than inlining the commutativity check.
	(fold): Similarly.


Index: tree.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree.c,v
retrieving revision 1.333
diff -c -3 -p -r1.333 tree.c
*** tree.c	6 Oct 2003 13:50:39 -0000	1.333
--- tree.c	12 Oct 2003 18:35:15 -0000
*************** compare_tree_int (tree t, unsigned HOST_
*** 3486,3491 ****
--- 3486,3540 ----
      return 1;
  }

+ /* Return true if CODE represents an associative tree code.  Otherwise
+    return false.  */
+ bool
+ associative_tree_code (enum tree_code code)
+ {
+   switch (code)
+     {
+     case BIT_IOR_EXPR:
+     case BIT_AND_EXPR:
+     case BIT_XOR_EXPR:
+     case PLUS_EXPR:
+     case MINUS_EXPR:
+     case MULT_EXPR:
+     case LSHIFT_EXPR:
+     case RSHIFT_EXPR:
+     case MIN_EXPR:
+     case MAX_EXPR:
+       return true;
+
+     default:
+       break;
+     }
+   return false;
+ }
+
+ /* Return true if CODE represents an commutative tree code.  Otherwise
+    return false.  */
+ bool
+ commutative_tree_code (enum tree_code code)
+ {
+   switch (code)
+     {
+     case PLUS_EXPR:
+     case MULT_EXPR:
+     case MIN_EXPR:
+     case MAX_EXPR:
+     case BIT_IOR_EXPR:
+     case BIT_XOR_EXPR:
+     case BIT_AND_EXPR:
+     case NE_EXPR:
+     case EQ_EXPR:
+       return true;
+
+     default:
+       break;
+     }
+   return false;
+ }
+
  /* Generate a hash value for an expression.  This can be used iteratively
     by passing a previous result as the "val" argument.

*************** iterative_hash_expr (tree t, hashval_t v
*** 3543,3551 ****
  	  || code == NON_LVALUE_EXPR)
  	val = iterative_hash_object (TREE_TYPE (t), val);

!       if (code == PLUS_EXPR || code == MULT_EXPR || code == MIN_EXPR
! 	  || code == MAX_EXPR || code == BIT_IOR_EXPR || code == BIT_XOR_EXPR
! 	  || code == BIT_AND_EXPR || code == NE_EXPR || code == EQ_EXPR)
  	{
  	  /* It's a commutative expression.  We want to hash it the same
  	     however it appears.  We do this by first hashing both operands
--- 3592,3598 ----
  	  || code == NON_LVALUE_EXPR)
  	val = iterative_hash_object (TREE_TYPE (t), val);

!       if (commutative_tree_code (code))
  	{
  	  /* It's a commutative expression.  We want to hash it the same
  	     however it appears.  We do this by first hashing both operands
Index: tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree.h,v
retrieving revision 1.448
diff -c -3 -p -r1.448 tree.h
*** tree.h	9 Oct 2003 05:44:51 -0000	1.448
--- tree.h	12 Oct 2003 18:35:16 -0000
*************** extern tree get_callee_fndecl (tree);
*** 2708,2713 ****
--- 2708,2715 ----
  extern void set_decl_assembler_name (tree);
  extern int type_num_arguments (tree);
  extern tree lhd_unsave_expr_now (tree);
+ extern bool associative_tree_code (enum tree_code);
+ extern bool commutative_tree_code (enum tree_code);


  /* In stmt.c */
Index: fold-const.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.313
diff -c -3 -p -r1.313 fold-const.c
*** fold-const.c	11 Oct 2003 21:15:08 -0000	1.313
--- fold-const.c	12 Oct 2003 18:35:17 -0000
*************** negate_mathfn_p (enum built_in_function
*** 833,839 ****
    return false;
  }

-
  /* Determine whether an expression T can be cheaply negated using
     the function negate_expr.  */

--- 833,838 ----
*************** operand_equal_p (tree arg0, tree arg1, i
*** 2085,2096 ****
  	return 1;

        /* For commutative ops, allow the other order.  */
!       return ((TREE_CODE (arg0) == PLUS_EXPR || TREE_CODE (arg0) == MULT_EXPR
! 	       || TREE_CODE (arg0) == MIN_EXPR || TREE_CODE (arg0) == MAX_EXPR
! 	       || TREE_CODE (arg0) == BIT_IOR_EXPR
! 	       || TREE_CODE (arg0) == BIT_XOR_EXPR
! 	       || TREE_CODE (arg0) == BIT_AND_EXPR
! 	       || TREE_CODE (arg0) == NE_EXPR || TREE_CODE (arg0) == EQ_EXPR)
  	      && operand_equal_p (TREE_OPERAND (arg0, 0),
  				  TREE_OPERAND (arg1, 1), 0)
  	      && operand_equal_p (TREE_OPERAND (arg0, 1),
--- 2084,2090 ----
  	return 1;

        /* For commutative ops, allow the other order.  */
!       return (commutative_tree_code (TREE_CODE (arg0))
  	      && operand_equal_p (TREE_OPERAND (arg0, 0),
  				  TREE_OPERAND (arg1, 1), 0)
  	      && operand_equal_p (TREE_OPERAND (arg0, 1),
*************** fold (tree expr)
*** 5269,5277 ****

    /* If this is a commutative operation, and ARG0 is a constant, move it
       to ARG1 to reduce the number of tests below.  */
!   if ((code == PLUS_EXPR || code == MULT_EXPR || code == MIN_EXPR
!        || code == MAX_EXPR || code == BIT_IOR_EXPR || code == BIT_XOR_EXPR
!        || code == BIT_AND_EXPR)
        && tree_swap_operands_p (arg0, arg1, true))
      return fold (build (code, type, arg1, arg0));

--- 5263,5269 ----

    /* If this is a commutative operation, and ARG0 is a constant, move it
       to ARG1 to reduce the number of tests below.  */
!   if (commutative_tree_code (code)
        && tree_swap_operands_p (arg0, arg1, true))
      return fold (build (code, type, arg1, arg0));


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]