Commit b3e65ebb by Roger Sayle Committed by Roger Sayle

fold-const.c (fold_binary_op_with_conditional_arg): Tweak calling convention to…

fold-const.c (fold_binary_op_with_conditional_arg): Tweak calling convention to allow a NULL_TREE to be returned.


	* fold-const.c (fold_binary_op_with_conditional_arg):  Tweak
	calling convention to allow a NULL_TREE to be returned.  Factor
	sanity checks from callers, return NULL_TREE when appropriate.
	(fold): Handle COMPOUND_EXPR operands of binary expressions
	before COND_EXPR operands.  Use reorder_operands_p(a,b) to check
	whether a op (b,c) can be rewritten as (b, a op c).  Simplify
	calls to fold_binary_op_with_conditional_arg.

From-SVN: r80609
parent 19d33948
2004-04-11 Roger Sayle <roger@eyesopen.com>
* fold-const.c (fold_binary_op_with_conditional_arg): Tweak
calling convention to allow a NULL_TREE to be returned. Factor
sanity checks from callers, return NULL_TREE when appropriate.
(fold): Handle COMPOUND_EXPR operands of binary expressions
before COND_EXPR operands. Use reorder_operands_p(a,b) to check
whether a op (b,c) can be rewritten as (b, a op c). Simplify
calls to fold_binary_op_with_conditional_arg.
2004-04-11 Kaveh R. Ghazi <ghazi@caip.rutgers.edu> 2004-04-11 Kaveh R. Ghazi <ghazi@caip.rutgers.edu>
* config/mips/iris5.h (current_section_flags): Add * config/mips/iris5.h (current_section_flags): Add
......
...@@ -4807,7 +4807,8 @@ count_cond (tree expr, int lim) ...@@ -4807,7 +4807,8 @@ count_cond (tree expr, int lim)
expression, and ARG to `a'. If COND_FIRST_P is nonzero, then the expression, and ARG to `a'. If COND_FIRST_P is nonzero, then the
COND is the first argument to CODE; otherwise (as in the example COND is the first argument to CODE; otherwise (as in the example
given here), it is the second argument. TYPE is the type of the given here), it is the second argument. TYPE is the type of the
original expression. */ original expression. Return NULL_TREE if no simplication is
possible. */
static tree static tree
fold_binary_op_with_conditional_arg (enum tree_code code, tree type, fold_binary_op_with_conditional_arg (enum tree_code code, tree type,
...@@ -4837,6 +4838,19 @@ fold_binary_op_with_conditional_arg (enum tree_code code, tree type, ...@@ -4837,6 +4838,19 @@ fold_binary_op_with_conditional_arg (enum tree_code code, tree type,
tree rhs_type = type; tree rhs_type = type;
int save = 0; int save = 0;
if (TREE_CODE (cond) != COND_EXPR
&& TREE_CODE_CLASS (code) == '<')
return NULL_TREE;
if (TREE_CODE (arg) == COND_EXPR
&& count_cond (cond, 25) + count_cond (arg, 25) > 25)
return NULL_TREE;
if (TREE_SIDE_EFFECTS (arg)
&& (lang_hooks.decls.global_bindings_p () != 0
|| CONTAINS_PLACEHOLDER_P (arg)))
return NULL_TREE;
if (cond_first_p) if (cond_first_p)
{ {
true_rhs = false_rhs = &arg; true_rhs = false_rhs = &arg;
...@@ -5578,37 +5592,32 @@ fold (tree expr) ...@@ -5578,37 +5592,32 @@ fold (tree expr)
else if (TREE_CODE_CLASS (code) == '2' else if (TREE_CODE_CLASS (code) == '2'
|| TREE_CODE_CLASS (code) == '<') || TREE_CODE_CLASS (code) == '<')
{ {
if (TREE_CODE (arg0) == COMPOUND_EXPR)
return build (COMPOUND_EXPR, type, TREE_OPERAND (arg0, 0),
fold (build (code, type, TREE_OPERAND (arg0, 1), arg1)));
if (TREE_CODE (arg1) == COMPOUND_EXPR if (TREE_CODE (arg1) == COMPOUND_EXPR
&& ! TREE_SIDE_EFFECTS (TREE_OPERAND (arg1, 0)) && reorder_operands_p (arg0, TREE_OPERAND (arg1, 0)))
&& ! TREE_SIDE_EFFECTS (arg0))
return build (COMPOUND_EXPR, type, TREE_OPERAND (arg1, 0), return build (COMPOUND_EXPR, type, TREE_OPERAND (arg1, 0),
fold (build (code, type, fold (build (code, type,
arg0, TREE_OPERAND (arg1, 1)))); arg0, TREE_OPERAND (arg1, 1))));
else if ((TREE_CODE (arg1) == COND_EXPR
|| (TREE_CODE_CLASS (TREE_CODE (arg1)) == '<' if (TREE_CODE (arg0) == COND_EXPR
&& TREE_CODE_CLASS (code) != '<')) || TREE_CODE_CLASS (TREE_CODE (arg0)) == '<')
&& (TREE_CODE (arg0) != COND_EXPR {
|| count_cond (arg0, 25) + count_cond (arg1, 25) <= 25) tem = fold_binary_op_with_conditional_arg (code, type, arg0, arg1,
&& (! TREE_SIDE_EFFECTS (arg0) /*cond_first_p=*/1);
|| (lang_hooks.decls.global_bindings_p () == 0 if (tem != NULL_TREE)
&& ! CONTAINS_PLACEHOLDER_P (arg0)))) return tem;
return }
fold_binary_op_with_conditional_arg (code, type, arg1, arg0,
/*cond_first_p=*/0); if (TREE_CODE (arg1) == COND_EXPR
else if (TREE_CODE (arg0) == COMPOUND_EXPR) || TREE_CODE_CLASS (TREE_CODE (arg1)) == '<')
return build (COMPOUND_EXPR, type, TREE_OPERAND (arg0, 0), {
fold (build (code, type, TREE_OPERAND (arg0, 1), arg1))); tem = fold_binary_op_with_conditional_arg (code, type, arg1, arg0,
else if ((TREE_CODE (arg0) == COND_EXPR /*cond_first_p=*/0);
|| (TREE_CODE_CLASS (TREE_CODE (arg0)) == '<' if (tem != NULL_TREE)
&& TREE_CODE_CLASS (code) != '<')) return tem;
&& (TREE_CODE (arg1) != COND_EXPR }
|| count_cond (arg0, 25) + count_cond (arg1, 25) <= 25)
&& (! TREE_SIDE_EFFECTS (arg1)
|| (lang_hooks.decls.global_bindings_p () == 0
&& ! CONTAINS_PLACEHOLDER_P (arg1))))
return
fold_binary_op_with_conditional_arg (code, type, arg0, arg1,
/*cond_first_p=*/1);
} }
switch (code) switch (code)
......
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