public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/51938] New: missed optimization: 2 comparisons
@ 2012-01-21 22:54 marc.glisse at normalesup dot org
  2012-01-23 10:29 ` [Bug rtl-optimization/51938] " rguenth at gcc dot gnu.org
                   ` (9 more replies)
  0 siblings, 10 replies; 11+ messages in thread
From: marc.glisse at normalesup dot org @ 2012-01-21 22:54 UTC (permalink / raw)
  To: gcc-bugs

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

             Bug #: 51938
           Summary: missed optimization: 2 comparisons
    Classification: Unclassified
           Product: gcc
           Version: 4.7.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: marc.glisse@normalesup.org


Hello,

this is possibly related to bug 28685, or to the bugs about the tracking of
flag register values.

void f();
enum Sign { NEG=-1, ZERO, POS };
enum Sign sign(double x){
    if(x>0) return POS;
    if(x<0) return NEG;
    return ZERO;
}
void g(double x){
    if(sign(x)==NEG) f();
}


Ideally, the compiler would realize that g is equivalent to:
if(x<0) f();

but on x86_64 I get with 4.6 (optimization -O3):

    xorpd    %xmm1, %xmm1
    ucomisd    %xmm1, %xmm0
    ja    .L8
    ucomisd    %xmm0, %xmm1
    jbe    .L8
    xorl    %eax, %eax
    jmp    f
.L8:
    rep
    ret

And with 4.7:

    xorpd    %xmm1, %xmm1
    ucomisd    %xmm1, %xmm0
    jbe    .L12
.L9:
    rep
    ret
.L12:
    ucomisd    %xmm0, %xmm1
    jbe    .L9
    xorl    %eax, %eax
    jmp    f

Other compilers: clang 2.9 does the optimization (it has only one ucomisd and
j*), but neither Intel 11.1 nor Oracle 5.12.

In my application, this optimization has a 5% impact on the total runtime.


^ permalink raw reply	[flat|nested] 11+ messages in thread

end of thread, other threads:[~2012-08-06 16:53 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-01-21 22:54 [Bug tree-optimization/51938] New: missed optimization: 2 comparisons marc.glisse at normalesup dot org
2012-01-23 10:29 ` [Bug rtl-optimization/51938] " rguenth at gcc dot gnu.org
2012-01-23 13:07 ` marc.glisse at normalesup dot org
2012-06-06 21:23 ` glisse at gcc dot gnu.org
2012-06-07 14:54 ` [Bug tree-optimization/51938] " marc.glisse at normalesup dot org
2012-06-08 13:07 ` glisse at gcc dot gnu.org
2012-06-08 19:49 ` glisse at gcc dot gnu.org
2012-06-08 20:03 ` glisse at gcc dot gnu.org
2012-06-09 21:36 ` glisse at gcc dot gnu.org
2012-08-06 16:39 ` glisse at gcc dot gnu.org
2012-08-06 16:53 ` glisse at gcc dot gnu.org

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).