diff options
author | rakdver <rakdver@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-11-02 21:31:20 +0000 |
---|---|---|
committer | rakdver <rakdver@138bc75d-0d04-0410-961f-82ee72b054a4> | 2004-11-02 21:31:20 +0000 |
commit | 97c2d44fc222dc1fc703bf570fcc75a12e9f3af7 (patch) | |
tree | e48aabceb4bd08808fc31d0bf20e2e5d8949bada /gcc | |
parent | 0abf128a9136437ee43464a22e00309cd27d6c91 (diff) | |
download | gcc-97c2d44fc222dc1fc703bf570fcc75a12e9f3af7.tar.gz |
* fold-const.c (fold): Reassociate also (x - mult) + mult and
(mult - x) + mult. Cast operands of expression after applying
distributive law to the correct types. Apply distributive law
to a * c - b * c for all non-float types.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@90000 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 7 | ||||
-rw-r--r-- | gcc/fold-const.c | 26 |
2 files changed, 23 insertions, 10 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 51cf8269694..f1234bacec6 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2004-11-02 Zdenek Dvorak <dvorakz@suse.cz> + + * fold-const.c (fold): Reassociate also (x - mult) + mult and + (mult - x) + mult. Cast operands of expression after applying + distributive law to the correct types. Apply distributive law + to a * c - b * c for all non-float types. + 2004-11-02 Geoffrey Keating <geoffk@apple.com> * configure.ac: Don't clear STMP_FIXINC or STMP_FIXPROTO just diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 00892f4abb0..01054d192bd 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -6586,17 +6586,21 @@ fold (tree expr) /* Reassociate (plus (plus (mult) (foo)) (mult)) as (plus (plus (mult) (mult)) (foo)) so that we can take advantage of the factoring cases below. */ - if ((TREE_CODE (arg0) == PLUS_EXPR + if (((TREE_CODE (arg0) == PLUS_EXPR + || TREE_CODE (arg0) == MINUS_EXPR) && TREE_CODE (arg1) == MULT_EXPR) - || (TREE_CODE (arg1) == PLUS_EXPR + || ((TREE_CODE (arg1) == PLUS_EXPR + || TREE_CODE (arg1) == MINUS_EXPR) && TREE_CODE (arg0) == MULT_EXPR)) { tree parg0, parg1, parg, marg; + enum tree_code pcode; - if (TREE_CODE (arg0) == PLUS_EXPR) + if (TREE_CODE (arg1) == MULT_EXPR) parg = arg0, marg = arg1; else parg = arg1, marg = arg0; + pcode = TREE_CODE (parg); parg0 = TREE_OPERAND (parg, 0); parg1 = TREE_OPERAND (parg, 1); STRIP_NOPS (parg0); @@ -6604,7 +6608,7 @@ fold (tree expr) if (TREE_CODE (parg0) == MULT_EXPR && TREE_CODE (parg1) != MULT_EXPR) - return fold (build2 (PLUS_EXPR, type, + return fold (build2 (pcode, type, fold (build2 (PLUS_EXPR, type, fold_convert (type, parg0), fold_convert (type, marg))), @@ -6612,10 +6616,11 @@ fold (tree expr) if (TREE_CODE (parg0) != MULT_EXPR && TREE_CODE (parg1) == MULT_EXPR) return fold (build2 (PLUS_EXPR, type, - fold (build2 (PLUS_EXPR, type, - fold_convert (type, parg1), - fold_convert (type, marg))), - fold_convert (type, parg0))); + fold_convert (type, parg0), + fold (build2 (pcode, type, + fold_convert (type, marg), + fold_convert (type, + parg1))))); } if (TREE_CODE (arg0) == MULT_EXPR && TREE_CODE (arg1) == MULT_EXPR) @@ -6677,7 +6682,8 @@ fold (tree expr) if (same) return fold (build2 (MULT_EXPR, type, fold (build2 (PLUS_EXPR, type, - alt0, alt1)), + fold_convert (type, alt0), + fold_convert (type, alt1))), same)); } @@ -7084,7 +7090,7 @@ fold (tree expr) if (TREE_CODE (arg0) == MULT_EXPR && TREE_CODE (arg1) == MULT_EXPR - && (INTEGRAL_TYPE_P (type) || flag_unsafe_math_optimizations)) + && (!FLOAT_TYPE_P (type) || flag_unsafe_math_optimizations)) { /* (A * C) - (B * C) -> (A-B) * C. */ if (operand_equal_p (TREE_OPERAND (arg0, 1), |