[PATCH] PR middle-end/12002: Don't fold z+z as z*2.0 for complex z (take 2)

Roger Sayle roger@eyesopen.com
Tue Aug 26 13:55:00 GMT 2003


On Mon, 25 Aug 2003, Richard Henderson wrote:
> On Sun, Aug 24, 2003 at 03:30:21PM -0600, Roger Sayle wrote:
> > - 	  if (operand_equal_p (arg0, arg1, 0))
> > + 	  if (operand_equal_p (arg0, arg1, 0)
> > + 	      && TREE_CODE (type) != COMPLEX_TYPE)
>
> I'd prefer that you check == REAL_TYPE.  Or, even better, introduce
> a SCALAR_FLOAT_TYPE_P to match SCALAR_FLOAT_MODE_P.

I've revised my patch by adding both SCALAR_FLOAT_TYPE_P and
COMPLEX_FLOAT_TYPE_P to tree.h.  FLOAT_TYPE_P is now the union of
these two macros.  I then check for SCALAR_FLOAT_TYPE_P in the my
main fix.  I've also renamed the new testcase as requested by Toon.


> Along these lines I wonder if there's code that's currently checking
> FLOAT_TYPE_P that does the wrong thing for fp vector types.

I expect to be going through fold-const checking FLOAT_TYPE_P usage
soon.  Not only for cases where we apply scalar optimizations when we
shouldn't but also adding new complex optimizations that we currently
miss by checking for REAL_CST instead of COMPLEX_CST, etc...


The following patch has been tested on i686-pc-linux-gnu with a complete
"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-26  Roger Sayle  <roger@eyesopen.com>

	PR middle-end/12002
	* tree.h (SCALAR_FLOAT_TYPE_P, COMPLEX_FLOAT_TYPE_P): New macros.
	(FLOAT_TYPE_P): Define in terms of these two new macros.
	* fold-const.c (fold <PLUS_EXPR>): Don't convert x+x into x*2.0
	for complex floating point types.

	* g77.f-torture/compile/12002.f: New test case.


Index: tree.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/tree.h,v
retrieving revision 1.439
diff -c -3 -p -r1.439 tree.h
*** tree.h	25 Aug 2003 15:47:26 -0000	1.439
--- tree.h	26 Aug 2003 03:42:03 -0000
*************** extern void tree_operand_check_failed (i
*** 446,458 ****
    (TREE_CODE (TYPE) == INTEGER_TYPE || TREE_CODE (TYPE) == ENUMERAL_TYPE  \
     || TREE_CODE (TYPE) == BOOLEAN_TYPE || TREE_CODE (TYPE) == CHAR_TYPE)

  /* Nonzero if TYPE represents a floating-point type, including complex
     floating-point types.  */

  #define FLOAT_TYPE_P(TYPE)		\
!   (TREE_CODE (TYPE) == REAL_TYPE	\
!    || (TREE_CODE (TYPE) == COMPLEX_TYPE \
!        && TREE_CODE (TREE_TYPE (TYPE)) == REAL_TYPE))

  /* Nonzero if TYPE represents an aggregate (multi-component) type.  */

--- 446,466 ----
    (TREE_CODE (TYPE) == INTEGER_TYPE || TREE_CODE (TYPE) == ENUMERAL_TYPE  \
     || TREE_CODE (TYPE) == BOOLEAN_TYPE || TREE_CODE (TYPE) == CHAR_TYPE)

+ /* Nonzero if TYPE represents a scalar floating-point type.  */
+
+ #define SCALAR_FLOAT_TYPE_P(TYPE) (TREE_CODE (TYPE) == REAL_TYPE)
+
+ /* Nonzero if TYPE represents a complex floating-point type.  */
+
+ #define COMPLEX_FLOAT_TYPE_P(TYPE)	\
+   (TREE_CODE (TYPE) == COMPLEX_TYPE	\
+    && TREE_CODE (TREE_TYPE (TYPE)) == REAL_TYPE)
+
  /* Nonzero if TYPE represents a floating-point type, including complex
     floating-point types.  */

  #define FLOAT_TYPE_P(TYPE)		\
!   (SCALAR_FLOAT_TYPE_P (TYPE) || COMPLEX_FLOAT_TYPE_P (TYPE))

  /* Nonzero if TYPE represents an aggregate (multi-component) type.  */

Index: fold-const.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fold-const.c,v
retrieving revision 1.297
diff -c -3 -p -r1.297 fold-const.c
*** fold-const.c	22 Aug 2003 06:45:13 -0000	1.297
--- fold-const.c	26 Aug 2003 03:42:04 -0000
*************** fold (tree expr)
*** 5713,5719 ****
  	    return non_lvalue (convert (type, arg1));

  	  /* Convert x+x into x*2.0.  */
! 	  if (operand_equal_p (arg0, arg1, 0))
  	    return fold (build (MULT_EXPR, type, arg0,
  				build_real (type, dconst2)));

--- 5713,5720 ----
  	    return non_lvalue (convert (type, arg1));

  	  /* Convert x+x into x*2.0.  */
! 	  if (operand_equal_p (arg0, arg1, 0)
! 	      && SCALAR_FLOAT_TYPE_P (type))
  	    return fold (build (MULT_EXPR, type, arg0,
  				build_real (type, dconst2)));



C      PR middle-end/12002
       COMPLEX TE1
       TE1=-2.
       TE1=TE1+TE1
       END


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



More information about the Gcc-patches mailing list