summaryrefslogtreecommitdiff
path: root/gcc/fold-const.c
diff options
context:
space:
mode:
authorsayle <sayle@138bc75d-0d04-0410-961f-82ee72b054a4>2003-06-12 12:53:01 +0000
committersayle <sayle@138bc75d-0d04-0410-961f-82ee72b054a4>2003-06-12 12:53:01 +0000
commitcfb7235bd455b6ff12fac016c7612a53c24983a9 (patch)
treebee1e78d630354a7ade37f1018887b2ec4c5cb43 /gcc/fold-const.c
parent3067b4d9c6243f9ff88e678b26a15b91e690ed2d (diff)
downloadgcc-cfb7235bd455b6ff12fac016c7612a53c24983a9.tar.gz
* fold-const.c (tree_expr_nonnegative_p): Add support for
floating point constants, addition and multiplication. * gcc.dg/builtins-21.c: New test case. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@67828 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/fold-const.c')
-rw-r--r--gcc/fold-const.c22
1 files changed, 21 insertions, 1 deletions
diff --git a/gcc/fold-const.c b/gcc/fold-const.c
index 927b4d7410c..b3271a2c6da 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: