This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
[PATCH] PR middle-end/12002: Don't fold z+z as z*2.0 for complex z
- From: Roger Sayle <roger at eyesopen dot com>
- To: gcc-patches at gcc dot gnu dot org
- Date: Sun, 24 Aug 2003 15:30:21 -0600 (MDT)
- Subject: [PATCH] PR middle-end/12002: Don't fold z+z as z*2.0 for complex z
The following patch fixes PR middle-end/12002, an ICE on legal that's
caused by one of my recent middle-end changes. It transpires that I
wasn't testing for (guarding against) complex floating point types
when I introduced the x+x into x*2.0 transformation. Unfortunately,
a REAL_CST isn't a valid operand for complex multiplications!
The following "obvious" patch fixes the failure by checking that the
type isn't a complex type. Hopefully, I'll redeem myself to the CERN
folks by providing the equivalent optimizations for complex types in
the near future, i.e. z+z -> z*(2+0i) and z*c+z -> z*(c+(1+0i)) 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. The new fortran
testcase fails without this patch, but passes with it.
Ok for mainline? Sorry for any inconvenience.
2003-08-24 Roger Sayle <roger@eyesopen.com>
PR middle-end/12002
* fold-const.c (fold <PLUS_EXPR>): Don't convert x+x into x*2.0
for complex floating point types.
* g77.f-torture/compile/20030824-1.f: New test case.
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 24 Aug 2003 17:58:38 -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)
! && TREE_CODE (type) != COMPLEX_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