aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorRichard Henderson <rth@cygnus.com>2000-07-15 10:22:26 -0700
committerRichard Henderson <rth@gcc.gnu.org>2000-07-15 10:22:26 -0700
commiteff9c80d3e2e37092e65e7cdad5e3e18b027c860 (patch)
treee5579d53bbfd68cc1b545093e50c591a58f7e5da /gcc
parentb27ca4d10ba6ce5966aa6e4b01966bcdc43a3181 (diff)
downloadgcc-eff9c80d3e2e37092e65e7cdad5e3e18b027c860.zip
gcc-eff9c80d3e2e37092e65e7cdad5e3e18b027c860.tar.gz
gcc-eff9c80d3e2e37092e65e7cdad5e3e18b027c860.tar.bz2
fold-const.c (extract_muldiv): Don't optimize past an unsigned cast around an expression.
* fold-const.c (extract_muldiv): Don't optimize past an unsigned cast around an expression. Tidy other unsigned tests. From-SVN: r35049
Diffstat (limited to 'gcc')
-rw-r--r--gcc/ChangeLog5
-rw-r--r--gcc/fold-const.c17
2 files changed, 19 insertions, 3 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index b428538..77a6af1 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,8 @@
+2000-07-15 Richard Henderson <rth@cygnus.com>
+
+ * fold-const.c (extract_muldiv): Don't optimize past an unsigned
+ cast around an expression. Tidy other unsigned tests.
+
2000-07-15 Gabriel Dos Reis <gdr@codesourcery.com>
* diagnostic.c (doing_line_wrapping, line_wrapper_printf, notice,
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index f259115..c636bdc 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -4397,6 +4397,18 @@ extract_muldiv (t, c, code, wide_type)
break;
case CONVERT_EXPR: case NON_LVALUE_EXPR: case NOP_EXPR:
+ /* If op0 is an expression, and is unsigned, and the type is
+ smaller than ctype, then we cannot widen the expression. */
+ if ((TREE_CODE_CLASS (TREE_CODE (op0)) == '<'
+ || TREE_CODE_CLASS (TREE_CODE (op0)) == '1'
+ || TREE_CODE_CLASS (TREE_CODE (op0)) == '2'
+ || TREE_CODE_CLASS (TREE_CODE (op0)) == 'e')
+ && TREE_UNSIGNED (TREE_TYPE (op0))
+ && ! TYPE_IS_SIZETYPE (TREE_TYPE (op0))
+ && (GET_MODE_SIZE (TYPE_MODE (ctype))
+ > GET_MODE_SIZE (TYPE_MODE (TREE_TYPE (op0)))))
+ break;
+
/* Pass the constant down and see if we can make a simplification. If
we can, replace this expression with the inner simplification for
possible later conversion to our or some other type. */
@@ -4413,7 +4425,7 @@ extract_muldiv (t, c, code, wide_type)
case MIN_EXPR: case MAX_EXPR:
/* If widening the type changes the signedness, then we can't perform
this optimization as that changes the result. */
- if (ctype != type && TREE_UNSIGNED (ctype) != TREE_UNSIGNED (type))
+ if (TREE_UNSIGNED (ctype) != TREE_UNSIGNED (type))
break;
/* MIN (a, b) / 5 -> MIN (a / 5, b / 5) */
@@ -4581,8 +4593,7 @@ extract_muldiv (t, c, code, wide_type)
this since it will change the result if the original computation
overflowed. */
if ((! TREE_UNSIGNED (ctype)
- || (TREE_CODE (ctype) == INTEGER_TYPE
- && TYPE_IS_SIZETYPE (ctype)))
+ || TYPE_IS_SIZETYPE (ctype))
&& ((code == MULT_EXPR && tcode == EXACT_DIV_EXPR)
|| (tcode == MULT_EXPR
&& code != TRUNC_MOD_EXPR && code != CEIL_MOD_EXPR