diff options
author | Richard Guenther <rguenther@suse.de> | 2011-08-03 13:33:28 +0000 |
---|---|---|
committer | Richard Biener <rguenth@gcc.gnu.org> | 2011-08-03 13:33:28 +0000 |
commit | a130fb24411061b0edf14203bd76ff1c3aad89b8 (patch) | |
tree | 8d726f330bfaa34d014e6f7a8736038a869c9858 /gcc/fold-const.c | |
parent | f77b022b82d2ff2a4859b2dab1f58c97ce0d1b51 (diff) | |
download | gcc-a130fb24411061b0edf14203bd76ff1c3aad89b8.zip gcc-a130fb24411061b0edf14203bd76ff1c3aad89b8.tar.gz gcc-a130fb24411061b0edf14203bd76ff1c3aad89b8.tar.bz2 |
re PR middle-end/49958 (fold performs invalid association)
2011-08-03 Richard Guenther <rguenther@suse.de>
PR middle-end/49958
* fold-const.c (fold_binary_loc): Only associate
(+ (+ (* a b) c) (* d e)) as (+ (+ (* a b) (* d e)) c) if
overflow wraps.
* gcc.dg/torture/pr49958.c: New testcase.
From-SVN: r177270
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r-- | gcc/fold-const.c | 13 |
1 files changed, 7 insertions, 6 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 8ad806f..0cdf682 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -9711,12 +9711,13 @@ fold_binary_loc (location_t loc, /* 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 - || TREE_CODE (arg0) == MINUS_EXPR) - && TREE_CODE (arg1) == MULT_EXPR) - || ((TREE_CODE (arg1) == PLUS_EXPR - || TREE_CODE (arg1) == MINUS_EXPR) - && TREE_CODE (arg0) == MULT_EXPR)) + if (TYPE_OVERFLOW_WRAPS (type) + && (((TREE_CODE (arg0) == PLUS_EXPR + || TREE_CODE (arg0) == MINUS_EXPR) + && TREE_CODE (arg1) == MULT_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; |