diff options
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r-- | gcc/fold-const.c | 45 |
1 files changed, 34 insertions, 11 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 2a78dd7..2beab08 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -96,6 +96,7 @@ static tree fold_truthop PROTO((enum tree_code, tree, tree, tree)); static tree strip_compound_expr PROTO((tree, tree)); static int multiple_of_p PROTO((tree, tree, tree)); static tree constant_boolean_node PROTO((int, tree)); +static int count_cond PROTO((tree, int)); #ifndef BRANCH_COST #define BRANCH_COST 1 @@ -2760,8 +2761,8 @@ optimize_bit_field_compare (code, compare_type, lhs, rhs) convert (unsigned_type, rhs), size_int (lbitsize), 0))) { - warning ("comparison is always %s due to width of bitfield", - code == NE_EXPR ? "one" : "zero"); + warning ("comparison is always %d due to width of bitfield", + code == NE_EXPR); return convert (compare_type, (code == NE_EXPR ? integer_one_node : integer_zero_node)); @@ -2773,8 +2774,8 @@ optimize_bit_field_compare (code, compare_type, lhs, rhs) size_int (lbitsize - 1), 0); if (! integer_zerop (tem) && ! integer_all_onesp (tem)) { - warning ("comparison is always %s due to width of bitfield", - code == NE_EXPR ? "one" : "zero"); + warning ("comparison is always %d due to width of bitfield", + code == NE_EXPR); return convert (compare_type, (code == NE_EXPR ? integer_one_node : integer_zero_node)); @@ -3541,7 +3542,6 @@ fold_range_test (exp) } } - return 0; } @@ -3804,8 +3804,7 @@ fold_truthop (code, truth_type, lhs, rhs) type, ll_mask)), 0))) { - warning ("comparison is always %s", - wanted_code == NE_EXPR ? "one" : "zero"); + warning ("comparison is always %d", wanted_code == NE_EXPR); return convert (truth_type, wanted_code == NE_EXPR @@ -3822,9 +3821,8 @@ fold_truthop (code, truth_type, lhs, rhs) type, rl_mask)), 0))) { - warning ("comparison is always %s", - wanted_code == NE_EXPR ? "one" : "zero"); - + warning ("comparison is always %d", wanted_code == NE_EXPR); + return convert (truth_type, wanted_code == NE_EXPR ? integer_one_node : integer_zero_node); @@ -3922,7 +3920,7 @@ fold_truthop (code, truth_type, lhs, rhs) } else { - warning ("`and' of mutually exclusive equal-tests is always zero"); + warning ("`and' of mutually exclusive equal-tests is always 0"); return convert (truth_type, integer_zero_node); } } @@ -3999,6 +3997,27 @@ constant_boolean_node (value, type) } } +/* Utility function for the following routine, to see how complex a nesting of + COND_EXPRs can be. EXPR is the expression and LIMIT is a count beyond which + we don't care (to avoid spending too much time on complex expressions.). */ + +static int +count_cond (expr, lim) + tree expr; + int lim; +{ + int true, false; + + if (TREE_CODE (expr) != COND_EXPR) + return 0; + else if (lim <= 0) + return 0; + + true = count_cond (TREE_OPERAND (expr, 1), lim - 1); + false = count_cond (TREE_OPERAND (expr, 2), lim - 1 - true); + return MIN (lim, 1 + true + false); +} + /* Perform constant folding and related simplification of EXPR. The related simplifications include x*1 => x, x*0 => 0, etc., and application of the associative law. @@ -4222,6 +4241,8 @@ fold (expr) 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) || (current_function_decl != 0 && ! contains_placeholder_p (arg0)))) @@ -4295,6 +4316,8 @@ fold (expr) 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) || (current_function_decl != 0 && ! contains_placeholder_p (arg1)))) |