public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/62041] New: vector fneg codegen uses a subtract instead of an xor (x86-64)
@ 2014-08-06 19:06 spatel at rotateright dot com
  2014-08-07  9:42 ` [Bug rtl-optimization/62041] " rguenth at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: spatel at rotateright dot com @ 2014-08-06 19:06 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 62041
           Summary: vector fneg codegen uses a subtract instead of an xor
                    (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 fneg.c
#include <xmmintrin.h>

__m128 fneg4(__m128 x) {
    return _mm_sub_ps(_mm_set1_ps(-0.0), x);
}

$ ~gcc49/local/bin/gcc -march=core-avx2 -O2 -S fneg.c -o - 
...
_fneg4:
LFB513:
    vmovaps    LC0(%rip), %xmm1
    vsubps    %xmm0, %xmm1, %xmm0
    ret
...
LC0:
    .long    2147483648
    .long    2147483648
    .long    2147483648
    .long    2147483648

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

Instead of generating 'vsubps' here, it would be better to generate 'vxorps'
because we know we're just flipping the sign bit of each element. This is what
gcc does for the scalar version of this code.

Note that there is no difference if I use -ffast-math with this testcase. With
-ffast-math enabled, we should generate the same 'xorps' code even if the
"-0.0" is "+0.0". Again, that's what the scalar codegen does, so I think this
is just a deficiency when generating vector code.

I can file the -ffast-math case as a separate bug if that would be better.


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

* [Bug rtl-optimization/62041] vector fneg codegen uses a subtract instead of an xor (x86-64)
  2014-08-06 19:06 [Bug target/62041] New: vector fneg codegen uses a subtract instead of an xor (x86-64) spatel at rotateright dot com
@ 2014-08-07  9:42 ` rguenth at gcc dot gnu.org
  2014-08-07 10:06 ` glisse at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu.org @ 2014-08-07  9:42 UTC (permalink / raw)
  To: gcc-bugs

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

Richard Biener <rguenth at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |missed-optimization
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2014-08-07
          Component|target                      |rtl-optimization
     Ever confirmed|0                           |1

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
That's because _mm_sub_ps is a builtin during gimple opts and on RTL we
generally don't do very many FP related optimizations (especially on vectors).

Confirmed.

(insn 6 5 7 (set (reg:V4SF 87)
        (mem/u/c:V4SF (symbol_ref/u:DI ("*.LC0") [flags 0x2]) [2  S16 A128]))
/usr/lib64/gcc/x86_64-suse-linux/4.9/include/xmmintrin.h:189 -1
     (expr_list:REG_EQUAL (const_vector:V4SF [
                (const_double:SF -0.0 [-0x0.0p+0])
                (const_double:SF -0.0 [-0x0.0p+0])
                (const_double:SF -0.0 [-0x0.0p+0])
                (const_double:SF -0.0 [-0x0.0p+0])
            ])
        (nil)))

(insn 7 6 8 (set (reg:V4SF 86)
        (minus:V4SF (reg:V4SF 87)
            (reg/v:V4SF 85 [ x ])))
/usr/lib64/gcc/x86_64-suse-linux/4.9/include/xmmintrin.h:189 -1
     (nil))

could be optimized guarded with the appropriate flags (signed zeros?
nans/infs?).


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

* [Bug rtl-optimization/62041] vector fneg codegen uses a subtract instead of an xor (x86-64)
  2014-08-06 19:06 [Bug target/62041] New: vector fneg codegen uses a subtract instead of an xor (x86-64) spatel at rotateright dot com
  2014-08-07  9:42 ` [Bug rtl-optimization/62041] " rguenth at gcc dot gnu.org
@ 2014-08-07 10:06 ` glisse at gcc dot gnu.org
  2014-08-07 10:10 ` glisse at gcc dot gnu.org
  2014-08-07 10:22 ` glisse at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: glisse at gcc dot gnu.org @ 2014-08-07 10:06 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Marc Glisse <glisse at gcc dot gnu.org> ---
https://gcc.gnu.org/ml/gcc-patches/2014-07/msg01812.html would most likely fix
it...


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

* [Bug rtl-optimization/62041] vector fneg codegen uses a subtract instead of an xor (x86-64)
  2014-08-06 19:06 [Bug target/62041] New: vector fneg codegen uses a subtract instead of an xor (x86-64) spatel at rotateright dot com
  2014-08-07  9:42 ` [Bug rtl-optimization/62041] " rguenth at gcc dot gnu.org
  2014-08-07 10:06 ` glisse at gcc dot gnu.org
@ 2014-08-07 10:10 ` glisse at gcc dot gnu.org
  2014-08-07 10:22 ` glisse at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: glisse at gcc dot gnu.org @ 2014-08-07 10:10 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Marc Glisse <glisse at gcc dot gnu.org> ---
(In reply to Marc Glisse from comment #2)
> https://gcc.gnu.org/ml/gcc-patches/2014-07/msg01812.html would most likely
> fix it...

Ah, no, it doesn't:

  _2 = { -0.0, -0.0, -0.0, -0.0 } - x_1(D);

doesn't get simplified to negate_expr in gimple either.


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

* [Bug rtl-optimization/62041] vector fneg codegen uses a subtract instead of an xor (x86-64)
  2014-08-06 19:06 [Bug target/62041] New: vector fneg codegen uses a subtract instead of an xor (x86-64) spatel at rotateright dot com
                   ` (2 preceding siblings ...)
  2014-08-07 10:10 ` glisse at gcc dot gnu.org
@ 2014-08-07 10:22 ` glisse at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: glisse at gcc dot gnu.org @ 2014-08-07 10:22 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Marc Glisse <glisse at gcc dot gnu.org> ---
(The gimple version works with -ffast-math at least)

In fold-const.c, fold_real_zero_addition_p has:

  /* In a vector or complex, we would need to check the sign of all zeros.  */
  if (TREE_CODE (addend) != REAL_CST)
    return false;

We should probably check the sign of all zeros indeed.


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

end of thread, other threads:[~2014-08-07 10:22 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-08-06 19:06 [Bug target/62041] New: vector fneg codegen uses a subtract instead of an xor (x86-64) spatel at rotateright dot com
2014-08-07  9:42 ` [Bug rtl-optimization/62041] " rguenth at gcc dot gnu.org
2014-08-07 10:06 ` glisse at gcc dot gnu.org
2014-08-07 10:10 ` glisse at gcc dot gnu.org
2014-08-07 10:22 ` 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).