diff --git a/gcc/ChangeLog b/gcc/ChangeLog index daf0bec3424..60bfb0289e4 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,3 +1,10 @@ +2003-08-04 Roger Sayle + + PR middle-end/11771 + * fold-const.c (negate_expr_p ): Change to match the + logic in negate_expr, i.e. we don't invert (A-B) for floating + point types unless flag_unsafe_math_optimizations. + 2003-08-04 Roger Sayle * fold-const.c (fold ): Transform x+x into x*2.0. diff --git a/gcc/fold-const.c b/gcc/fold-const.c index 4dd606f68bf..9333c590747 100644 --- a/gcc/fold-const.c +++ b/gcc/fold-const.c @@ -841,9 +841,12 @@ negate_expr_p (tree t) case REAL_CST: case NEGATE_EXPR: - case MINUS_EXPR: return true; + case MINUS_EXPR: + /* We can't turn -(A-B) into B-A when we honor signed zeros. */ + return ! FLOAT_TYPE_P (type) || flag_unsafe_math_optimizations; + default: break; } diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog index ba19bc89283..86e12c522c4 100644 --- a/gcc/testsuite/ChangeLog +++ b/gcc/testsuite/ChangeLog @@ -1,3 +1,8 @@ +2003-08-04 Roger Sayle + + PR middle-end/11771 + * gcc.c-torture/compile/20030804-1.c: New test case. + 2003-08-04 Roger Sayle * gcc.dg/20030804-1.c: New test case. diff --git a/gcc/testsuite/gcc.c-torture/compile/20030804-1.c b/gcc/testsuite/gcc.c-torture/compile/20030804-1.c new file mode 100644 index 00000000000..189fde3cee5 --- /dev/null +++ b/gcc/testsuite/gcc.c-torture/compile/20030804-1.c @@ -0,0 +1,9 @@ +/* Extracted from PR middle-end/11771. */ +/* The following testcase used to ICE without -ffast-math from unbounded + recursion in fold. This was due to the logic in negate_expr_p not + matching that in negate_expr. */ + +double f(double x) { + return -(1 - x) + (x ? -(1 - x) : 0); +} +