aboutsummaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
authorRoger Sayle <roger@eyesopen.com>2004-04-11 21:18:40 +0000
committerRoger Sayle <sayle@gcc.gnu.org>2004-04-11 21:18:40 +0000
commitb3e65ebba923d11c5988bc01babc3bb75147af77 (patch)
tree2c08eedba3d2c19905334e4142402a18798acf01 /gcc/fold-const.c
parent19d33948f22884d8dbd4ac9cffbbb84768b2e498 (diff)
downloadgcc-b3e65ebba923d11c5988bc01babc3bb75147af77.zip
gcc-b3e65ebba923d11c5988bc01babc3bb75147af77.tar.gz
gcc-b3e65ebba923d11c5988bc01babc3bb75147af77.tar.bz2
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
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c65
1 files changed, 37 insertions, 28 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index e0d2adc..75ef65c 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -4807,7 +4807,8 @@ count_cond (tree expr, int lim)
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
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
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;
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)
{
true_rhs = false_rhs = &arg;
@@ -5578,37 +5592,32 @@ fold (tree expr)
else if (TREE_CODE_CLASS (code) == '2'
|| 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
- && ! TREE_SIDE_EFFECTS (TREE_OPERAND (arg1, 0))
- && ! TREE_SIDE_EFFECTS (arg0))
+ && reorder_operands_p (arg0, TREE_OPERAND (arg1, 0)))
return build (COMPOUND_EXPR, type, TREE_OPERAND (arg1, 0),
fold (build (code, type,
arg0, TREE_OPERAND (arg1, 1))));
- else if ((TREE_CODE (arg1) == COND_EXPR
- || (TREE_CODE_CLASS (TREE_CODE (arg1)) == '<'
- && TREE_CODE_CLASS (code) != '<'))
- && (TREE_CODE (arg0) != COND_EXPR
- || count_cond (arg0, 25) + count_cond (arg1, 25) <= 25)
- && (! TREE_SIDE_EFFECTS (arg0)
- || (lang_hooks.decls.global_bindings_p () == 0
- && ! CONTAINS_PLACEHOLDER_P (arg0))))
- return
- fold_binary_op_with_conditional_arg (code, type, arg1, arg0,
- /*cond_first_p=*/0);
- else if (TREE_CODE (arg0) == COMPOUND_EXPR)
- return build (COMPOUND_EXPR, type, TREE_OPERAND (arg0, 0),
- fold (build (code, type, TREE_OPERAND (arg0, 1), arg1)));
- else if ((TREE_CODE (arg0) == COND_EXPR
- || (TREE_CODE_CLASS (TREE_CODE (arg0)) == '<'
- && TREE_CODE_CLASS (code) != '<'))
- && (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);
+
+ if (TREE_CODE (arg0) == COND_EXPR
+ || TREE_CODE_CLASS (TREE_CODE (arg0)) == '<')
+ {
+ tem = fold_binary_op_with_conditional_arg (code, type, arg0, arg1,
+ /*cond_first_p=*/1);
+ if (tem != NULL_TREE)
+ return tem;
+ }
+
+ if (TREE_CODE (arg1) == COND_EXPR
+ || TREE_CODE_CLASS (TREE_CODE (arg1)) == '<')
+ {
+ tem = fold_binary_op_with_conditional_arg (code, type, arg1, arg0,
+ /*cond_first_p=*/0);
+ if (tem != NULL_TREE)
+ return tem;
+ }
}
switch (code)