Commit 1ade5842 by James A. Morrison

fold-const.c (tree_expr_nonnegative_p): Only return true for ABS_EXPR when…

fold-const.c (tree_expr_nonnegative_p): Only return true for ABS_EXPR when flag_wrapv is false because of INT_MIN.

2005-07-19  James A. Morrison  <phython@gcc.gnu.org>

        * fold-const.c (tree_expr_nonnegative_p): Only return true for
        ABS_EXPR when flag_wrapv is false because of INT_MIN.
        (tree_expr_nonzero_p): Always call tree_expr_nonzero_p on the argument
        of an ABS_EXPR.
        (fold_unary): Always fold ABS_EXPR<ABS_EXPR<x>> into
        ABS_EXPR<x>.

From-SVN: r102184
parent 4038c495
2005-07-19 James A. Morrison <phython@gcc.gnu.org>
* fold-const.c (tree_expr_nonnegative_p): Only return true for
ABS_EXPR when flag_wrapv is false because of INT_MIN.
(tree_expr_nonzero_p): Always call tree_expr_nonzero_p on the argument
of an ABS_EXPR.
(fold_unary): Always fold ABS_EXPR<ABS_EXPR<x>> into
ABS_EXPR<x>.
2005-07-20 Giovanni Bajo <giovannibajo@libero.it> 2005-07-20 Giovanni Bajo <giovannibajo@libero.it>
Make CONSTRUCTOR use VEC to store initializers. Make CONSTRUCTOR use VEC to store initializers.
......
...@@ -6827,7 +6827,8 @@ fold_unary (enum tree_code code, tree type, tree op0) ...@@ -6827,7 +6827,8 @@ fold_unary (enum tree_code code, tree type, tree op0)
TREE_TYPE (targ0), TREE_TYPE (targ0),
targ0)); targ0));
} }
else if (tree_expr_nonnegative_p (arg0)) /* ABS_EXPR<ABS_EXPR<x>> = ABS_EXPR<x> even if flag_wrapv is on. */
else if (tree_expr_nonnegative_p (arg0) || TREE_CODE (arg0) == ABS_EXPR)
return arg0; return arg0;
/* Strip sign ops from argument. */ /* Strip sign ops from argument. */
...@@ -10527,7 +10528,11 @@ tree_expr_nonnegative_p (tree t) ...@@ -10527,7 +10528,11 @@ tree_expr_nonnegative_p (tree t)
switch (TREE_CODE (t)) switch (TREE_CODE (t))
{ {
case ABS_EXPR: case ABS_EXPR:
return 1; /* We can't return 1 if flag_wrapv is set because
ABS_EXPR<INT_MIN> = INT_MIN. */
if (!flag_wrapv)
return 1;
break;
case INTEGER_CST: case INTEGER_CST:
return tree_int_cst_sgn (t) >= 0; return tree_int_cst_sgn (t) >= 0;
...@@ -10804,8 +10809,7 @@ tree_expr_nonzero_p (tree t) ...@@ -10804,8 +10809,7 @@ tree_expr_nonzero_p (tree t)
switch (TREE_CODE (t)) switch (TREE_CODE (t))
{ {
case ABS_EXPR: case ABS_EXPR:
if (!TYPE_UNSIGNED (type) && !flag_wrapv) return tree_expr_nonzero_p (TREE_OPERAND (t, 0));
return tree_expr_nonzero_p (TREE_OPERAND (t, 0));
case INTEGER_CST: case INTEGER_CST:
/* We used to test for !integer_zerop here. This does not work correctly /* We used to test for !integer_zerop here. This does not work correctly
......
2005-07-19 James A. Morrison <phython@gcc.gnu.org>
* gcc.dg/fold-abs-1.c: New test.
* gcc.dg/fold-abs-2.c: New test.
* gcc.dg/fold-abs-3.c: New test.
2005-07-20 Giovanni Bajo <giovannibajo@libero.it> 2005-07-20 Giovanni Bajo <giovannibajo@libero.it>
Make CONSTRUCTOR use VEC to store initializers. Make CONSTRUCTOR use VEC to store initializers.
......
/* { dg-do compile } */
/* { dg-options "-O1 -fwrapv" } */
#define ABS(x) (x > 0 ? x : -x)
int f (int a, int b) {
if ((ABS(a) | b) != 0) return 1;
else return 0;
}
/* { dg-do run } */
/* { dg-options "-O1 -fwrapv" } */
#include <limits.h>
void exit (int);
void abort ();
#define ABS(x) (x > 0 ? x : -x)
int f (int a) {
if (ABS(a) >= 0) return 1;
else return 0;
}
int main (int argc, char *argv[]) {
if (f(INT_MIN))
abort ();
else
exit (0);
}
/* { dg-do compile } */
/* { dg-options "-fdump-tree-gimple -fwrapv" } */
#define ABS(x) (x > 0 ? x : -x)
int f (int a) {
return ABS (ABS(a));
}
/* { dg-final { scan-tree-dump-times "ABS" 1 "gimple" } } */
/* { dg-final { cleanup-tree-dump "gimple" } } */
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment