Reassociate multiply expression with an adjacent non-multiply expression.
authorFariborz Jahanian <fjahanian@apple.com>
Tue, 30 Mar 2004 20:00:23 +0000 (20:00 +0000)
committerFariborz Jahanian <fjahanian@gcc.gnu.org>
Tue, 30 Mar 2004 20:00:23 +0000 (20:00 +0000)
Reviewed by Roger Sayle.

From-SVN: r80093

gcc/ChangeLog
gcc/fold-const.c

index 7500a8c7311c2b139082d285edb85bc7d91dc0c5..61813c4529e09c2b8852b4a879bdc684a5ac2ac3 100644 (file)
@@ -1,3 +1,9 @@
+2004-03-29  Fariborz Jahanian <fjahanian@apple.com>
+
+        * fold-const.c (fold): Reassociate multiply expression
+        with an adjacent non-multiply expression to use
+        architecture's multiply-add instruction.
+
 2004-03-30  Zack Weinberg  <zack@codesourcery.com>
 
        * gengtype.c (create_option): New function.
index 7fbbc8ec8b5b98606315fdc84a7c0041d5de8190..9be1ceae02373c35e35885cbec2f2e6dcd396df6 100644 (file)
@@ -6042,6 +6042,36 @@ fold (tree expr)
                                  TREE_OPERAND (arg0, 0),
                                  build_real (type, c1)));
            }
+          /* Convert a + (b*c + d*e) into (a + b*c) + d*e */
+          if (flag_unsafe_math_optimizations
+              && TREE_CODE (arg1) == PLUS_EXPR
+              && TREE_CODE (arg0) != MULT_EXPR)
+            {
+              tree tree10 = TREE_OPERAND (arg1, 0);
+              tree tree11 = TREE_OPERAND (arg1, 1);
+              if (TREE_CODE (tree11) == MULT_EXPR
+                 && TREE_CODE (tree10) == MULT_EXPR)
+                {
+                  tree tree0;
+                  tree0 = fold (build (PLUS_EXPR, type, arg0, tree10));
+                  return fold (build (PLUS_EXPR, type, tree0, tree11));
+                }
+            }
+          /* Convert (b*c + d*e) + a into b*c + (d*e +a) */
+          if (flag_unsafe_math_optimizations
+              && TREE_CODE (arg0) == PLUS_EXPR
+              && TREE_CODE (arg1) != MULT_EXPR)
+            {
+              tree tree00 = TREE_OPERAND (arg0, 0);
+              tree tree01 = TREE_OPERAND (arg0, 1);
+              if (TREE_CODE (tree01) == MULT_EXPR
+                 && TREE_CODE (tree00) == MULT_EXPR)
+                {
+                  tree tree0;
+                  tree0 = fold (build (PLUS_EXPR, type, tree01, arg1));
+                  return fold (build (PLUS_EXPR, type, tree00, tree0));
+                }
+            }
        }
 
      bit_rotate: