diff options
author | mmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4> | 1998-05-15 07:19:38 +0000 |
---|---|---|
committer | mmitchel <mmitchel@138bc75d-0d04-0410-961f-82ee72b054a4> | 1998-05-15 07:19:38 +0000 |
commit | b4af30fde71df3982b0b99f453816da5b7c7b3b7 (patch) | |
tree | 2e00495fcce6dbb97ffa17134d5329d55dab5c66 /gcc/fold-const.c | |
parent | b9a72f1d754323776fc09689aed260d280217bb1 (diff) | |
download | gcc-b4af30fde71df3982b0b99f453816da5b7c7b3b7.tar.gz |
* fold-const.c (constant_boolean_node): New function.
(fold): Use it.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@19775 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r-- | gcc/fold-const.c | 38 |
1 files changed, 24 insertions, 14 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c index bfcaed7746e..c47f80a7b68 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -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 strip_compound_expr PROTO((tree, tree)); static int multiple_of_p PROTO((tree, tree, tree)); +static tree constant_boolean_node PROTO((int, tree)); #ifndef BRANCH_COST #define BRANCH_COST 1 @@ -3702,6 +3703,27 @@ strip_compound_expr (t, s) 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. The related simplifications include x*1 => x, x*0 => 0, etc., and application of the associative law. @@ -5343,14 +5365,7 @@ fold (expr) case GE_EXPR: case LE_EXPR: if (INTEGRAL_TYPE_P (TREE_TYPE (arg0))) - { - if (type == integer_type_node) - return integer_one_node; - - t = build_int_2 (1, 0); - TREE_TYPE (t) = type; - return t; - } + return constant_boolean_node (1, type); code = EQ_EXPR; TREE_SET_CODE (t, code); break; @@ -5362,12 +5377,7 @@ fold (expr) /* ... fall through ... */ case GT_EXPR: case LT_EXPR: - if (type == integer_type_node) - return integer_zero_node; - - t = build_int_2 (0, 0); - TREE_TYPE (t) = type; - return t; + return constant_boolean_node (0, type); default: abort (); } |