diff options
author | Richard Guenther <rguenther@suse.de> | 2008-08-22 12:43:49 +0000 |
---|---|---|
committer | Richard Biener <rguenth@gcc.gnu.org> | 2008-08-22 12:43:49 +0000 |
commit | beeab17c6ed0733203002932c08d1d3f3fe5d053 (patch) | |
tree | 3d71422e6cc09e286c8804aef278b4add145989a /gcc/fold-const.c | |
parent | da2f5d14dfc05f9a9527ea3e0700a345857a83bc (diff) | |
download | gcc-beeab17c6ed0733203002932c08d1d3f3fe5d053.zip gcc-beeab17c6ed0733203002932c08d1d3f3fe5d053.tar.gz gcc-beeab17c6ed0733203002932c08d1d3f3fe5d053.tar.bz2 |
re PR middle-end/36548 (remainder gives the wrong result for wrapping case with unsigned types)
2008-08-22 Richard Guenther <rguenther@suse.de>
PR middle-end/36548
PR middle-end/37125
* fold-const.c (extract_muldiv_1): Optimize (X * C1) % C2 only
if the multiplication does not overflow.
* gcc.c-torture/execute/pr37125.c: New testcase.
From-SVN: r139450
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r-- | gcc/fold-const.c | 13 |
1 files changed, 12 insertions, 1 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c index cba8826..e6769a6 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -5930,9 +5930,20 @@ extract_muldiv_1 (tree t, tree c, enum tree_code code, tree wide_type, (C * 8) % 4 since we know that's zero. */ if ((code == TRUNC_MOD_EXPR || code == CEIL_MOD_EXPR || code == FLOOR_MOD_EXPR || code == ROUND_MOD_EXPR) + /* If the multiplication can overflow we cannot optimize this. + ??? Until we can properly mark individual operations as + not overflowing we need to treat sizetype special here as + stor-layout relies on this opimization to make + DECL_FIELD_BIT_OFFSET always a constant. */ + && (TYPE_OVERFLOW_UNDEFINED (TREE_TYPE (t)) + || (TREE_CODE (TREE_TYPE (t)) == INTEGER_TYPE + && TYPE_IS_SIZETYPE (TREE_TYPE (t)))) && TREE_CODE (TREE_OPERAND (t, 1)) == INTEGER_CST && integer_zerop (const_binop (TRUNC_MOD_EXPR, op1, c, 0))) - return omit_one_operand (type, integer_zero_node, op0); + { + *strict_overflow_p = true; + return omit_one_operand (type, integer_zero_node, op0); + } /* ... fall through ... */ |