re PR tree-optimization/24575 (-(i /10) is not foldded to i/-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  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.

From-SVN: r107575
This commit is contained in:
Andrew Pinski 2005-11-27 21:31:36 +00:00 committed by Andrew Pinski
parent a0a7fbc94e
commit 965d7fa40e
5 changed files with 73 additions and 0 deletions

View File

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

View File

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

View File

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

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