Commit 3168cb99 by Jeff Law Committed by Roger Sayle

tree.c (commutative_tree_code, [...]): New functions.


	* 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): Declare.
	* fold-const.c (operand_equal_p): Use commutative_tree_code
	rather than inlining the commutativity check.
	(fold): Likewise.

Co-Authored-By: Roger Sayle <roger@eyesopen.com>

From-SVN: r77152
parent 4e0e4a49
2004-02-02 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): Declare.
* fold-const.c (operand_equal_p): Use commutative_tree_code
rather than inlining the commutativity check.
(fold): Likewise.
2004-02-02 Kazu Hirata <kazu@cs.umass.edu> 2004-02-02 Kazu Hirata <kazu@cs.umass.edu>
* system.h (FUNCTION_ARG_KEEP_AS_REFERENCE): Poison. * system.h (FUNCTION_ARG_KEEP_AS_REFERENCE): Poison.
......
...@@ -833,7 +833,6 @@ negate_mathfn_p (enum built_in_function code) ...@@ -833,7 +833,6 @@ negate_mathfn_p (enum built_in_function code)
return false; return false;
} }
/* Determine whether an expression T can be cheaply negated using /* Determine whether an expression T can be cheaply negated using
the function negate_expr. */ the function negate_expr. */
...@@ -2105,12 +2104,7 @@ operand_equal_p (tree arg0, tree arg1, int only_const) ...@@ -2105,12 +2104,7 @@ operand_equal_p (tree arg0, tree arg1, int only_const)
return 1; return 1;
/* For commutative ops, allow the other order. */ /* For commutative ops, allow the other order. */
return ((TREE_CODE (arg0) == PLUS_EXPR || TREE_CODE (arg0) == MULT_EXPR return (commutative_tree_code (TREE_CODE (arg0))
|| 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), && operand_equal_p (TREE_OPERAND (arg0, 0),
TREE_OPERAND (arg1, 1), 0) TREE_OPERAND (arg1, 1), 0)
&& operand_equal_p (TREE_OPERAND (arg0, 1), && operand_equal_p (TREE_OPERAND (arg0, 1),
...@@ -5299,9 +5293,7 @@ fold (tree expr) ...@@ -5299,9 +5293,7 @@ fold (tree expr)
/* If this is a commutative operation, and ARG0 is a constant, move it /* If this is a commutative operation, and ARG0 is a constant, move it
to ARG1 to reduce the number of tests below. */ to ARG1 to reduce the number of tests below. */
if ((code == PLUS_EXPR || code == MULT_EXPR || code == MIN_EXPR if (commutative_tree_code (code)
|| code == MAX_EXPR || code == BIT_IOR_EXPR || code == BIT_XOR_EXPR
|| code == BIT_AND_EXPR)
&& tree_swap_operands_p (arg0, arg1, true)) && tree_swap_operands_p (arg0, arg1, true))
return fold (build (code, type, arg1, arg0)); return fold (build (code, type, arg1, arg0));
......
...@@ -3538,6 +3538,55 @@ compare_tree_int (tree t, unsigned HOST_WIDE_INT u) ...@@ -3538,6 +3538,55 @@ compare_tree_int (tree t, unsigned HOST_WIDE_INT u)
return 1; 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 /* Generate a hash value for an expression. This can be used iteratively
by passing a previous result as the "val" argument. by passing a previous result as the "val" argument.
...@@ -3595,9 +3644,7 @@ iterative_hash_expr (tree t, hashval_t val) ...@@ -3595,9 +3644,7 @@ iterative_hash_expr (tree t, hashval_t val)
|| code == NON_LVALUE_EXPR) || code == NON_LVALUE_EXPR)
val = iterative_hash_object (TREE_TYPE (t), val); val = iterative_hash_object (TREE_TYPE (t), val);
if (code == PLUS_EXPR || code == MULT_EXPR || code == MIN_EXPR if (commutative_tree_code (code))
|| 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 /* It's a commutative expression. We want to hash it the same
however it appears. We do this by first hashing both operands however it appears. We do this by first hashing both operands
......
...@@ -2713,6 +2713,8 @@ extern tree get_callee_fndecl (tree); ...@@ -2713,6 +2713,8 @@ extern tree get_callee_fndecl (tree);
extern void change_decl_assembler_name (tree, tree); extern void change_decl_assembler_name (tree, tree);
extern int type_num_arguments (tree); extern int type_num_arguments (tree);
extern tree lhd_unsave_expr_now (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 */ /* In stmt.c */
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment