diff options
author | Roger Sayle <roger@eyesopen.com> | 2004-06-10 00:02:48 +0000 |
---|---|---|
committer | Roger Sayle <sayle@gcc.gnu.org> | 2004-06-10 00:02:48 +0000 |
commit | a653e758f68488c0056b0a0a3d9fcbe5d5eaf50f (patch) | |
tree | 5fc66f9f60abbd000cc68d47fb8bb109947f94bc /gcc/fold-const.c | |
parent | e66e7856e8c88873ba3a5b37f8afcd003e0f8df9 (diff) | |
download | gcc-a653e758f68488c0056b0a0a3d9fcbe5d5eaf50f.zip gcc-a653e758f68488c0056b0a0a3d9fcbe5d5eaf50f.tar.gz gcc-a653e758f68488c0056b0a0a3d9fcbe5d5eaf50f.tar.bz2 |
fold-const.c (fold_not_const): New function.
* fold-const.c (fold_not_const): New function.
(fold) <ABS_EXPR>: Don't bother testing wins.
(fold) <BIT_NOT_EXPR>: Call fold_not_const.
(nondestructive_fold_unary_to_constant) <BIT_NOT_EXPR>: Likewise.
From-SVN: r82868
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r-- | gcc/fold-const.c | 57 |
1 files changed, 33 insertions, 24 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c index ecd59f8..be97417 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -136,8 +136,10 @@ static bool tree_swap_operands_p (tree, tree, bool); static tree fold_negate_const (tree, tree); static tree fold_abs_const (tree, tree); +static tree fold_not_const (tree, tree); static tree fold_relational_const (enum tree_code, tree, tree, tree); -static tree fold_relational_hi_lo (enum tree_code *, const tree, tree *, tree *); +static tree fold_relational_hi_lo (enum tree_code *, const tree, + tree *, tree *); /* We know that A1 + B1 = SUM1, using 2's complement arithmetic and ignoring overflow. Suppose A, B and SUM have the same respective signs as A1, B1, @@ -6018,8 +6020,7 @@ fold (tree expr) return t; case ABS_EXPR: - if (wins - && (TREE_CODE (arg0) == INTEGER_CST || TREE_CODE (arg0) == REAL_CST)) + if (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))); @@ -6058,16 +6059,8 @@ fold (tree expr) return t; case BIT_NOT_EXPR: - if (wins) - { - tem = build_int_2 (~ TREE_INT_CST_LOW (arg0), - ~ TREE_INT_CST_HIGH (arg0)); - TREE_TYPE (tem) = type; - force_fit_type (tem, 0); - TREE_OVERFLOW (tem) = TREE_OVERFLOW (arg0); - TREE_CONSTANT_OVERFLOW (tem) = TREE_CONSTANT_OVERFLOW (arg0); - return tem; - } + if (TREE_CODE (arg0) == INTEGER_CST) + return fold_not_const (arg0, type); else if (TREE_CODE (arg0) == BIT_NOT_EXPR) return TREE_OPERAND (arg0, 0); return t; @@ -9697,8 +9690,6 @@ tree nondestructive_fold_unary_to_constant (enum tree_code code, tree type, tree op0) { - tree t; - /* Make sure we have a suitable constant argument. */ if (code == NOP_EXPR || code == FLOAT_EXPR || code == CONVERT_EXPR) { @@ -9736,15 +9727,8 @@ nondestructive_fold_unary_to_constant (enum tree_code code, tree type, return NULL_TREE; case BIT_NOT_EXPR: - if (TREE_CODE (op0) == INTEGER_CST || TREE_CODE (op0) == REAL_CST) - { - t = build_int_2 (~ TREE_INT_CST_LOW (op0), ~ TREE_INT_CST_HIGH (op0)); - TREE_TYPE (t) = type; - force_fit_type (t, 0); - TREE_OVERFLOW (t) = TREE_OVERFLOW (op0); - TREE_CONSTANT_OVERFLOW (t) = TREE_CONSTANT_OVERFLOW (op0); - return t; - } + if (TREE_CODE (op0) == INTEGER_CST) + return fold_not_const (op0, type); else return NULL_TREE; @@ -9910,6 +9894,31 @@ fold_abs_const (tree arg0, tree type) return t; } +/* Return the tree for not (ARG0) when ARG0 is known to be an integer + constant. TYPE is the type of the result. */ + +static tree +fold_not_const (tree arg0, tree type) +{ + tree t = NULL_TREE; + + if (TREE_CODE (arg0) == INTEGER_CST) + { + t = build_int_2 (~ TREE_INT_CST_LOW (arg0), + ~ TREE_INT_CST_HIGH (arg0)); + TREE_TYPE (t) = type; + force_fit_type (t, 0); + TREE_OVERFLOW (t) = TREE_OVERFLOW (arg0); + TREE_CONSTANT_OVERFLOW (t) = TREE_CONSTANT_OVERFLOW (arg0); + } +#ifdef ENABLE_CHECKING + else + abort (); +#endif + + return t; +} + /* Given CODE, a relational operator, the target type, TYPE and two constant operands OP0 and OP1, return the result of the relational operation. If the result is not a compile time |