fold-const.c (fold): For ((a * C1) / C3) or (((a * C1) + C2) / C3) optimizations...
authorToon Moene <toon@moene.indiv.nluug.nl>
Tue, 28 Oct 1997 19:02:23 +0000 (20:02 +0100)
committerJeff Law <law@gcc.gnu.org>
Tue, 28 Oct 1997 19:02:23 +0000 (12:02 -0700)
        * fold-const.c (fold): For ((a * C1) / C3) or (((a * C1) + C2) / C3)
        optimizations, look inside dividend to determine if the expression
        can be simplified by using EXACT_DIV_EXPR.

From-SVN: r16216

gcc/ChangeLog
gcc/fold-const.c

index 9d7055e7d209cef5be7af046652addcec2915942..0b3f40f3f6e8ae9306cefffa80f12cd03fe63bd9 100644 (file)
@@ -1,3 +1,9 @@
+Tue Oct 28 11:58:40 1997  Toon Moene  <toon@moene.indiv.nluug.nl>
+
+       * fold-const.c (fold): For ((a * C1) / C3) or (((a * C1) + C2) / C3)
+       optimizations, look inside dividend to determine if the expression
+       can be simplified by using EXACT_DIV_EXPR.
+
 Tue Oct 28 10:19:01 1997  Jason Merrill  <jason@yorick.cygnus.com>
 
        From Brendan:
index 1e823fbf4c71efbcc9bdd50ffe5c3689c60baa2d..da18997acc335751d216c4975a1ef3476a113852 100644 (file)
@@ -4655,6 +4655,37 @@ fold (expr)
 
          STRIP_NOPS (xarg0);
 
+         /* Look inside the dividend and simplify using EXACT_DIV_EXPR
+            if possible.  */
+         if (TREE_CODE (xarg0) == MULT_EXPR
+             && multiple_of_p (type, TREE_OPERAND (xarg0, 0), arg1))
+           {
+             tree t;
+
+             t = fold (build (MULT_EXPR, type,
+                              fold (build (EXACT_DIV_EXPR, type,
+                                           TREE_OPERAND (xarg0, 0), arg1)),
+                              TREE_OPERAND (xarg0, 1)));
+             if (have_save_expr)
+               t = save_expr (t);
+             return t;
+
+           }
+
+         if (TREE_CODE (xarg0) == MULT_EXPR
+             && multiple_of_p (type, TREE_OPERAND (xarg0, 1), arg1))
+           {
+             tree t;
+
+             t = fold (build (MULT_EXPR, type,
+                              fold (build (EXACT_DIV_EXPR, type,
+                                           TREE_OPERAND (xarg0, 1), arg1)),
+                              TREE_OPERAND (xarg0, 0)));
+             if (have_save_expr)
+               t = save_expr (t);
+             return t;
+           }
+
          if (TREE_CODE (xarg0) == PLUS_EXPR
              && TREE_CODE (TREE_OPERAND (xarg0, 1)) == INTEGER_CST)
            c2 = TREE_OPERAND (xarg0, 1), xarg0 = TREE_OPERAND (xarg0, 0);