diff options
author | jakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4> | 2013-04-11 07:30:20 +0000 |
---|---|---|
committer | jakub <jakub@138bc75d-0d04-0410-961f-82ee72b054a4> | 2013-04-11 07:30:20 +0000 |
commit | 4debb32673b9a4f480ee333f812b28460ca80179 (patch) | |
tree | cfb012f8c9037ad4b63ec4f3e82cbc88f9a21773 /gcc/fold-const.c | |
parent | a0ca7f3ded60c309d018df2b6f10a438bd30afe4 (diff) | |
download | gcc-4debb32673b9a4f480ee333f812b28460ca80179.tar.gz |
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.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@197692 138bc75d-0d04-0410-961f-82ee72b054a4
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 dcf7aa0d6a5..467b6d65619 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), |