summaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
authorrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>2011-08-03 13:33:28 +0000
committerrguenth <rguenth@138bc75d-0d04-0410-961f-82ee72b054a4>2011-08-03 13:33:28 +0000
commit105f72b0a8bd8fe5cbc440cbc413411fecf5b3f3 (patch)
tree8d726f330bfaa34d014e6f7a8736038a869c9858 /gcc/fold-const.c
parenta52a801dbb21f7fd58673c52ab1398fcec1bb3bc (diff)
downloadgcc-105f72b0a8bd8fe5cbc440cbc413411fecf5b3f3.tar.gz
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. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@177270 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c13
1 files changed, 7 insertions, 6 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 8ad806f9eee..0cdf682ae38 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;