re PR middle-end/23669 (fold does convert (-a)/10 into a/-10 with -fno-wrapv)

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.

From-SVN: r107543
This commit is contained in:
Andrew Pinski 2005-11-26 22:18:04 +00:00 committed by Andrew Pinski
parent cd16503aa2
commit 37d3243dad
5 changed files with 53 additions and 0 deletions

View File

@ -1,3 +1,9 @@
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 Hans-Peter Nilsson <hp@axis.com>
* doc/md.texi (Insn Canonicalizations): Refer to the

View File

@ -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.

View File

@ -1,3 +1,9 @@
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.
2005-11-26 Janne Blomqvist <jb@gcc.gnu.org>
PR libgfortran/24945

View File

@ -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" } } */

View File

@ -0,0 +1,14 @@
/* { dg-do compile } */
/* { dg-options "-O1 -fdump-tree-optimized" } */
int f(int a)
{
return 10/-a;
}
/* { dg-final { scan-tree-dump-times "10 / -a" 0 "optimized"} } */
/* { dg-final { scan-tree-dump-times "-10 / a" 1 "optimized"} } */
/* { dg-final { cleanup-tree-dump "optimized" } } */