From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: (qmail 6019 invoked by alias); 7 Aug 2014 19:17:15 -0000 Mailing-List: contact gcc-bugs-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Archive: List-Post: List-Help: Sender: gcc-bugs-owner@gcc.gnu.org Received: (qmail 5993 invoked by uid 48); 7 Aug 2014 19:17:11 -0000 From: "spatel at rotateright dot com" To: gcc-bugs@gcc.gnu.org Subject: [Bug target/62055] New: missed optimization: recognize fnabs (FP negative absolute value) (x86-64) Date: Thu, 07 Aug 2014 19:17:00 -0000 X-Bugzilla-Reason: CC X-Bugzilla-Type: new X-Bugzilla-Watch-Reason: None X-Bugzilla-Product: gcc X-Bugzilla-Component: target X-Bugzilla-Version: 4.9.0 X-Bugzilla-Keywords: X-Bugzilla-Severity: normal X-Bugzilla-Who: spatel at rotateright dot com X-Bugzilla-Status: UNCONFIRMED X-Bugzilla-Priority: P3 X-Bugzilla-Assigned-To: unassigned at gcc dot gnu.org X-Bugzilla-Target-Milestone: --- X-Bugzilla-Flags: X-Bugzilla-Changed-Fields: bug_id short_desc product version bug_status bug_severity priority component assigned_to reporter Message-ID: Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: 7bit X-Bugzilla-URL: http://gcc.gnu.org/bugzilla/ Auto-Submitted: auto-generated MIME-Version: 1.0 X-SW-Source: 2014-08/txt/msg00480.txt.bz2 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 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?