diff options
author | James A. Morrison <phython@gcc.gnu.org> | 2005-02-13 06:21:35 +0000 |
---|---|---|
committer | James A. Morrison <phython@gcc.gnu.org> | 2005-02-13 06:21:35 +0000 |
commit | e24b954eff5d22b80457f2e94c33214bd193f8a6 (patch) | |
tree | 2622ef70f3a694db5d17729fe9d5cd5337959e9e | |
parent | 2c1bbe52e631153e03745218309b2fa29a806404 (diff) |
2005-02-13 James A. Morrison <phython@gcc.gnu.org>
PR tree-optimization/14303
PR tree-optimization/15784
* fold-const.c (fold): Fold ABS_EXPR<x> >= 0 to true, when possible.
Fold ABS_EXPR<x> < 0 to false. Fold ABS_EXPR<x> == 0 to x == 0 and
ABS_EXPR<x> != 0 to x != 0.
git-svn-id: https://gcc.gnu.org/svn/gcc/trunk@94977 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r-- | gcc/ChangeLog | 8 | ||||
-rw-r--r-- | gcc/fold-const.c | 23 |
2 files changed, 31 insertions, 0 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 1d74ab64157..35f46de3d7c 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,11 @@ +2005-02-13 James A. Morrison <phython@gcc.gnu.org> + + PR tree-optimization/14303 + PR tree-optimization/15784 + * fold-const.c (fold): Fold ABS_EXPR<x> >= 0 to true, when possible. + Fold ABS_EXPR<x> < 0 to false. Fold ABS_EXPR<x> == 0 to x == 0 and + ABS_EXPR<x> != 0 to x != 0. + 2005-02-12 Kazu Hirata <kazu@cs.umass.edu> * c-tree.h, combine.c, expmed.c, flow.c, libgcc2.c, diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 5d6e5c50854..601f023ce9a 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -8973,6 +8973,29 @@ fold (tree expr) build2 (LE_EXPR, type, TREE_OPERAND (arg0, 0), arg1))); + /* Convert ABS_EXPR<x> >= 0 to true. */ + else if (code == GE_EXPR + && tree_expr_nonnegative_p (arg0) + && ! TREE_SIDE_EFFECTS (arg0) + && (integer_zerop (arg1) + || (! HONOR_NANS (TYPE_MODE (TREE_TYPE (arg0))) + && real_zerop (arg1)))) + return constant_boolean_node (true, type); + + /* Convert ABS_EXPR<x> < 0 to false. */ + else if (code == LT_EXPR + && tree_expr_nonnegative_p (arg0) + && ! TREE_SIDE_EFFECTS (arg0) + && (integer_zerop (arg1) || real_zerop (arg1))) + return constant_boolean_node (false, type); + + /* Convert ABS_EXPR<x> == 0 or ABS_EXPR<x> != 0 to x == 0 or x != 0. */ + else if ((code == EQ_EXPR || code == NE_EXPR) + && TREE_CODE (arg0) == ABS_EXPR + && ! TREE_SIDE_EFFECTS (arg0) + && (integer_zerop (arg1) || real_zerop (arg1))) + return fold (build2 (code, type, TREE_OPERAND (arg0, 0), arg1)); + /* If this is an EQ or NE comparison with zero and ARG0 is (1 << foo) & bar, convert it to (bar >> foo) & 1. Both require two operations, but the latter can be done in one less insn |