[Bug middle-end/37850] infinite recursive call to __mulsc3 when multiplying not-constant complexs
rguenth at gcc dot gnu dot org
gcc-bugzilla@gcc.gnu.org
Sat Oct 18 12:44:00 GMT 2008
------- Comment #7 from rguenth at gcc dot gnu dot org 2008-10-18 12:43 -------
This is because the implementation of __muldc3 uses
return x + I * y;
which if built with -O0 results in a call to __muldc3 ... because this
is what complex lowering at -O0 produces:
<bb 2>:
D.1235 = COMPLEX_EXPR <x, 0.0>;
D.1236 = COMPLEX_EXPR <y, 0.0>;
D.1241 = REALPART_EXPR <D.1236>;
D.1242 = IMAGPART_EXPR <D.1236>;
D.1237 = __muldc3 (D.1241, D.1242, 0.0, 1.0e+0);
D.1243 = REALPART_EXPR <D.1235>;
D.1244 = IMAGPART_EXPR <D.1235>;
D.1245 = REALPART_EXPR <D.1237>;
D.1246 = IMAGPART_EXPR <D.1237>;
D.1247 = D.1243 + D.1245;
D.1248 = D.1244 + D.1246;
D.1238 = COMPLEX_EXPR <D.1247, D.1248>;
<retval> = D.1238;
return <retval>;
That said - you shouldn't build libgcc itself without optimization.
Still I see a missed optimization in that we do not fold
COMPLEX_EXPR <x, 0.0> + COMPLEX_EXPR <y, 0.0> * __complex__ (0.0, 1.0e+0);
I thought I added this capability. And I did:
/* Fold z * +-I to __complex__ (-+__imag z, +-__real z).
This is not the same for NaNs or if signed zeros are
involved. */
if (!HONOR_NANS (TYPE_MODE (TREE_TYPE (arg0)))
&& !HONOR_SIGNED_ZEROS (TYPE_MODE (TREE_TYPE (arg0)))
&& COMPLEX_FLOAT_TYPE_P (TREE_TYPE (arg0))
&& TREE_CODE (arg1) == COMPLEX_CST
&& real_zerop (TREE_REALPART (arg1)))
The question is whether the standard requires actual complex multiplication
carried out for y * I, as it seems to allow an imaginary type used for I
as well.
A probably better writing of the return statement is
CTYPE res;
__real res = x;
__imag res = y;
return res;
which should be valid, as the NaN cases are checked earlier.
Joseph?
--
rguenth at gcc dot gnu dot org changed:
What |Removed |Added
----------------------------------------------------------------------------
CC| |jsm28 at gcc dot gnu dot org
Severity|normal |enhancement
Status|UNCONFIRMED |NEW
Component|c |middle-end
Ever Confirmed|0 |1
Keywords| |build, missed-optimization
Last reconfirmed|0000-00-00 00:00:00 |2008-10-18 12:43:35
date| |
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=37850
More information about the Gcc-bugs
mailing list