This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug target/17390] New: missing floating point compare optimization


The if optimization, which produces quite optimized code for integer case is
missing for floatin-point compares.

This code:

int test(int a) {
       return a == 0 ? 0 : (a > 0 ? 1 : -1);
}


produces (with -O2 -fomit-frame-pointer):

test:
       xorl    %eax, %eax
       cmpl    $0, 4(%esp)
       je      .L4
       setg    %al
       movzbl  %al, %eax
       leal    -1(%eax,%eax), %eax
.L4:
       ret


However, fp compares:

double testf(double a) {
       return a == 0.0 ? 0.0 : (a > 0.0 ? 1.0 : -1.0);
}


Produce somehow unoptimized code (-O2 -ffast-math -fomit-frame-pointer):

testf:
       fldl    4(%esp)
       ftst
       fnstsw  %ax
       sahf
       jne     .L9
       fstp    %st(0)
       fldz
       ret
       .p2align 4,,7
.L9:
       ftst
       fnstsw  %ax
       fstp    %st(0)
       sahf
       ja      .L12
       flds    .LC1
       ret
       .p2align 4,,7
.L12:
       fld1
       .p2align 4,,2
       ret


There is no need for second fp compare, two conditional jumps after first fp
compare would be enough.

-- 
           Summary: missing floating point compare optimization
           Product: gcc
           Version: 4.0.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P2
         Component: target
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: uros at kss-loka dot si
                CC: gcc-bugs at gcc dot gnu dot org
 GCC build triplet: i686-*-*-*
  GCC host triplet: i686-*-*-*
GCC target triplet: i586-*-*-*


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


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]