diff options
author | Kazu Hirata <kazu@cs.umass.edu> | 2004-03-19 23:07:29 +0000 |
---|---|---|
committer | Kazu Hirata <kazu@gcc.gnu.org> | 2004-03-19 23:07:29 +0000 |
commit | 73c4ab99de2a48eb748c61ddcce1adef752eb702 (patch) | |
tree | d39de4b55c63eee949729daea70534a78f7f4f3a /gcc | |
parent | edb3d426310169159f4747e405f0c0d3a540515e (diff) | |
download | gcc-73c4ab99de2a48eb748c61ddcce1adef752eb702.zip gcc-73c4ab99de2a48eb748c61ddcce1adef752eb702.tar.gz gcc-73c4ab99de2a48eb748c61ddcce1adef752eb702.tar.bz2 |
fold-const.c (fold): Move the handling of constants ...
* fold-const.c (fold) <ABS_EXPR>: Move the handling of constants
...
(fold_abs_const): ... here.
From-SVN: r79709
Diffstat (limited to 'gcc')
-rw-r--r-- | gcc/ChangeLog | 6 | ||||
-rw-r--r-- | gcc/fold-const.c | 93 |
2 files changed, 63 insertions, 36 deletions
diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 066a6bf..c2f52d8 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,9 @@ +2004-03-19 Kazu Hirata <kazu@cs.umass.edu> + + * fold-const.c (fold) <ABS_EXPR>: Move the handling of constants + ... + (fold_abs_const): ... here. + 2004-03-19 Richard Kenner <kenner@vlsi1.ultra.nyu.edu> * tree.h (TYPE_ARRAY_MAX_SIZE): Use type.maxval directly. diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 26cba67..c744491 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -114,6 +114,7 @@ static bool reorder_operands_p (tree, tree); static bool tree_swap_operands_p (tree, tree, bool); static tree fold_negate_const (tree, tree); +static tree fold_abs_const (tree, tree); /* The following constants represent a bit based encoding of GCC's comparison operators. This encoding simplifies transformations @@ -5820,42 +5821,9 @@ fold (tree expr) return t; case ABS_EXPR: - if (wins) - { - if (TREE_CODE (arg0) == INTEGER_CST) - { - /* If the value is unsigned, then the absolute value is - the same as the ordinary value. */ - if (TREE_UNSIGNED (type)) - return arg0; - /* Similarly, if the value is non-negative. */ - else if (INT_CST_LT (integer_minus_one_node, arg0)) - return arg0; - /* If the value is negative, then the absolute value is - its negation. */ - else - { - unsigned HOST_WIDE_INT low; - HOST_WIDE_INT high; - int overflow = neg_double (TREE_INT_CST_LOW (arg0), - TREE_INT_CST_HIGH (arg0), - &low, &high); - t = build_int_2 (low, high); - TREE_TYPE (t) = type; - TREE_OVERFLOW (t) - = (TREE_OVERFLOW (arg0) - | force_fit_type (t, overflow)); - TREE_CONSTANT_OVERFLOW (t) - = TREE_OVERFLOW (t) | TREE_CONSTANT_OVERFLOW (arg0); - } - } - else if (TREE_CODE (arg0) == REAL_CST) - { - if (REAL_VALUE_NEGATIVE (TREE_REAL_CST (arg0))) - t = build_real (type, - REAL_VALUE_NEGATE (TREE_REAL_CST (arg0))); - } - } + if (wins + && (TREE_CODE (arg0) == INTEGER_CST || TREE_CODE (arg0) == REAL_CST)) + return fold_abs_const (arg0, type); else if (TREE_CODE (arg0) == NEGATE_EXPR) return fold (build1 (ABS_EXPR, type, TREE_OPERAND (arg0, 0))); /* Convert fabs((double)float) into (double)fabsf(float). */ @@ -9073,4 +9041,57 @@ fold_negate_const (tree arg0, tree type) return t; } +/* Return the tree for abs (ARG0) when ARG0 is known to be either + an integer constant or real constant. + + TYPE is the type of the result. */ + +static tree +fold_abs_const (tree arg0, tree type) +{ + tree t = NULL_TREE; + + if (TREE_CODE (arg0) == INTEGER_CST) + { + /* If the value is unsigned, then the absolute value is + the same as the ordinary value. */ + if (TREE_UNSIGNED (type)) + return arg0; + /* Similarly, if the value is non-negative. */ + else if (INT_CST_LT (integer_minus_one_node, arg0)) + return arg0; + /* If the value is negative, then the absolute value is + its negation. */ + else + { + unsigned HOST_WIDE_INT low; + HOST_WIDE_INT high; + int overflow = neg_double (TREE_INT_CST_LOW (arg0), + TREE_INT_CST_HIGH (arg0), + &low, &high); + t = build_int_2 (low, high); + TREE_TYPE (t) = type; + TREE_OVERFLOW (t) + = (TREE_OVERFLOW (arg0) + | force_fit_type (t, overflow)); + TREE_CONSTANT_OVERFLOW (t) + = TREE_OVERFLOW (t) | TREE_CONSTANT_OVERFLOW (arg0); + return t; + } + } + else if (TREE_CODE (arg0) == REAL_CST) + { + if (REAL_VALUE_NEGATIVE (TREE_REAL_CST (arg0))) + return build_real (type, REAL_VALUE_NEGATE (TREE_REAL_CST (arg0))); + else + return arg0; + } +#ifdef ENABLE_CHECKING + else + abort (); +#endif + + return t; +} + #include "gt-fold-const.h" |