diff options
author | Jakub Jelinek <jakub@redhat.com> | 2013-04-11 09:30:20 +0200 |
---|---|---|
committer | Jakub Jelinek <jakub@gcc.gnu.org> | 2013-04-11 09:30:20 +0200 |
commit | 146b8692e33b78872476435d084d5062a243a200 (patch) | |
tree | cfb012f8c9037ad4b63ec4f3e82cbc88f9a21773 /gcc/fold-const.c | |
parent | b8578ff77f8ea4d23fa5edc2805e1f3625b46c14 (diff) | |
download | gcc-146b8692e33b78872476435d084d5062a243a200.zip gcc-146b8692e33b78872476435d084d5062a243a200.tar.gz gcc-146b8692e33b78872476435d084d5062a243a200.tar.bz2 |
re PR tree-optimization/56899 (Wrong constant folding)
PR tree-optimization/56899
* fold-const.c (extract_muldiv_1): Apply distributive law
only if TYPE_OVERFLOW_WRAPS (ctype).
* gcc.c-torture/execute/pr56899.c: New test.
From-SVN: r197692
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r-- | gcc/fold-const.c | 6 |
1 files changed, 4 insertions, 2 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c index dcf7aa0..467b6d6 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -5850,8 +5850,10 @@ extract_muldiv_1 (tree t, tree c, enum tree_code code, tree wide_type, /* The last case is if we are a multiply. In that case, we can apply the distributive law to commute the multiply and addition - if the multiplication of the constants doesn't overflow. */ - if (code == MULT_EXPR) + if the multiplication of the constants doesn't overflow + and overflow is defined. With undefined overflow + op0 * c might overflow, while (op0 + orig_op1) * c doesn't. */ + if (code == MULT_EXPR && TYPE_OVERFLOW_WRAPS (ctype)) return fold_build2 (tcode, ctype, fold_build2 (code, ctype, fold_convert (ctype, op0), |