[Committed] Use constant_boolean_node in fold_relational_const
Roger Sayle
roger@eyesopen.com
Thu Jun 17 21:59:00 GMT 2004
The following patch tweaks fold_relational_const to use the middle-end's
constant_boolean_node function to create trees representing true and
false. This has the advantage that constant_boolean_node returns a
shared integer_one_node or integer_zero_node rather than allocating a
new tree node for the purpose using build_int_2. It also simplifies
much of the affected code below.
The following patch has been tested on i686-pc-linux-gnu with a full
"make bootstrap", all default languages, and regression tested with a
top-level "make -k check" with no new failures.
Committed to mainline CVS.
2004-06-17 Roger Sayle <roger@eyesopen.com>
* fold-const.c (fold_relational_const): Use constant_boolean_node.
Index: fold-const.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.398
diff -c -3 -p -r1.398 fold-const.c
*** fold-const.c 16 Jun 2004 05:09:39 -0000 1.398
--- fold-const.c 17 Jun 2004 16:09:55 -0000
*************** fold_not_const (tree arg0, tree type)
*** 9966,9973 ****
static tree
fold_relational_const (enum tree_code code, tree type, tree op0, tree op1)
{
! tree tem;
! int invert;
/* From here on, the only cases we handle are when the result is
known to be a constant.
--- 9966,9972 ----
static tree
fold_relational_const (enum tree_code code, tree type, tree op0, tree op1)
{
! int result, invert;
/* From here on, the only cases we handle are when the result is
known to be a constant.
*************** fold_relational_const (enum tree_code co
*** 9981,9994 ****
if (code == LE_EXPR || code == GT_EXPR)
{
! tem = op0, op0 = op1, op1 = tem;
code = swap_tree_comparison (code);
}
/* Note that it is safe to invert for real values here because we
will check below in the one case that it matters. */
- tem = NULL_TREE;
invert = 0;
if (code == NE_EXPR || code == GE_EXPR)
{
--- 9980,9994 ----
if (code == LE_EXPR || code == GT_EXPR)
{
! tree tem = op0;
! op0 = op1;
! op1 = tem;
code = swap_tree_comparison (code);
}
/* Note that it is safe to invert for real values here because we
will check below in the one case that it matters. */
invert = 0;
if (code == NE_EXPR || code == GE_EXPR)
{
*************** fold_relational_const (enum tree_code co
*** 10001,10017 ****
if (TREE_CODE (op0) == INTEGER_CST && TREE_CODE (op1) == INTEGER_CST)
{
if (code == EQ_EXPR)
! tem = build_int_2 (tree_int_cst_equal (op0, op1), 0);
else
! tem = build_int_2 ((TYPE_UNSIGNED (TREE_TYPE (op0))
! ? INT_CST_LT_UNSIGNED (op0, op1)
! : INT_CST_LT (op0, op1)),
! 0);
}
else if (code == EQ_EXPR && !TREE_SIDE_EFFECTS (op0)
&& integer_zerop (op1) && tree_expr_nonzero_p (op0))
! tem = build_int_2 (0, 0);
/* Two real constants can be compared explicitly. */
else if (TREE_CODE (op0) == REAL_CST && TREE_CODE (op1) == REAL_CST)
--- 10001,10016 ----
if (TREE_CODE (op0) == INTEGER_CST && TREE_CODE (op1) == INTEGER_CST)
{
if (code == EQ_EXPR)
! result = tree_int_cst_equal (op0, op1);
! else if (TYPE_UNSIGNED (TREE_TYPE (op0)))
! result = INT_CST_LT_UNSIGNED (op0, op1);
else
! result = INT_CST_LT (op0, op1);
}
else if (code == EQ_EXPR && !TREE_SIDE_EFFECTS (op0)
&& integer_zerop (op1) && tree_expr_nonzero_p (op0))
! result = 0;
/* Two real constants can be compared explicitly. */
else if (TREE_CODE (op0) == REAL_CST && TREE_CODE (op1) == REAL_CST)
*************** fold_relational_const (enum tree_code co
*** 10025,10052 ****
if (REAL_VALUE_ISNAN (TREE_REAL_CST (op0))
|| REAL_VALUE_ISNAN (TREE_REAL_CST (op1)))
! tem = build_int_2 (invert && code == LT_EXPR, 0);
else if (code == EQ_EXPR)
! tem = build_int_2 (REAL_VALUES_EQUAL (TREE_REAL_CST (op0),
! TREE_REAL_CST (op1)),
! 0);
else
! tem = build_int_2 (REAL_VALUES_LESS (TREE_REAL_CST (op0),
! TREE_REAL_CST (op1)),
! 0);
}
!
! if (tem == NULL_TREE)
return NULL_TREE;
if (invert)
! TREE_INT_CST_LOW (tem) ^= 1;
!
! TREE_TYPE (tem) = type;
! if (TREE_CODE (type) == BOOLEAN_TYPE)
! return lang_hooks.truthvalue_conversion (tem);
! return tem;
}
/* Build an expression for the address of T. Folds away INDIRECT_REF to
--- 10024,10044 ----
if (REAL_VALUE_ISNAN (TREE_REAL_CST (op0))
|| REAL_VALUE_ISNAN (TREE_REAL_CST (op1)))
! result = invert && code == LT_EXPR;
else if (code == EQ_EXPR)
! result = REAL_VALUES_EQUAL (TREE_REAL_CST (op0),
! TREE_REAL_CST (op1));
else
! result = REAL_VALUES_LESS (TREE_REAL_CST (op0),
! TREE_REAL_CST (op1));
}
! else
return NULL_TREE;
if (invert)
! result ^= 1;
! return constant_boolean_node (result, type);
}
/* Build an expression for the address of T. Folds away INDIRECT_REF to
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
More information about the Gcc-patches
mailing list