aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRichard Guenther <rguenther@suse.de>2007-11-12 14:16:05 +0000
committerRichard Guenther <rguenther@suse.de>2007-11-12 14:16:05 +0000
commit0e24095702120cd886820bfc4c61bb306a629290 (patch)
treefb294631ce72ef4c2afc3cd1f59f93a16cf0896a
parent608eab07d87470d6f41f40d1a98f2eebc536ff9a (diff)
2007-11-12 Richard Guenther <rguenther@suse.de>
PR middle-end/34070 * fold-const.c (fold_binary): If testing for non-negative operands with tree_expr_nonnegative_warnv_p make sure to use op0 which has all (sign) conversions retained. * gcc.c-torture/execute/pr34070-1.c: New testcase. * gcc.c-torture/execute/pr34070-2.c: Likewise. git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@130098 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/ChangeLog7
-rw-r--r--gcc/fold-const.c4
-rw-r--r--gcc/testsuite/ChangeLog6
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/pr34070-1.c13
-rw-r--r--gcc/testsuite/gcc.c-torture/execute/pr34070-2.c13
5 files changed, 41 insertions, 2 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index b95f35d9679..5b6c7306d57 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,5 +1,12 @@
2007-11-12 Richard Guenther <rguenther@suse.de>
+ PR middle-end/34070
+ * fold-const.c (fold_binary): If testing for non-negative
+ operands with tree_expr_nonnegative_warnv_p make sure to
+ use op0 which has all (sign) conversions retained.
+
+2007-11-12 Richard Guenther <rguenther@suse.de>
+
PR middle-end/34027
* fold-const.c (fold_binary): Fold n - (n / m) * m to n % m.
(fold_binary): Fold unsinged FLOOR_DIV_EXPR to TRUNC_DIV_EXPR.
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 5b81d88fd57..0d6524e7fd2 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -11230,7 +11230,7 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1)
strict_overflow_p = false;
if (TREE_CODE (arg1) == LSHIFT_EXPR
&& (TYPE_UNSIGNED (type)
- || tree_expr_nonnegative_warnv_p (arg0, &strict_overflow_p)))
+ || tree_expr_nonnegative_warnv_p (op0, &strict_overflow_p)))
{
tree sval = TREE_OPERAND (arg1, 0);
if (integer_pow2p (sval) && tree_int_cst_sgn (sval) > 0)
@@ -11356,7 +11356,7 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1)
strict_overflow_p = false;
if ((code == TRUNC_MOD_EXPR || code == FLOOR_MOD_EXPR)
&& (TYPE_UNSIGNED (type)
- || tree_expr_nonnegative_warnv_p (arg0, &strict_overflow_p)))
+ || tree_expr_nonnegative_warnv_p (op0, &strict_overflow_p)))
{
tree c = arg1;
/* Also optimize A % (C << N) where C is a power of 2,
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index e22485905ac..15c5e93eeab 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,11 @@
2007-11-12 Richard Guenther <rguenther@suse.de>
+ PR middle-end/34070
+ * gcc.c-torture/execute/pr34070-1.c: New testcase.
+ * gcc.c-torture/execute/pr34070-2.c: Likewise.
+
+2007-11-12 Richard Guenther <rguenther@suse.de>
+
PR middle-end/34027
* gcc.dg/pr34027-1.c: New testcase.
* gcc.dg/pr34027-2.c: Likewise.
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr34070-1.c b/gcc/testsuite/gcc.c-torture/execute/pr34070-1.c
new file mode 100644
index 00000000000..6589bb0c095
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/pr34070-1.c
@@ -0,0 +1,13 @@
+extern void abort (void);
+
+int f(unsigned int x)
+{
+ return ((int)x) % 4;
+}
+
+int main()
+{
+ if (f(-1) != -1)
+ abort ();
+ return 0;
+}
diff --git a/gcc/testsuite/gcc.c-torture/execute/pr34070-2.c b/gcc/testsuite/gcc.c-torture/execute/pr34070-2.c
new file mode 100644
index 00000000000..4c1ce7b0231
--- /dev/null
+++ b/gcc/testsuite/gcc.c-torture/execute/pr34070-2.c
@@ -0,0 +1,13 @@
+extern void abort (void);
+
+int f(unsigned int x, int n)
+{
+ return ((int)x) / (1 << n);
+}
+
+int main()
+{
+ if (f(-1, 1) != 0)
+ abort ();
+ return 0;
+}