Commit f7df23be by Roger Sayle Committed by Roger Sayle

fold-const.c (tree_expr_nonnegative_p): Add support for floating point…

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
parent 38b3ef8b
2003-06-12 Roger Sayle <roger@eyesopen.com>
* fold-const.c (tree_expr_nonnegative_p): Add support for
floating point constants, addition and multiplication.
2003-06-12 J"orn Rennecke <joern.rennecke@superh.com>
* sh.md (adddi3_compact, subdi3_compact): Add earlyclobber
......
......@@ -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:
......
2003-06-12 Roger Sayle <roger@eyesopen.com>
* gcc.dg/builtins-21.c: New test case.
2003-06-11 Kelley Cook <kelleycook@wideopenwest.com>
* lib/gcc.exp (gcc_target_compile): Put TOOL_OPTIONS at front of
......
/* Copyright (C) 2003 Free Software Foundation.
Verify that built-in math function constant folding doesn't
cause any problems for the compiler.
Written by Roger Sayle, 7th June 2003. */
/* { dg-do compile } */
/* { dg-options "-O2 -ffast-math" } */
double test1(double x)
{
return fabs(x*x);
}
double test2(double x)
{
return fabs(sqrt(x)+2.0);
}
double test3(double x)
{
return fabs(3.0*exp(x));
}
float test1f(float x)
{
return fabsf(x*x);
}
float test2f(float x)
{
return fabsf(sqrtf(x)+2.0f);
}
float test3f(float x)
{
return fabsf(3.0f*expf(x));
}
long double test1l(long double x)
{
return fabsl(x*x);
}
long double test2l(long double x)
{
return fabsl(sqrtl(x)+2.0l);
}
long double test3l(long double x)
{
return fabsl(3.0l*expl(x));
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment