diff options
author | Roger Sayle <roger@eyesopen.com> | 2003-06-12 12:53:01 +0000 |
---|---|---|
committer | Roger Sayle <sayle@gcc.gnu.org> | 2003-06-12 12:53:01 +0000 |
commit | f7df23be90f2f2d73234546a192271007c29d5cc (patch) | |
tree | bee1e78d630354a7ade37f1018887b2ec4c5cb43 /gcc/fold-const.c | |
parent | 38b3ef8be6733c9b911cf9fac07d92d22d5b057c (diff) | |
download | gcc-f7df23be90f2f2d73234546a192271007c29d5cc.zip gcc-f7df23be90f2f2d73234546a192271007c29d5cc.tar.gz gcc-f7df23be90f2f2d73234546a192271007c29d5cc.tar.bz2 |
fold-const.c (tree_expr_nonnegative_p): Add support for floating point constants, addition and multiplication.
* fold-const.c (tree_expr_nonnegative_p): Add support for
floating point constants, addition and multiplication.
* gcc.dg/builtins-21.c: New test case.
From-SVN: r67828
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r-- | gcc/fold-const.c | 22 |
1 files changed, 21 insertions, 1 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 927b4d7..b3271a2 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -8014,9 +8014,29 @@ tree_expr_nonnegative_p (t) C[LT]Z_DEFINED_VALUE_AT_ZERO is set, since what we're computing here is a user-visible property. */ return 0; - + case INTEGER_CST: return tree_int_cst_sgn (t) >= 0; + + case REAL_CST: + return ! REAL_VALUE_NEGATIVE (TREE_REAL_CST (t)); + + case PLUS_EXPR: + return FLOAT_TYPE_P (TREE_TYPE (t)) + && tree_expr_nonnegative_p (TREE_OPERAND (t, 0)) + && tree_expr_nonnegative_p (TREE_OPERAND (t, 1)); + + case MULT_EXPR: + if (FLOAT_TYPE_P (TREE_TYPE (t))) + { + /* x * x for floating point x is always non-negative. */ + if (operand_equal_p (TREE_OPERAND (t, 0), TREE_OPERAND (t, 1), 0)) + return 1; + return tree_expr_nonnegative_p (TREE_OPERAND (t, 0)) + && tree_expr_nonnegative_p (TREE_OPERAND (t, 1)); + } + return 0; + case TRUNC_DIV_EXPR: case CEIL_DIV_EXPR: case FLOOR_DIV_EXPR: |