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 to iterative_hash_expr


iterative_hash_expr was failing to produce the same hash code for
commutative expressions--operand_equal_p returns true for a*b and b*a, but
iterative_hash_expr was giving different results.

Fixed thus.  Tested athlon-pc-linux-gnu, applied to trunk and tree-ssa.

2003-05-27  Jason Merrill  <jason@redhat.com>

	* tree.c (iterative_hash_expr): Hash commutative expressions
	consistently.

*** tree.c.~1~	2003-05-24 14:56:05.000000000 -0400
--- tree.c	2003-05-27 10:31:48.000000000 -0400
*************** iterative_hash_expr (tree t, hashval_t v
*** 3552,3560 ****
        if (code == NOP_EXPR || code == CONVERT_EXPR
  	  || code == NON_LVALUE_EXPR)
  	val = iterative_hash_object (TREE_TYPE (t), val);
!   
!       for (i = first_rtl_op (code) - 1; i >= 0; --i)
! 	val = iterative_hash_expr (TREE_OPERAND (t, i), val);
      }
    else if (code == TREE_LIST)
      {
--- 3578,3605 ----
        if (code == NOP_EXPR || code == CONVERT_EXPR
  	  || 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
! 	     and then rehashing based on the order of their independent
! 	     hashes.  */
! 	  hashval_t one = iterative_hash_expr (TREE_OPERAND (t, 0), 0);
! 	  hashval_t two = iterative_hash_expr (TREE_OPERAND (t, 1), 0);
! 	  hashval_t t;
! 
! 	  if (one > two)
! 	    t = one, one = two, two = t;
! 
! 	  val = iterative_hash_object (one, val);
! 	  val = iterative_hash_object (two, val);
! 	}
!       else
! 	for (i = first_rtl_op (code) - 1; i >= 0; --i)
! 	  val = iterative_hash_expr (TREE_OPERAND (t, i), val);
      }
    else if (code == TREE_LIST)
      {

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