This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[PATCH] PR middle-end/11984: Fix 5.0 - x - 2.0 ICE


My sincere apologies.  It looks like a recent patch of mine to
allow "fold" to reassociate floating point operations other than
multiplication when using -ffast-math appears to have introduced
a regression.  I hadn't noticed but one of the clauses in the
association code currently assumes that the constant operands
being reassociated are always integer constants.  This leads to
an ICE on mainline compiling "5.0 - x - 2.0" with -ffast-math.

The patch below should resolve the failure.  The problematic call
to tree_int_cst_lt appears to just be working around a problem in
extract_muldiv, so guarding it by testing for INTEGER_CST appears
to be the correct solution.

On the positive side, its nice to see that mainline GCC can now
convert "5.0 - x - 2.0" into "3.0 - x", with -ffast-math, which
requires only a single floating point subtraction, where previously
we generated two.


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-19  Roger Sayle  <roger@eyesopen.com>

	PR middle-end/11984
	* fold-const.c (fold <PLUS_EXPR>): Check for integer constant
	operands before calling tree_int_cst_lt when performing associative
	transformations.

	* gcc.dg/20030819-1.c: New test case.


Index: fold-const.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.291
diff -c -3 -p -r1.291 fold-const.c
*** fold-const.c	14 Aug 2003 20:53:26 -0000	1.291
--- fold-const.c	20 Aug 2003 00:25:36 -0000
*************** fold (tree expr)
*** 5886,5892 ****
  		 example: ((X*2 + 4) - 8U)/2.  */
  	      if (minus_lit0 && lit0)
  		{
! 		  if (tree_int_cst_lt (lit0, minus_lit0))
  		    {
  		      minus_lit0 = associate_trees (minus_lit0, lit0,
  						    MINUS_EXPR, type);
--- 5886,5894 ----
  		 example: ((X*2 + 4) - 8U)/2.  */
  	      if (minus_lit0 && lit0)
  		{
! 		  if (TREE_CODE (lit0) == INTEGER_CST
! 		      && TREE_CODE (minus_lit0) == INTEGER_CST
! 		      && tree_int_cst_lt (lit0, minus_lit0))
  		    {
  		      minus_lit0 = associate_trees (minus_lit0, lit0,
  						    MINUS_EXPR, type);


/* PR middle-end/11984 */
/* The following program used to ICE in fold because we didn't check
   whether the constants we were reassociating were integer constants
   before calling tree_int_cst_lt.  */

/* { dg-do compile } */
/* { dg-options "-O2 -ffast-math" } */

double f(double x)
{
  return 5.0 - x - 2.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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]