aboutsummaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
authorFariborz Jahanian <fjahanian@apple.com>2004-03-30 20:00:23 +0000
committerFariborz Jahanian <fjahanian@gcc.gnu.org>2004-03-30 20:00:23 +0000
commit0af5da7fb02b22c775094c868ea907b69ec7a3c1 (patch)
treeec2e191c5a9154e212b3e213108a31cd8ca98477 /gcc/fold-const.c
parentcfdfa11075770af7e2c8b0d3fd7e17d066c7385d (diff)
downloadgcc-0af5da7fb02b22c775094c868ea907b69ec7a3c1.zip
gcc-0af5da7fb02b22c775094c868ea907b69ec7a3c1.tar.gz
gcc-0af5da7fb02b22c775094c868ea907b69ec7a3c1.tar.bz2
Reassociate multiply expression with an adjacent non-multiply expression.
Reviewed by Roger Sayle. From-SVN: r80093
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c30
1 files changed, 30 insertions, 0 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 7fbbc8e..9be1cea 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -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: