aboutsummaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
authorArend Bayer <arend.bayer@web.de>2003-02-16 08:24:25 +0000
committerRichard Henderson <rth@gcc.gnu.org>2003-02-16 00:24:25 -0800
commitcdd4b0d464c4873e72866d5bb9dc239141a20e28 (patch)
tree933222f0f9d27667fe6ae17f06ec0b29d2b39963 /gcc/fold-const.c
parent616f273ae71d5c3c034419a2905f41b689dfc2b3 (diff)
downloadgcc-cdd4b0d464c4873e72866d5bb9dc239141a20e28.zip
gcc-cdd4b0d464c4873e72866d5bb9dc239141a20e28.tar.gz
gcc-cdd4b0d464c4873e72866d5bb9dc239141a20e28.tar.bz2
fold-const.c (extract_muldiv_1): Rename from extract_muldiv; rearrange mult arguments for less recursion.
* fold-const.c (extract_muldiv_1): Rename from extract_muldiv; rearrange mult arguments for less recursion. (extract_muldiv): New. Prevent runaway recursion. Co-Authored-By: Richard Henderson <rth@redhat.com> From-SVN: r62963
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c34
1 files changed, 34 insertions, 0 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 0e301a7..d6f3561 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -104,6 +104,7 @@ static tree unextend PARAMS ((tree, int, int, tree));
static tree fold_truthop PARAMS ((enum tree_code, tree, tree, tree));
static tree optimize_minmax_comparison PARAMS ((tree));
static tree extract_muldiv PARAMS ((tree, tree, enum tree_code, tree));
+static tree extract_muldiv_1 PARAMS ((tree, tree, enum tree_code, tree));
static tree strip_compound_expr PARAMS ((tree, tree));
static int multiple_of_p PARAMS ((tree, tree, tree));
static tree constant_boolean_node PARAMS ((int, tree));
@@ -4046,6 +4047,31 @@ extract_muldiv (t, c, code, wide_type)
enum tree_code code;
tree wide_type;
{
+ /* To avoid exponential search depth, refuse to allow recursion past
+ three levels. Beyond that (1) it's highly unlikely that we'll find
+ something interesting and (2) we've probably processed it before
+ when we built the inner expression. */
+
+ static int depth;
+ tree ret;
+
+ if (depth > 3)
+ return NULL;
+
+ depth++;
+ ret = extract_muldiv_1 (t, c, code, wide_type);
+ depth--;
+
+ return ret;
+}
+
+static tree
+extract_muldiv_1 (t, c, code, wide_type)
+ tree t;
+ tree c;
+ enum tree_code code;
+ tree wide_type;
+{
tree type = TREE_TYPE (t);
enum tree_code tcode = TREE_CODE (t);
tree ctype = (wide_type != 0 && (GET_MODE_SIZE (TYPE_MODE (wide_type))
@@ -4254,6 +4280,14 @@ extract_muldiv (t, c, code, wide_type)
&& integer_zerop (const_binop (TRUNC_MOD_EXPR, op1, c, 0)))
return omit_one_operand (type, integer_zero_node, op0);
+ /* Arrange for the code below to simplify two constants first. */
+ if (TREE_CODE (op1) == INTEGER_CST && TREE_CODE (op0) != INTEGER_CST)
+ {
+ tree tmp = op0;
+ op0 = op1;
+ op1 = tmp;
+ }
+
/* ... fall through ... */
case TRUNC_DIV_EXPR: case CEIL_DIV_EXPR: case FLOOR_DIV_EXPR: