summaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
authorpinskia <pinskia@138bc75d-0d04-0410-961f-82ee72b054a4>2005-11-26 22:18:04 +0000
committerpinskia <pinskia@138bc75d-0d04-0410-961f-82ee72b054a4>2005-11-26 22:18:04 +0000
commit4df6b6e5554bcacf9c3eb681aabb51820c33a9f9 (patch)
tree74cae8a39ab44003fc82853af062e2e770ed36f8 /gcc/fold-const.c
parentd5d8a63bb0c855f95557fb289bac391c68891292 (diff)
downloadgcc-4df6b6e5554bcacf9c3eb681aabb51820c33a9f9.tar.gz
2005-11-26 Andrew Pinski <pinskia@physics.uc.edu>
PR middle-end/23669 * fold-const.c (fold_binary): Convert -A/-B to A/B for signed types when overflow is undefined. 2005-11-26 Andrew Pinski <pinskia@physics.uc.edu> PR middle-end/23669 * gcc.dg/tree-ssa/divide-1.c: New test. * gcc.dg/tree-ssa/divide-2.c: New test. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@107543 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 59037d59758..63f12949ab7 100644
--- a/gcc/fold-const.c
+++ b/gcc/fold-const.c
@@ -8440,6 +8440,19 @@ fold_binary (enum tree_code code, tree type, tree op0, tree op1)
&& TREE_INT_CST_HIGH (arg1) == -1)
return fold_convert (type, negate_expr (arg0));
+ /* Convert -A / -B to A / B when the type is signed and overflow is
+ undefined. */
+ if (!TYPE_UNSIGNED (type) && !flag_wrapv
+ && TREE_CODE (arg0) == NEGATE_EXPR
+ && negate_expr_p (arg1))
+ return fold_build2 (code, type, TREE_OPERAND (arg0, 0),
+ negate_expr (arg1));
+ if (!TYPE_UNSIGNED (type) && !flag_wrapv
+ && TREE_CODE (arg1) == NEGATE_EXPR
+ && negate_expr_p (arg0))
+ return fold_build2 (code, type, negate_expr (arg0),
+ TREE_OPERAND (arg1, 0));
+
/* If arg0 is a multiple of arg1, then rewrite to the fastest div
operation, EXACT_DIV_EXPR.