summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--gcc/ChangeLog7
-rw-r--r--gcc/fold-const.c32
-rw-r--r--gcc/testsuite/ChangeLog6
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/divide-3.c14
-rw-r--r--gcc/testsuite/gcc.dg/tree-ssa/divide-4.c14
5 files changed, 73 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog
index 446ae10f91a..615160c8fe5 100644
--- a/gcc/ChangeLog
+++ b/gcc/ChangeLog
@@ -1,3 +1,10 @@
+2005-11-27 Andrew Pinski <pinskia@physics.uc.edu>
+
+ PR middle-end/24575
+ * fold-const.c (negate_expr_p): Add case for signed divides if overflow
+ is undefined.
+ (negate_expr): Likewise.
+
2005-11-27 Andreas Schwab <schwab@suse.de>
* config/m68k/m68k.c: Reindent and fix whitespace, remove
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 63f12949ab7..45863ee77e3 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -991,6 +991,16 @@ negate_expr_p (tree t)
|| negate_expr_p (TREE_OPERAND (t, 0));
break;
+ case TRUNC_DIV_EXPR:
+ case ROUND_DIV_EXPR:
+ case FLOOR_DIV_EXPR:
+ case CEIL_DIV_EXPR:
+ case EXACT_DIV_EXPR:
+ if (TYPE_UNSIGNED (TREE_TYPE (t)) || flag_wrapv)
+ break;
+ return negate_expr_p (TREE_OPERAND (t, 1))
+ || negate_expr_p (TREE_OPERAND (t, 0));
+
case NOP_EXPR:
/* Negate -((double)float) as (double)(-float). */
if (TREE_CODE (type) == REAL_TYPE)
@@ -1132,6 +1142,28 @@ negate_expr (tree t)
}
break;
+ case TRUNC_DIV_EXPR:
+ case ROUND_DIV_EXPR:
+ case FLOOR_DIV_EXPR:
+ case CEIL_DIV_EXPR:
+ case EXACT_DIV_EXPR:
+ if (!TYPE_UNSIGNED (TREE_TYPE (t)) && !flag_wrapv)
+ {
+ tem = TREE_OPERAND (t, 1);
+ if (negate_expr_p (tem))
+ return fold_convert (type,
+ fold_build2 (TREE_CODE (t), TREE_TYPE (t),
+ TREE_OPERAND (t, 0),
+ negate_expr (tem)));
+ tem = TREE_OPERAND (t, 0);
+ if (negate_expr_p (tem))
+ return fold_convert (type,
+ fold_build2 (TREE_CODE (t), TREE_TYPE (t),
+ negate_expr (tem),
+ TREE_OPERAND (t, 1)));
+ }
+ break;
+
case NOP_EXPR:
/* Convert -((double)float) into (double)(-float). */
if (TREE_CODE (type) == REAL_TYPE)
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index cb692358746..8c38c880317 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,3 +1,9 @@
+2005-11-27 Andrew Pinski <pinskia@physics.uc.edu>
+
+ PR middle-end/24575
+ * gcc.dg/tree-ssa/divide-3.c: New test.
+ * gcc.dg/tree-ssa/divide-4.c: New test.
+
2005-11-27 Steven G. Kargl <kargls@comcast.net>
PR fortran/24917
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/divide-3.c b/gcc/testsuite/gcc.dg/tree-ssa/divide-3.c
new file mode 100644
index 00000000000..fa3e35a6a0b
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/divide-3.c
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-O1 -fdump-tree-optimized" } */
+
+int f(int a)
+{
+ return -(a/10);
+}
+
+/* { dg-final { scan-tree-dump-times "a / 10" 0 "optimized"} } */
+/* { dg-final { scan-tree-dump-times "a / -10" 1 "optimized"} } */
+
+/* { dg-final { cleanup-tree-dump "optimized" } } */
+
+
diff --git a/gcc/testsuite/gcc.dg/tree-ssa/divide-4.c b/gcc/testsuite/gcc.dg/tree-ssa/divide-4.c
new file mode 100644
index 00000000000..38c68cf6e8d
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/tree-ssa/divide-4.c
@@ -0,0 +1,14 @@
+/* { dg-do compile } */
+/* { dg-options "-O1 -fdump-tree-optimized" } */
+
+int f(int a)
+{
+ return -(-a/10);
+}
+
+/* { dg-final { scan-tree-dump-times "-a / 10" 0 "optimized"} } */
+/* { dg-final { scan-tree-dump-times "a / 10" 1 "optimized"} } */
+
+/* { dg-final { cleanup-tree-dump "optimized" } } */
+
+