fold-const.c (extract_muldiv): Check whether c divides op1 exactly if operation is...
authorToon Moene <toon@moene.indiv.nluug.nl>
Sat, 8 Jul 2000 22:29:17 +0000 (00:29 +0200)
committerToon Moene <toon@gcc.gnu.org>
Sat, 8 Jul 2000 22:29:17 +0000 (22:29 +0000)
2000-07-08  Toon Moene  <toon@moene.indiv.nluug.nl>

* fold-const.c (extract_muldiv) case PLUS_EXPR, MINUS_EXPR:
Check whether c divides op1 exactly if operation is not
multiplication.

From-SVN: r34928

gcc/ChangeLog
gcc/fold-const.c

index 7bc499e2461cf903278d3a9cee8f8722267bdca4..4d33224b012dca9349435a804927c1d535e51151 100644 (file)
@@ -1,3 +1,9 @@
+2000-07-08  Toon Moene  <toon@moene.indiv.nluug.nl>
+
+       * fold-const.c (extract_muldiv) case PLUS_EXPR, MINUS_EXPR:
+       Check whether c divides op1 exactly if operation is not
+       multiplication.
+
 2000-07-08  Richard Henderson  <rth@cygnus.com>
 
         * final.c (final): Do not abort when reg-stack introduces
index 5cf688f61e2a2c5d239fb6916267a862637e9dcf..26ac5d27a7e56f1b56c86102e426908d1bfbae7c 100644 (file)
@@ -4501,10 +4501,17 @@ extract_muldiv (t, c, code, wide_type)
            break;
        }
 
-      /* Now do the operation and verify it doesn't overflow.  */
-      op1 = const_binop (code, convert (ctype, op1), convert (ctype, c), 0);
-      if (op1 == 0 || TREE_OVERFLOW (op1))
-       break;
+      /* If it's a multiply or a division/modulus operation of a multiple
+         of our constant, do the operation and verify it doesn't overflow.  */
+      if (code == MULT_EXPR
+         || integer_zerop (const_binop (TRUNC_MOD_EXPR, op1, c, 0)))
+        {
+          op1 = const_binop (code, convert (ctype, op1), convert (ctype, c), 0);
+          if (op1 == 0 || TREE_OVERFLOW (op1))
+            break;
+        }
+      else
+        break;
 
       /* If we have an unsigned type is not a sizetype, we cannot widen
         the operation since it will change the result if the original