Commit a653e758 by Roger Sayle Committed by Roger Sayle

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
parent e66e7856
2004-06-09 Roger Sayle <roger@eyesopen.com>
* 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.
2004-06-09 Richard Henderson <rth@redhat.com> 2004-06-09 Richard Henderson <rth@redhat.com>
PR middle-end/15228 PR middle-end/15228
......
...@@ -136,8 +136,10 @@ static bool tree_swap_operands_p (tree, tree, bool); ...@@ -136,8 +136,10 @@ static bool tree_swap_operands_p (tree, tree, bool);
static tree fold_negate_const (tree, tree); static tree fold_negate_const (tree, tree);
static tree fold_abs_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_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 /* 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, overflow. Suppose A, B and SUM have the same respective signs as A1, B1,
...@@ -6018,8 +6020,7 @@ fold (tree expr) ...@@ -6018,8 +6020,7 @@ fold (tree expr)
return t; return t;
case ABS_EXPR: case ABS_EXPR:
if (wins if (TREE_CODE (arg0) == INTEGER_CST || TREE_CODE (arg0) == REAL_CST)
&& (TREE_CODE (arg0) == INTEGER_CST || TREE_CODE (arg0) == REAL_CST))
return fold_abs_const (arg0, type); return fold_abs_const (arg0, type);
else if (TREE_CODE (arg0) == NEGATE_EXPR) else if (TREE_CODE (arg0) == NEGATE_EXPR)
return fold (build1 (ABS_EXPR, type, TREE_OPERAND (arg0, 0))); return fold (build1 (ABS_EXPR, type, TREE_OPERAND (arg0, 0)));
...@@ -6058,16 +6059,8 @@ fold (tree expr) ...@@ -6058,16 +6059,8 @@ fold (tree expr)
return t; return t;
case BIT_NOT_EXPR: case BIT_NOT_EXPR:
if (wins) if (TREE_CODE (arg0) == INTEGER_CST)
{ return fold_not_const (arg0, type);
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;
}
else if (TREE_CODE (arg0) == BIT_NOT_EXPR) else if (TREE_CODE (arg0) == BIT_NOT_EXPR)
return TREE_OPERAND (arg0, 0); return TREE_OPERAND (arg0, 0);
return t; return t;
...@@ -9697,8 +9690,6 @@ tree ...@@ -9697,8 +9690,6 @@ tree
nondestructive_fold_unary_to_constant (enum tree_code code, tree type, nondestructive_fold_unary_to_constant (enum tree_code code, tree type,
tree op0) tree op0)
{ {
tree t;
/* Make sure we have a suitable constant argument. */ /* Make sure we have a suitable constant argument. */
if (code == NOP_EXPR || code == FLOAT_EXPR || code == CONVERT_EXPR) 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, ...@@ -9736,15 +9727,8 @@ nondestructive_fold_unary_to_constant (enum tree_code code, tree type,
return NULL_TREE; return NULL_TREE;
case BIT_NOT_EXPR: case BIT_NOT_EXPR:
if (TREE_CODE (op0) == INTEGER_CST || TREE_CODE (op0) == REAL_CST) if (TREE_CODE (op0) == INTEGER_CST)
{ return fold_not_const (op0, type);
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;
}
else else
return NULL_TREE; return NULL_TREE;
...@@ -9910,6 +9894,31 @@ fold_abs_const (tree arg0, tree type) ...@@ -9910,6 +9894,31 @@ fold_abs_const (tree arg0, tree type)
return t; 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 /* Given CODE, a relational operator, the target type, TYPE and two
constant operands OP0 and OP1, return the result of the constant operands OP0 and OP1, return the result of the
relational operation. If the result is not a compile time relational operation. If the result is not a compile time
......
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