aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Kenner <kenner@vlsi1.ultra.nyu.edu>2003-04-21 20:58:05 +0000
committerRichard Kenner <kenner@gcc.gnu.org>2003-04-21 16:58:05 -0400
commit26b84487c706cac8160048f5875f6a0e162a1095 (patch)
treeb5d1e352f5810d0e19651682c96a3da77f186d46
parent1a96dc4634533d7691e4d369658b8c9cfc473a2a (diff)
downloadgcc-26b84487c706cac8160048f5875f6a0e162a1095.zip
gcc-26b84487c706cac8160048f5875f6a0e162a1095.tar.gz
gcc-26b84487c706cac8160048f5875f6a0e162a1095.tar.bz2
fold-const.c (extract_muldiv, [...]): Detect case when conversion overflows.
* fold-const.c (extract_muldiv, case CONVERT_EXPR): Detect case when conversion overflows. From-SVN: r65900
-rw-r--r--gcc/ChangeLog3
-rw-r--r--gcc/fold-const.c23
2 files changed, 19 insertions, 7 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 9c52c0f..b27996f 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -56,6 +56,9 @@
2003-04-21 Richard Kenner <kenner@vlsi1.ultra.nyu.edu>
+ * fold-const.c (extract_muldiv, case CONVERT_EXPR): Detect case
+ when conversion overflows.
+
* stor-layout.c (layout_decl): Don't set DECL_SIZE_UNIT if already set.
* expr.c (store_constructor): Set RTX_UNCHANGING_P if readonly_field_p
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index fa64fd2..146f40f 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -4182,8 +4182,12 @@ extract_muldiv_1 (t, c, code, wide_type)
/* 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. */
- if (0 != (t1 = extract_muldiv (op0, convert (TREE_TYPE (op0), c), code,
- code == MULT_EXPR ? ctype : NULL_TREE)))
+ if ((t2 = convert (TREE_TYPE (op0), c)) != 0
+ && TREE_CODE (t2) == INTEGER_CST
+ && ! TREE_CONSTANT_OVERFLOW (t2)
+ && (0 != (t1 = extract_muldiv (op0, t2, code,
+ code == MULT_EXPR
+ ? ctype : NULL_TREE))))
return t1;
break;
@@ -5478,13 +5482,17 @@ fold (expr)
if (TREE_CODE (parg0) == MULT_EXPR
&& TREE_CODE (parg1) != MULT_EXPR)
return fold (build (PLUS_EXPR, type,
- fold (build (PLUS_EXPR, type, parg0, marg)),
- parg1));
+ fold (build (PLUS_EXPR, type,
+ convert (type, parg0),
+ convert (type, marg))),
+ convert (type, parg1)));
if (TREE_CODE (parg0) != MULT_EXPR
&& TREE_CODE (parg1) == MULT_EXPR)
return fold (build (PLUS_EXPR, type,
- fold (build (PLUS_EXPR, type, parg1, marg)),
- parg0));
+ fold (build (PLUS_EXPR, type,
+ convert (type, parg1),
+ convert (type, marg))),
+ convert (type, parg0)));
}
if (TREE_CODE (arg0) == MULT_EXPR && TREE_CODE (arg1) == MULT_EXPR)
@@ -5816,7 +5824,8 @@ fold (expr)
TREE_OPERAND (arg0, 1)));
if (TREE_CODE (arg1) == INTEGER_CST
- && 0 != (tem = extract_muldiv (TREE_OPERAND (t, 0), arg1,
+ && 0 != (tem = extract_muldiv (TREE_OPERAND (t, 0),
+ convert (type, arg1),
code, NULL_TREE)))
return convert (type, tem);