]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
fold-const.c (extract_muldiv_1): Rename from extract_muldiv; rearrange mult arguments...
authorArend Bayer <arend.bayer@web.de>
Sun, 16 Feb 2003 08:28:04 +0000 (08:28 +0000)
committerRichard Henderson <rth@gcc.gnu.org>
Sun, 16 Feb 2003 08:28:04 +0000 (00:28 -0800)
        * 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: r62967

gcc/ChangeLog
gcc/fold-const.c

index 799530225822e3aa4bb86e6ca33eedfa331a7fd6..5c68c15405755dbffd71929b2b0a79f479ddee0b 100644 (file)
@@ -1,3 +1,11 @@
+2003-02-16 Arend Bayer <arend.bayer@web.de>
+           Richard Henderson  <rth@redhat.com>
+
+       PR c/8068
+        * fold-const.c (extract_muldiv_1): Rename from extract_muldiv;
+        rearrange mult arguments for less recursion.
+        (extract_muldiv): New.  Prevent runaway recursion.
+
 2003-02-14  Falk Hueffner  <falk.hueffner@student.uni-tuebingen.de>
 
        PR optimization/7702
index ef247174d91226ad09a70f9bdb5e4fbc1d1e9a62..ccf0a7cc2158026d94c98c270b5c40416c234458 100644 (file)
@@ -102,6 +102,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));
@@ -4484,6 +4485,31 @@ extract_muldiv (t, c, code, wide_type)
      tree c;
      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);
@@ -4693,6 +4719,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: