When doing real by complex multiplications in C++ using std::complex<double>, 
the multiplication is transformed to a complex by complex multiplication, even 
though the imaginary part is zero for one of the arguments.  
  
This is similar to TR 19953, however there is still a problem even though it is 
supposed to be fixed.  
  
Here is a small test program:  
  
#include <complex>  
  
std::complex<double> a, b;  
double c;  
  
void f()  
{  
 a = b * c;  
}  
  
When compiled with "g++ -O3 -march=pentium4 -mfpmath=sse -S -c test.C", the 
following is produced (from test.s):  
  
_Z1fv:  
.LFB1857:  
 pushl %ebp  
.LCFI0:  
 movl %esp, %ebp  
.LCFI1:  
 movsd b+8, %xmm3  
 movsd b, %xmm2  
 movsd c, %xmm4  
 pxor %xmm5, %xmm5  
 movapd %xmm2, %xmm0  
 mulsd %xmm5, %xmm0  
 movapd %xmm4, %xmm1  
 mulsd %xmm3, %xmm1  
 addsd %xmm1, %xmm0  
 movsd %xmm0, a+8  
 mulsd %xmm4, %xmm2  
 mulsd %xmm5, %xmm3  
 subsd %xmm3, %xmm2  
 movsd %xmm2, a  
 popl %ebp  
 ret  
  
I.e, the real value c is still converted to a complex value and a full 
multiplication is done.  
  
I'm using the following version of gcc:  
  
Using built-in specs.  
Target: i686-pc-linux-gnu  
Configured with: ../gcc-4.0-20050312/configure --prefix=/home/fredrik/gcc  
--enable-languages=c,c++  
Thread model: posix  
gcc version 4.0.0 20050312 (prerelease)

-- 
           Summary: Real by complex multiplications perform unnecessary
                    operations
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: middle-end
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: fredrik dot huss at home dot se
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i686-pc-linux-gnu
  GCC host triplet: i686-pc-linux-gnu
GCC target triplet: i686-pc-linux-gnu


http://gcc.gnu.org/bugzilla/show_bug.cgi?id=20610

Reply via email to