public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/62055] New: missed optimization: recognize fnabs (FP negative absolute value) (x86-64)
@ 2014-08-07 19:17 spatel at rotateright dot com
  2014-08-08  8:04 ` [Bug target/62055] " rguenth at gcc dot gnu.org
  0 siblings, 1 reply; 2+ messages in thread
From: spatel at rotateright dot com @ 2014-08-07 19:17 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=62055

            Bug ID: 62055
           Summary: missed optimization: recognize fnabs (FP negative
                    absolute value) (x86-64)
           Product: gcc
           Version: 4.9.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: target
          Assignee: unassigned at gcc dot gnu.org
          Reporter: spatel at rotateright dot com

$ cat fnabs.c
#include <math.h>
float foo(float a) {
    return -fabsf(a);
}
$ gcc49 -O1 fnabs.c -S -o -
    .text
    .globl _foo
_foo:
LFB19:
    movss    LC0(%rip), %xmm1
    andps    %xmm1, %xmm0
    movss    LC1(%rip), %xmm1
    xorps    %xmm1, %xmm0
    ret
LFE19:
    .literal16
    .align 4
LC0:
    .long    2147483647
    .long    0
    .long    0
    .long    0
    .align 4
LC1:
    .long    2147483648
    .long    0
    .long    0
    .long    0

---------------------------------------------------

That's a lot of constant pool data and instructions to turn on a single bit.

I think there are 2 steps to improving this. First, recognize that -(fabs(a))
can be transformed into an 'or' op:

    movss    LC0(%rip), %xmm1
        orps    %xmm1, %xmm0

LC0:
    .long    2147483648

Second, I don't think we need the extra 0 longs here; movss only loads 4 bytes.
This may require understanding that the upper vector elements for the 'orps'
are don't cares?


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

end of thread, other threads:[~2014-08-08  8:04 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-07 19:17 [Bug target/62055] New: missed optimization: recognize fnabs (FP negative absolute value) (x86-64) spatel at rotateright dot com
2014-08-08  8:04 ` [Bug target/62055] " rguenth 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).