This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[Committed] Use constant_boolean_node in fold-const.c
- From: Roger Sayle <roger at eyesopen dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sun, 30 May 2004 16:39:29 -0600 (MDT)
- Subject: [Committed] Use constant_boolean_node in fold-const.c
The following patch is a collection of minor clean-ups to fold-const.c.
Now that tree-ssa has provided a constant_boolean_node, many of the uses
of fold_convert in fold-const.c can be converted to use this new function
where appropriate. Additionally, there were a number of places where we
were calling fold_convert to prepare the second argument to the function
omit_one_operand. Fortunately, omit_one_operand already internally calls
fold_convert on its second argument, to convert it to the required return
type, so these calls aren't necessary.
There should be no functional changes with this patch, but these clean-ups
reduce the number of lines of fold-const.c (to just below 10,000 :).
The following patch has been tested on i686-pc-linux-gnu with a complete
"make bootstrap", all default languages, and regression tested with a
top-level "make -k check" with no new failures.
Committed to mainline CVS.
2004-05-30 Roger Sayle <roger@eyesopen.com>
* fold-const.c (combine_comparisons, optimize_bit_field_compare,
range_binop, fold_truthop, fold_binary_op_with_conditional_arg,
fold_mathfn_compare, fold_inf_compare, fold,
fold_relational_hi_lo, nondestructive_fold_binary_to_constant):
Use constant_boolean_node where appropriate. Don't bother using
fold_convert on the second argument to omit_one_operand.
Index: fold-const.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.383
diff -c -3 -p -r1.383 fold-const.c
*** fold-const.c 28 May 2004 16:37:00 -0000 1.383
--- fold-const.c 30 May 2004 20:02:20 -0000
*************** combine_comparisons (enum tree_code code
*** 2298,2306 ****
}
if (compcode == COMPCODE_TRUE)
! return fold_convert (truth_type, integer_one_node);
else if (compcode == COMPCODE_FALSE)
! return fold_convert (truth_type, integer_zero_node);
else
return fold (build2 (compcode_to_comparison (compcode),
truth_type, ll_arg, lr_arg));
--- 2298,2306 ----
}
if (compcode == COMPCODE_TRUE)
! return constant_boolean_node (true, truth_type);
else if (compcode == COMPCODE_FALSE)
! return constant_boolean_node (false, truth_type);
else
return fold (build2 (compcode_to_comparison (compcode),
truth_type, ll_arg, lr_arg));
*************** optimize_bit_field_compare (enum tree_co
*** 3141,3149 ****
{
warning ("comparison is always %d due to width of bit-field",
code == NE_EXPR);
! return fold_convert (compare_type,
! (code == NE_EXPR
! ? integer_one_node : integer_zero_node));
}
}
else
--- 3141,3147 ----
{
warning ("comparison is always %d due to width of bit-field",
code == NE_EXPR);
! return constant_boolean_node (code == NE_EXPR, compare_type);
}
}
else
*************** optimize_bit_field_compare (enum tree_co
*** 3154,3162 ****
{
warning ("comparison is always %d due to width of bit-field",
code == NE_EXPR);
! return fold_convert (compare_type,
! (code == NE_EXPR
! ? integer_one_node : integer_zero_node));
}
}
--- 3152,3158 ----
{
warning ("comparison is always %d due to width of bit-field",
code == NE_EXPR);
! return constant_boolean_node (code == NE_EXPR, compare_type);
}
}
*************** range_binop (enum tree_code code, tree t
*** 3479,3485 ****
abort ();
}
! return fold_convert (type, result ? integer_one_node : integer_zero_node);
}
/* Given EXP, a logical expression, set the range it is testing into
--- 3475,3481 ----
abort ();
}
! return constant_boolean_node (result, type);
}
/* Given EXP, a logical expression, set the range it is testing into
*************** fold_truthop (enum tree_code code, tree
*** 4212,4218 ****
return build2 (NE_EXPR, truth_type,
build2 (BIT_IOR_EXPR, TREE_TYPE (ll_arg),
ll_arg, rl_arg),
! integer_zero_node);
/* Convert (a == 0) && (b == 0) into (a | b) == 0. */
if (code == TRUTH_AND_EXPR
--- 4208,4214 ----
return build2 (NE_EXPR, truth_type,
build2 (BIT_IOR_EXPR, TREE_TYPE (ll_arg),
ll_arg, rl_arg),
! fold_convert (TREE_TYPE (ll_arg), integer_zero_node));
/* Convert (a == 0) && (b == 0) into (a | b) == 0. */
if (code == TRUTH_AND_EXPR
*************** fold_truthop (enum tree_code code, tree
*** 4222,4228 ****
return build2 (EQ_EXPR, truth_type,
build2 (BIT_IOR_EXPR, TREE_TYPE (ll_arg),
ll_arg, rl_arg),
! integer_zero_node);
return build2 (code, truth_type, lhs, rhs);
}
--- 4218,4224 ----
return build2 (EQ_EXPR, truth_type,
build2 (BIT_IOR_EXPR, TREE_TYPE (ll_arg),
ll_arg, rl_arg),
! fold_convert (TREE_TYPE (ll_arg), integer_zero_node));
return build2 (code, truth_type, lhs, rhs);
}
*************** fold_truthop (enum tree_code code, tree
*** 4344,4352 ****
{
warning ("comparison is always %d", wanted_code == NE_EXPR);
! return fold_convert (truth_type,
! wanted_code == NE_EXPR
! ? integer_one_node : integer_zero_node);
}
}
if (r_const)
--- 4340,4346 ----
{
warning ("comparison is always %d", wanted_code == NE_EXPR);
! return constant_boolean_node (wanted_code == NE_EXPR, truth_type);
}
}
if (r_const)
*************** fold_truthop (enum tree_code code, tree
*** 4361,4369 ****
{
warning ("comparison is always %d", wanted_code == NE_EXPR);
! return fold_convert (truth_type,
! wanted_code == NE_EXPR
! ? integer_one_node : integer_zero_node);
}
}
--- 4355,4361 ----
{
warning ("comparison is always %d", wanted_code == NE_EXPR);
! return constant_boolean_node (wanted_code == NE_EXPR, truth_type);
}
}
*************** fold_truthop (enum tree_code code, tree
*** 4491,4502 ****
if (wanted_code == NE_EXPR)
{
warning ("`or' of unmatched not-equal tests is always 1");
! return fold_convert (truth_type, integer_one_node);
}
else
{
warning ("`and' of mutually exclusive equal-tests is always 0");
! return fold_convert (truth_type, integer_zero_node);
}
}
--- 4483,4494 ----
if (wanted_code == NE_EXPR)
{
warning ("`or' of unmatched not-equal tests is always 1");
! return constant_boolean_node (true, truth_type);
}
else
{
warning ("`and' of mutually exclusive equal-tests is always 0");
! return constant_boolean_node (false, truth_type);
}
}
*************** fold_binary_op_with_conditional_arg (enu
*** 4973,4980 ****
{
tree testtype = TREE_TYPE (cond);
test = cond;
! true_value = fold_convert (testtype, integer_one_node);
! false_value = fold_convert (testtype, integer_zero_node);
}
if (lhs == 0)
--- 4965,4972 ----
{
tree testtype = TREE_TYPE (cond);
test = cond;
! true_value = constant_boolean_node (true, testtype);
! false_value = constant_boolean_node (false, testtype);
}
if (lhs == 0)
*************** fold_mathfn_compare (enum built_in_funct
*** 5054,5069 ****
{
/* sqrt(x) < y is always false, if y is negative. */
if (code == EQ_EXPR || code == LT_EXPR || code == LE_EXPR)
! return omit_one_operand (type,
! fold_convert (type, integer_zero_node),
! arg);
/* sqrt(x) > y is always true, if y is negative and we
don't care about NaNs, i.e. negative values of x. */
if (code == NE_EXPR || !HONOR_NANS (mode))
! return omit_one_operand (type,
! fold_convert (type, integer_one_node),
! arg);
/* sqrt(x) > y is the same as x >= 0, if y is negative. */
return fold (build2 (GE_EXPR, type, arg,
--- 5046,5057 ----
{
/* sqrt(x) < y is always false, if y is negative. */
if (code == EQ_EXPR || code == LT_EXPR || code == LE_EXPR)
! return omit_one_operand (type, integer_zero_node, arg);
/* sqrt(x) > y is always true, if y is negative and we
don't care about NaNs, i.e. negative values of x. */
if (code == NE_EXPR || !HONOR_NANS (mode))
! return omit_one_operand (type, integer_one_node, arg);
/* sqrt(x) > y is the same as x >= 0, if y is negative. */
return fold (build2 (GE_EXPR, type, arg,
*************** fold_mathfn_compare (enum built_in_funct
*** 5085,5093 ****
/* sqrt(x) > y is always false, when y is very large
and we don't care about infinities. */
! return omit_one_operand (type,
! fold_convert (type, integer_zero_node),
! arg);
}
/* sqrt(x) > c is the same as x > c*c. */
--- 5073,5079 ----
/* sqrt(x) > y is always false, when y is very large
and we don't care about infinities. */
! return omit_one_operand (type, integer_zero_node, arg);
}
/* sqrt(x) > c is the same as x > c*c. */
*************** fold_mathfn_compare (enum built_in_funct
*** 5106,5114 ****
/* sqrt(x) < y is always true, when y is a very large
value and we don't care about NaNs or Infinities. */
if (! HONOR_NANS (mode) && ! HONOR_INFINITIES (mode))
! return omit_one_operand (type,
! fold_convert (type, integer_one_node),
! arg);
/* sqrt(x) < y is x != +Inf when y is very large and we
don't care about NaNs. */
--- 5092,5098 ----
/* sqrt(x) < y is always true, when y is a very large
value and we don't care about NaNs or Infinities. */
if (! HONOR_NANS (mode) && ! HONOR_INFINITIES (mode))
! return omit_one_operand (type, integer_one_node, arg);
/* sqrt(x) < y is x != +Inf when y is very large and we
don't care about NaNs. */
*************** fold_inf_compare (enum tree_code code, t
*** 5192,5207 ****
/* x > +Inf is always false, if with ignore sNANs. */
if (HONOR_SNANS (mode))
return NULL_TREE;
! return omit_one_operand (type,
! fold_convert (type, integer_zero_node),
! arg0);
case LE_EXPR:
/* x <= +Inf is always true, if we don't case about NaNs. */
if (! HONOR_NANS (mode))
! return omit_one_operand (type,
! fold_convert (type, integer_one_node),
! arg0);
/* x <= +Inf is the same as x == x, i.e. isfinite(x). */
if (lang_hooks.decls.global_bindings_p () == 0
--- 5176,5187 ----
/* x > +Inf is always false, if with ignore sNANs. */
if (HONOR_SNANS (mode))
return NULL_TREE;
! return omit_one_operand (type, integer_zero_node, arg0);
case LE_EXPR:
/* x <= +Inf is always true, if we don't case about NaNs. */
if (! HONOR_NANS (mode))
! return omit_one_operand (type, integer_one_node, arg0);
/* x <= +Inf is the same as x == x, i.e. isfinite(x). */
if (lang_hooks.decls.global_bindings_p () == 0
*************** fold (tree expr)
*** 7376,7387 ****
&& DECL_P (TREE_OPERAND (arg0, 0))
&& ! DECL_WEAK (TREE_OPERAND (arg0, 0))
&& integer_zerop (arg1))
! {
! if (code == EQ_EXPR)
! return fold_convert (type, integer_zero_node);
! else
! return fold_convert (type, integer_one_node);
! }
/* If this is an equality comparison of the address of two non-weak,
unaliased symbols neither of which are extern (since we do not
--- 7356,7362 ----
&& DECL_P (TREE_OPERAND (arg0, 0))
&& ! DECL_WEAK (TREE_OPERAND (arg0, 0))
&& integer_zerop (arg1))
! return constant_boolean_node (code != EQ_EXPR, type);
/* If this is an equality comparison of the address of two non-weak,
unaliased symbols neither of which are extern (since we do not
*************** fold (tree expr)
*** 7399,7412 ****
&& ! lookup_attribute ("alias",
DECL_ATTRIBUTES (TREE_OPERAND (arg1, 0)))
&& ! DECL_EXTERNAL (TREE_OPERAND (arg1, 0)))
! {
! if (code == EQ_EXPR)
! return fold_convert (type, (operand_equal_p (arg0, arg1, 0)
! ? integer_one_node : integer_zero_node));
! else
! return fold_convert (type, (operand_equal_p (arg0, arg1, 0)
! ? integer_zero_node : integer_one_node));
! }
if (FLOAT_TYPE_P (TREE_TYPE (arg0)))
{
--- 7374,7382 ----
&& ! lookup_attribute ("alias",
DECL_ATTRIBUTES (TREE_OPERAND (arg1, 0)))
&& ! DECL_EXTERNAL (TREE_OPERAND (arg1, 0)))
! return constant_boolean_node (operand_equal_p (arg0, arg1, 0)
! ? code == EQ_EXPR : code != EQ_EXPR,
! type);
if (FLOAT_TYPE_P (TREE_TYPE (arg0)))
{
*************** fold (tree expr)
*** 7452,7458 ****
&& ! HONOR_SNANS (TYPE_MODE (TREE_TYPE (arg1))))
{
tem = (code == NE_EXPR) ? integer_one_node : integer_zero_node;
! return omit_one_operand (type, fold_convert (type, tem), arg0);
}
/* Fold comparisons against infinity. */
--- 7422,7428 ----
&& ! HONOR_SNANS (TYPE_MODE (TREE_TYPE (arg1))))
{
tem = (code == NE_EXPR) ? integer_one_node : integer_zero_node;
! return omit_one_operand (type, tem, arg0);
}
/* Fold comparisons against infinity. */
*************** fold (tree expr)
*** 7628,7645 ****
switch (code)
{
case GT_EXPR:
! return omit_one_operand (type,
! fold_convert (type,
! integer_zero_node),
! arg0);
case GE_EXPR:
return fold (build2 (EQ_EXPR, type, arg0, arg1));
case LE_EXPR:
! return omit_one_operand (type,
! fold_convert (type,
! integer_one_node),
! arg0);
case LT_EXPR:
return fold (build2 (NE_EXPR, type, arg0, arg1));
--- 7598,7611 ----
switch (code)
{
case GT_EXPR:
! return omit_one_operand (type, integer_zero_node, arg0);
!
case GE_EXPR:
return fold (build2 (EQ_EXPR, type, arg0, arg1));
case LE_EXPR:
! return omit_one_operand (type, integer_one_node, arg0);
!
case LT_EXPR:
return fold (build2 (NE_EXPR, type, arg0, arg1));
*************** fold (tree expr)
*** 7667,7684 ****
switch (code)
{
case LT_EXPR:
! return omit_one_operand (type,
! fold_convert (type,
! integer_zero_node),
! arg0);
case LE_EXPR:
return fold (build2 (EQ_EXPR, type, arg0, arg1));
case GE_EXPR:
! return omit_one_operand (type,
! fold_convert (type,
! integer_one_node),
! arg0);
case GT_EXPR:
return fold (build2 (NE_EXPR, type, arg0, arg1));
--- 7633,7646 ----
switch (code)
{
case LT_EXPR:
! return omit_one_operand (type, integer_zero_node, arg0);
!
case LE_EXPR:
return fold (build2 (EQ_EXPR, type, arg0, arg1));
case GE_EXPR:
! return omit_one_operand (type, integer_one_node, arg0);
!
case GT_EXPR:
return fold (build2 (NE_EXPR, type, arg0, arg1));
*************** fold_relational_hi_lo (enum tree_code *c
*** 9312,9327 ****
switch (code)
{
case GT_EXPR:
! return omit_one_operand (type,
! fold_convert (type, integer_zero_node),
! op0);
case GE_EXPR:
*code_p = EQ_EXPR;
break;
case LE_EXPR:
! return omit_one_operand (type,
! fold_convert (type, integer_one_node),
! op0);
case LT_EXPR:
*code_p = NE_EXPR;
break;
--- 9274,9287 ----
switch (code)
{
case GT_EXPR:
! return omit_one_operand (type, integer_zero_node, op0);
!
case GE_EXPR:
*code_p = EQ_EXPR;
break;
case LE_EXPR:
! return omit_one_operand (type, integer_one_node, op0);
!
case LT_EXPR:
*code_p = NE_EXPR;
break;
*************** fold_relational_hi_lo (enum tree_code *c
*** 9352,9368 ****
switch (code)
{
case LT_EXPR:
! return omit_one_operand (type,
! fold_convert (type, integer_zero_node),
! op0);
case LE_EXPR:
*code_p = EQ_EXPR;
break;
case GE_EXPR:
! return omit_one_operand (type,
! fold_convert (type, integer_one_node),
! op0);
case GT_EXPR:
*code_p = NE_EXPR;
break;
--- 9312,9326 ----
switch (code)
{
case LT_EXPR:
! return omit_one_operand (type, integer_zero_node, op0);
!
case LE_EXPR:
*code_p = EQ_EXPR;
break;
case GE_EXPR:
! return omit_one_operand (type, integer_one_node, op0);
!
case GT_EXPR:
*code_p = NE_EXPR;
break;
*************** nondestructive_fold_binary_to_constant (
*** 9682,9693 ****
if (integer_zerop (op0))
return omit_one_operand (type, op0, op1);
if (TREE_CODE (op0) == INTEGER_CST && TREE_CODE (op1) == INTEGER_CST)
! {
! int x1 = ! integer_zerop (op0);
! int x2 = ! integer_zerop (op1);
!
! return ((x1 & x2) ? integer_one_node : integer_zero_node);
! }
return NULL_TREE;
case TRUTH_OR_EXPR:
--- 9640,9646 ----
if (integer_zerop (op0))
return omit_one_operand (type, op0, op1);
if (TREE_CODE (op0) == INTEGER_CST && TREE_CODE (op1) == INTEGER_CST)
! return constant_boolean_node (true, type);
return NULL_TREE;
case TRUTH_OR_EXPR:
*************** nondestructive_fold_binary_to_constant (
*** 9700,9720 ****
if (TREE_CODE (op0) == INTEGER_CST && ! integer_zerop (op0))
return omit_one_operand (type, op0, op1);
if (TREE_CODE (op0) == INTEGER_CST && TREE_CODE (op1) == INTEGER_CST)
! {
! int x1 = ! integer_zerop (op0);
! int x2 = ! integer_zerop (op1);
!
! return ((x1 | x2) ? integer_one_node : integer_zero_node);
! }
return NULL_TREE;
case TRUTH_XOR_EXPR:
if (TREE_CODE (op0) == INTEGER_CST && TREE_CODE (op1) == INTEGER_CST)
{
! int x1 = ! integer_zerop (op0);
! int x2 = ! integer_zerop (op1);
!
! return ((x1 ^ x2) ? integer_one_node : integer_zero_node);
}
return NULL_TREE;
--- 9653,9666 ----
if (TREE_CODE (op0) == INTEGER_CST && ! integer_zerop (op0))
return omit_one_operand (type, op0, op1);
if (TREE_CODE (op0) == INTEGER_CST && TREE_CODE (op1) == INTEGER_CST)
! return constant_boolean_node (false, type);
return NULL_TREE;
case TRUTH_XOR_EXPR:
if (TREE_CODE (op0) == INTEGER_CST && TREE_CODE (op1) == INTEGER_CST)
{
! int x = ! integer_zerop (op0) ^ ! integer_zerop (op1);
! return constant_boolean_node (x, type);
}
return NULL_TREE;
Roger
--
Roger Sayle, E-mail: roger@eyesopen.com
OpenEye Scientific Software, WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road, Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507. Fax: (+1) 505-473-0833