[Bug rtl-optimization/37784] New: inefficient code for double compare double yielding double

rrh at google dot com gcc-bugzilla@gcc.gnu.org
Thu Oct 9 18:10:00 GMT 2008


The function:
double dfunc_001 ( const double a, const double b) { return a > b; }
yields the x86_64 code:
        cmpltsd %xmm0, %xmm1
        movapd  %xmm1, %xmm0
        movsd   .LC1(%rip), %xmm1
        andpd   %xmm0, %xmm1
        xorpd   %xmm2, %xmm2
        andnpd  %xmm2, %xmm0
        orpd    %xmm1, %xmm0
        ret
.LC1:
        .long   0
        .long   1072693248
Where LC1 is the fp constant +1.0

The 3 instruction sequence preceding the ret (eg xorpd;andnpd;orpd) is not
needed.  The xorpd generates a 0, which is anded with something to yield a 0,
which is or'ed in with the value (+0.0 or +1.0) to yield the result.

Similar illness is seen for the other compares built around cmpsd variants.

Some improvement is seen when compiling -O3, but in that case there are 2
unneeded instructions.


-- 
           Summary: inefficient code for double compare double yielding
                    double
           Product: gcc
           Version: 4.4.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: rtl-optimization
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: rrh at google dot com
 GCC build triplet: i686-host_pc-linux-gnu
  GCC host triplet: i686-host_pc-linux-gnu
GCC target triplet: x86_64-unknown-linux-gnu


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



More information about the Gcc-bugs mailing list