This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] PR middle-end/11771: Tighten up negate_expr_p
- From: Roger Sayle <roger at eyesopen dot com>
- To: gcc-patches at gcc dot gnu dot org
- Cc: Falk Hueffner <falk dot hueffner at student dot uni-tuebingen dot de>
- Date: Sun, 3 Aug 2003 15:33:06 -0600 (MDT)
- Subject: [PATCH] PR middle-end/11771: Tighten up negate_expr_p
The following patch fixes PR middle-end/11771 which is an ICE-on-valid.
The cause of the failure is that the logic in negate_expr_p doesn't
quite match that in negate_expr. We then try to simplify something
that doesn't get simplified, which leads to unbounded recursion in
fold, which then kills the compiler with a segmentation fault.
Alas the bug is mine. Apologies for any inconvenience this may have
caused. Many thanks to Falk Hueffner from bringing it to my attention.
The fix is simple. Tighten the MINUS_EXPR case in negate_expr_p to
match the condition in negate_expr. For floating point expressions,
we can't convert -(x-y) into y-x unless -ffast-math is specified due
to potential problems with signed zeros and/or sign-dependent rounding.
The following patch has been tested on i686-pc-linux-gnu with a full
"make bootstrap", all languages except treelang, and regression tested
with a top-level "make -k check" with no new failures.
Ok for mainline?
2003-08-03 Roger Sayle <roger@eyesopen.com>
PR middle-end/11771
* fold-const.c (negate_expr_p <MINUS_EXPR>): 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.
* gcc.c-torture/compile/20030803-1.c: New test case.
Index: fold-const.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.287
diff -c -3 -p -r1.287 fold-const.c
*** fold-const.c 1 Aug 2003 00:36:52 -0000 1.287
--- fold-const.c 3 Aug 2003 18:54:37 -0000
*************** negate_expr_p (tree t)
*** 841,848 ****
case REAL_CST:
case NEGATE_EXPR:
- case MINUS_EXPR:
return true;
default:
break;
--- 841,851 ----
case REAL_CST:
case NEGATE_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;
/* 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);
}
Roger
--
Roger Sayle, E-mail: roger@eyesopen.com
OpenEye Scientific Software, WWW: http://www.eyesopen.com/
Suite 1107, 3600 Cerrillos Road, Tel: (+1) 505-473-7385
Santa Fe, New Mexico, 87507. Fax: (+1) 505-473-0833