fold-const.c (constant_boolean_node): New function.

* fold-const.c (constant_boolean_node): New function.
	(fold): Use it.

From-SVN: r19775
This commit is contained in:
Mark Mitchell 1998-05-15 07:19:38 +00:00 committed by Mark Mitchell
parent 8ebe42f1e4
commit f628873f1f
2 changed files with 29 additions and 14 deletions

View File

@ -1,3 +1,8 @@
Fri May 15 07:20:03 1998 Mark Mitchell <mmitchell@usa.net>
* fold-const.c (constant_boolean_node): New function.
(fold): Use it.
Fri May 15 11:21:16 1998 J"orn Rennecke <amylaar@cygnus.co.uk> Fri May 15 11:21:16 1998 J"orn Rennecke <amylaar@cygnus.co.uk>
* sh.c (gen_shl_and): Don't sign extend constant for kind two. * sh.c (gen_shl_and): Don't sign extend constant for kind two.

View File

@ -94,6 +94,7 @@ static tree unextend PROTO((tree, int, int, tree));
static tree fold_truthop PROTO((enum tree_code, tree, tree, tree)); static tree fold_truthop PROTO((enum tree_code, tree, tree, tree));
static tree strip_compound_expr PROTO((tree, tree)); static tree strip_compound_expr PROTO((tree, tree));
static int multiple_of_p PROTO((tree, tree, tree)); static int multiple_of_p PROTO((tree, tree, tree));
static tree constant_boolean_node PROTO((int, tree));
#ifndef BRANCH_COST #ifndef BRANCH_COST
#define BRANCH_COST 1 #define BRANCH_COST 1
@ -3702,6 +3703,27 @@ strip_compound_expr (t, s)
return t; return t;
} }
/* Return a node which has the indicated constant VALUE (either 0 or
1), and is of the indicated TYPE. */
tree
constant_boolean_node (value, type)
int value;
tree type;
{
if (type == integer_type_node)
return value ? integer_one_node : integer_zero_node;
else if (TREE_CODE (type) == BOOLEAN_TYPE)
return truthvalue_conversion (value ? integer_one_node :
integer_zero_node);
else
{
tree t = build_int_2 (value, 0);
TREE_TYPE (t) = type;
return t;
}
}
/* Perform constant folding and related simplification of EXPR. /* Perform constant folding and related simplification of EXPR.
The related simplifications include x*1 => x, x*0 => 0, etc., The related simplifications include x*1 => x, x*0 => 0, etc.,
and application of the associative law. and application of the associative law.
@ -5343,14 +5365,7 @@ fold (expr)
case GE_EXPR: case GE_EXPR:
case LE_EXPR: case LE_EXPR:
if (INTEGRAL_TYPE_P (TREE_TYPE (arg0))) if (INTEGRAL_TYPE_P (TREE_TYPE (arg0)))
{ return constant_boolean_node (1, type);
if (type == integer_type_node)
return integer_one_node;
t = build_int_2 (1, 0);
TREE_TYPE (t) = type;
return t;
}
code = EQ_EXPR; code = EQ_EXPR;
TREE_SET_CODE (t, code); TREE_SET_CODE (t, code);
break; break;
@ -5362,12 +5377,7 @@ fold (expr)
/* ... fall through ... */ /* ... fall through ... */
case GT_EXPR: case GT_EXPR:
case LT_EXPR: case LT_EXPR:
if (type == integer_type_node) return constant_boolean_node (0, type);
return integer_zero_node;
t = build_int_2 (0, 0);
TREE_TYPE (t) = type;
return t;
default: default:
abort (); abort ();
} }