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]

[tree-ssa] Factor some code



This is just code factoring.  I'm going to need associative_tree_code
shortly in tree-ssa-dom.c.

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

Index: fold-const.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.213.2.45
diff -c -3 -p -r1.213.2.45 fold-const.c
*** fold-const.c	21 Aug 2003 07:44:56 -0000	1.213.2.45
--- fold-const.c	18 Sep 2003 18:17:03 -0000
*************** operand_equal_p (tree arg0, tree arg1, i
*** 1950,1961 ****
  	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),
--- 1950,1956 ----
  	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)
*** 5088,5096 ****
  
    /* 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_CODE (arg0) == INTEGER_CST && TREE_CODE (arg1) != 
INTEGER_CST)
  	  || (TREE_CODE (arg0) == REAL_CST && TREE_CODE (arg1) != REAL_CST)))
      {
--- 5083,5089 ----
  
    /* 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_CODE (arg0) == INTEGER_CST && TREE_CODE (arg1) != 
INTEGER_CST)
  	  || (TREE_CODE (arg0) == REAL_CST && TREE_CODE (arg1) != REAL_CST)))
      {
*************** nondestructive_fold_binary_to_constant (
*** 8854,8862 ****
  
    /* 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_CODE (op0) == INTEGER_CST || TREE_CODE (op0) == REAL_CST))
      {
        tem = op0;
--- 8847,8853 ----
  
    /* 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_CODE (op0) == INTEGER_CST || TREE_CODE (op0) == REAL_CST))
      {
        tem = op0;
Index: tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree.h,v
retrieving revision 1.342.2.99
diff -c -3 -p -r1.342.2.99 tree.h
*** tree.h	18 Sep 2003 00:19:27 -0000	1.342.2.99
--- tree.h	18 Sep 2003 18:17:11 -0000
*************** extern void set_decl_assembler_name (tre
*** 3064,3069 ****
--- 3064,3071 ----
  extern int type_num_arguments (tree);
  extern tree lhd_unsave_expr_now (tree);
  extern bool is_essa_node (tree);
+ extern bool associative_tree_code (enum tree_code);
+ extern bool commutative_tree_code (enum tree_code);
  
  
  /* In stmt.c */
Index: tree.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree.c,v
retrieving revision 1.263.2.52
diff -c -3 -p -r1.263.2.52 tree.c
*** tree.c	17 Sep 2003 23:53:46 -0000	1.263.2.52
--- tree.c	18 Sep 2003 18:17:20 -0000
*************** compare_tree_int (tree t, unsigned HOST_
*** 3475,3480 ****
--- 3475,3513 ----
      return 1;
  }
  
+ /* Return true if CODE represents an associative tree code.  Otherwise
+    return false.  */
+ bool
+ associative_tree_code (enum tree_code code)
+ {
+   return (code == BIT_IOR_EXPR
+ 	  || code == BIT_AND_EXPR
+ 	  || code == BIT_XOR_EXPR
+ 	  || code == PLUS_EXPR
+ 	  || code == MINUS_EXPR
+ 	  || code == MULT_EXPR
+ 	  || code == LSHIFT_EXPR
+ 	  || code == RSHIFT_EXPR
+ 	  || code == MIN_EXPR
+ 	  || code == MAX_EXPR);
+ }
+ 
+ /* Return true if CODE represents an commutative tree code.  Otherwise
+    return false.  */
+ bool
+ commutative_tree_code (enum tree_code code)
+ {
+   return (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);
+ }
+ 
  /* 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
*** 3540,3548 ****
  	  val = iterative_hash_expr (TREE_OPERAND (t, 0), 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
--- 3573,3579 ----
  	  val = iterative_hash_expr (TREE_OPERAND (t, 0), 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 Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]