public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug target/54703] New: [miscompilation] _mm_sub_pd is incorrectly substituted with vandnps
@ 2012-09-25 13:29 kretz at kde dot org
  2012-09-25 13:32 ` [Bug target/54703] " kretz at kde dot org
                   ` (11 more replies)
  0 siblings, 12 replies; 13+ messages in thread
From: kretz at kde dot org @ 2012-09-25 13:29 UTC (permalink / raw)
  To: gcc-bugs


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

             Bug #: 54703
           Summary: [miscompilation] _mm_sub_pd is incorrectly substituted
                    with vandnps
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: major
          Priority: P3
         Component: target
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: kretz@kde.org


The following testcase:

#include <xmmintrin.h>
__attribute__((aligned(16))) static const unsigned long long mask[2] = {
0xffffffffff000000ull, 0xffffffffff000000ull };
inline __m128d foo(__m128d v1) {
    const __m128d h1 = _mm_and_pd(v1, _mm_load_pd(reinterpret_cast<const double
*>(&mask)));
    const __m128d l1 = _mm_sub_pd(v1, h1);
    return _mm_mul_pd(h1, l1);
}
__m128d test() {
    __m128d a = _mm_set1_pd(2.);
    return foo(foo(a));
}

compiles to

        .cfi_startproc
        vmovaps _ZL4mask(%rip), %xmm0
        vandps  .LC0(%rip), %xmm0, %xmm2
        vandnps .LC0(%rip), %xmm0, %xmm1
        vmulpd  %xmm1, %xmm2, %xmm1
        vandps  %xmm0, %xmm1, %xmm0
        vsubpd  %xmm0, %xmm1, %xmm1
        vmulpd  %xmm1, %xmm0, %xmm0
        ret
        .cfi_endproc

The second foo call is correct: vandps and vsubpd are used. But the first call
uses vandps and vandnps. This pattern would be correct for integers, but is
obviously wrong for floating point numbers.


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

* [Bug target/54703] [miscompilation] _mm_sub_pd is incorrectly substituted with vandnps
  2012-09-25 13:29 [Bug target/54703] New: [miscompilation] _mm_sub_pd is incorrectly substituted with vandnps kretz at kde dot org
@ 2012-09-25 13:32 ` kretz at kde dot org
  2012-09-25 13:48 ` [Bug target/54703] " rguenth at gcc dot gnu.org
                   ` (10 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: kretz at kde dot org @ 2012-09-25 13:32 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #1 from Matthias Kretz <kretz at kde dot org> 2012-09-25 13:32:27 UTC ---
Um, sorry. Forgot to note the compiler switches:

gcc -O1 -march=bdver1

I can't reproduce the error with corei7-avx or any other non-AVX target.


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

* [Bug target/54703] _mm_sub_pd is incorrectly substituted with vandnps
  2012-09-25 13:29 [Bug target/54703] New: [miscompilation] _mm_sub_pd is incorrectly substituted with vandnps kretz at kde dot org
  2012-09-25 13:32 ` [Bug target/54703] " kretz at kde dot org
  2012-09-25 13:48 ` [Bug target/54703] " rguenth at gcc dot gnu.org
@ 2012-09-25 13:48 ` jakub at gcc dot gnu.org
  2012-09-25 14:30 ` jakub at gcc dot gnu.org
                   ` (8 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu.org @ 2012-09-25 13:48 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #3 from Jakub Jelinek <jakub at gcc dot gnu.org> 2012-09-25 13:48:10 UTC ---
Looking into it.


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

* [Bug target/54703] _mm_sub_pd is incorrectly substituted with vandnps
  2012-09-25 13:29 [Bug target/54703] New: [miscompilation] _mm_sub_pd is incorrectly substituted with vandnps kretz at kde dot org
  2012-09-25 13:32 ` [Bug target/54703] " kretz at kde dot org
@ 2012-09-25 13:48 ` rguenth at gcc dot gnu.org
  2012-09-25 13:48 ` jakub at gcc dot gnu.org
                   ` (9 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-09-25 13:48 UTC (permalink / raw)
  To: gcc-bugs


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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |wrong-code
             Target|                            |x86_64-*-*, i?86-*-*
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2012-09-25
            Summary|[miscompilation] _mm_sub_pd |_mm_sub_pd is incorrectly
                   |is incorrectly substituted  |substituted with vandnps
                   |with vandnps                |
     Ever Confirmed|0                           |1

--- Comment #2 from Richard Guenther <rguenth at gcc dot gnu.org> 2012-09-25 13:47:48 UTC ---
Confirmed.


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

* [Bug target/54703] _mm_sub_pd is incorrectly substituted with vandnps
  2012-09-25 13:29 [Bug target/54703] New: [miscompilation] _mm_sub_pd is incorrectly substituted with vandnps kretz at kde dot org
                   ` (2 preceding siblings ...)
  2012-09-25 13:48 ` jakub at gcc dot gnu.org
@ 2012-09-25 14:30 ` jakub at gcc dot gnu.org
  2012-09-25 14:35 ` jakub at gcc dot gnu.org
                   ` (7 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu.org @ 2012-09-25 14:30 UTC (permalink / raw)
  To: gcc-bugs


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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org
   Target Milestone|---                         |4.6.4


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

* [Bug target/54703] _mm_sub_pd is incorrectly substituted with vandnps
  2012-09-25 13:29 [Bug target/54703] New: [miscompilation] _mm_sub_pd is incorrectly substituted with vandnps kretz at kde dot org
                   ` (3 preceding siblings ...)
  2012-09-25 14:30 ` jakub at gcc dot gnu.org
@ 2012-09-25 14:35 ` jakub at gcc dot gnu.org
  2012-09-25 18:04 ` pinskia at gcc dot gnu.org
                   ` (6 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu.org @ 2012-09-25 14:35 UTC (permalink / raw)
  To: gcc-bugs


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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
         AssignedTo|unassigned at gcc dot       |jakub at gcc dot gnu.org
                   |gnu.org                     |

--- Comment #4 from Jakub Jelinek <jakub at gcc dot gnu.org> 2012-09-25 14:34:32 UTC ---
Created attachment 28270
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=28270
gcc48-pr54703.patch

Untested fix.


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

* [Bug target/54703] _mm_sub_pd is incorrectly substituted with vandnps
  2012-09-25 13:29 [Bug target/54703] New: [miscompilation] _mm_sub_pd is incorrectly substituted with vandnps kretz at kde dot org
                   ` (4 preceding siblings ...)
  2012-09-25 14:35 ` jakub at gcc dot gnu.org
@ 2012-09-25 18:04 ` pinskia at gcc dot gnu.org
  2012-09-25 21:57 ` jakub at gcc dot gnu.org
                   ` (5 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: pinskia at gcc dot gnu.org @ 2012-09-25 18:04 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> 2012-09-25 18:04:00 UTC ---
(In reply to comment #4)
> Created attachment 28270 [details]
> gcc48-pr54703.patch

Since I wrote the code which breaks this, this looks good.  The only question I
have is why is AND allowed on non integer types anyways?


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

* [Bug target/54703] _mm_sub_pd is incorrectly substituted with vandnps
  2012-09-25 13:29 [Bug target/54703] New: [miscompilation] _mm_sub_pd is incorrectly substituted with vandnps kretz at kde dot org
                   ` (5 preceding siblings ...)
  2012-09-25 18:04 ` pinskia at gcc dot gnu.org
@ 2012-09-25 21:57 ` jakub at gcc dot gnu.org
  2012-09-26 10:53 ` kretz at kde dot org
                   ` (4 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu.org @ 2012-09-25 21:57 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #6 from Jakub Jelinek <jakub at gcc dot gnu.org> 2012-09-25 21:56:53 UTC ---
Yeah, the generic code is not buggy, it seems sane to assume AND is
integral/vector integer operation only, but I think i?86 isn't the only backend
that uses AND on vector floating point modes extensively.


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

* [Bug target/54703] _mm_sub_pd is incorrectly substituted with vandnps
  2012-09-25 13:29 [Bug target/54703] New: [miscompilation] _mm_sub_pd is incorrectly substituted with vandnps kretz at kde dot org
                   ` (6 preceding siblings ...)
  2012-09-25 21:57 ` jakub at gcc dot gnu.org
@ 2012-09-26 10:53 ` kretz at kde dot org
  2012-09-27 10:48 ` jakub at gcc dot gnu.org
                   ` (3 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: kretz at kde dot org @ 2012-09-26 10:53 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #7 from Matthias Kretz <kretz at kde dot org> 2012-09-26 10:52:38 UTC ---
Thanks for the quick response! You guys are cool! :)

The pattern here is for calculation with extended precision:

xh = x & mask;
xl = x - xh;
yh = y & mask
yl = y - yh;
/* x * y + small = */ xh * yh + ((xh * yl + xl * yh) + (xl * yl + small));

Other than that, yes there's a lot of ANDPS is SSE code, just this pattern
which gets miscompiled is not very common.


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

* [Bug target/54703] _mm_sub_pd is incorrectly substituted with vandnps
  2012-09-25 13:29 [Bug target/54703] New: [miscompilation] _mm_sub_pd is incorrectly substituted with vandnps kretz at kde dot org
                   ` (7 preceding siblings ...)
  2012-09-26 10:53 ` kretz at kde dot org
@ 2012-09-27 10:48 ` jakub at gcc dot gnu.org
  2012-09-27 10:54 ` jakub at gcc dot gnu.org
                   ` (2 subsequent siblings)
  11 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu.org @ 2012-09-27 10:48 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #8 from Jakub Jelinek <jakub at gcc dot gnu.org> 2012-09-27 10:48:14 UTC ---
Author: jakub
Date: Thu Sep 27 10:48:07 2012
New Revision: 191801

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=191801
Log:
    PR target/54703
    * simplify-rtx.c (simplify_binary_operation_1): Perform
    (x - (x & y)) -> (x & ~y) optimization only for integral
    modes.

    * gcc.target/i386/pr54703.c: New test.

Added:
    trunk/gcc/testsuite/gcc.target/i386/pr54703.c
Modified:
    trunk/gcc/ChangeLog
    trunk/gcc/simplify-rtx.c
    trunk/gcc/testsuite/ChangeLog


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

* [Bug target/54703] _mm_sub_pd is incorrectly substituted with vandnps
  2012-09-25 13:29 [Bug target/54703] New: [miscompilation] _mm_sub_pd is incorrectly substituted with vandnps kretz at kde dot org
                   ` (9 preceding siblings ...)
  2012-09-27 10:54 ` jakub at gcc dot gnu.org
@ 2012-09-27 10:54 ` jakub at gcc dot gnu.org
  2013-04-12 16:29 ` jakub at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu.org @ 2012-09-27 10:54 UTC (permalink / raw)
  To: gcc-bugs


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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|                            |4.7.3, 4.8.0
      Known to fail|4.8.0                       |

--- Comment #10 from Jakub Jelinek <jakub at gcc dot gnu.org> 2012-09-27 10:54:36 UTC ---
Fixed for 4.7.3+ so far.


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

* [Bug target/54703] _mm_sub_pd is incorrectly substituted with vandnps
  2012-09-25 13:29 [Bug target/54703] New: [miscompilation] _mm_sub_pd is incorrectly substituted with vandnps kretz at kde dot org
                   ` (8 preceding siblings ...)
  2012-09-27 10:48 ` jakub at gcc dot gnu.org
@ 2012-09-27 10:54 ` jakub at gcc dot gnu.org
  2012-09-27 10:54 ` jakub at gcc dot gnu.org
  2013-04-12 16:29 ` jakub at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu.org @ 2012-09-27 10:54 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #9 from Jakub Jelinek <jakub at gcc dot gnu.org> 2012-09-27 10:53:47 UTC ---
Author: jakub
Date: Thu Sep 27 10:53:42 2012
New Revision: 191802

URL: http://gcc.gnu.org/viewcvs?root=gcc&view=rev&rev=191802
Log:
    PR target/54703
    * simplify-rtx.c (simplify_binary_operation_1): Perform
    (x - (x & y)) -> (x & ~y) optimization only for integral
    modes.

    * gcc.target/i386/pr54703.c: New test.

Added:
    branches/gcc-4_7-branch/gcc/testsuite/gcc.target/i386/pr54703.c
Modified:
    branches/gcc-4_7-branch/gcc/ChangeLog
    branches/gcc-4_7-branch/gcc/simplify-rtx.c
    branches/gcc-4_7-branch/gcc/testsuite/ChangeLog


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

* [Bug target/54703] _mm_sub_pd is incorrectly substituted with vandnps
  2012-09-25 13:29 [Bug target/54703] New: [miscompilation] _mm_sub_pd is incorrectly substituted with vandnps kretz at kde dot org
                   ` (10 preceding siblings ...)
  2012-09-27 10:54 ` jakub at gcc dot gnu.org
@ 2013-04-12 16:29 ` jakub at gcc dot gnu.org
  11 siblings, 0 replies; 13+ messages in thread
From: jakub at gcc dot gnu.org @ 2013-04-12 16:29 UTC (permalink / raw)
  To: gcc-bugs


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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|ASSIGNED                    |RESOLVED
         Resolution|                            |FIXED
   Target Milestone|4.6.4                       |4.7.3

--- Comment #11 from Jakub Jelinek <jakub at gcc dot gnu.org> 2013-04-12 16:29:14 UTC ---
The 4.6 branch has been closed, fixed in GCC 4.7.3.


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

end of thread, other threads:[~2013-04-12 16:29 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-09-25 13:29 [Bug target/54703] New: [miscompilation] _mm_sub_pd is incorrectly substituted with vandnps kretz at kde dot org
2012-09-25 13:32 ` [Bug target/54703] " kretz at kde dot org
2012-09-25 13:48 ` [Bug target/54703] " rguenth at gcc dot gnu.org
2012-09-25 13:48 ` jakub at gcc dot gnu.org
2012-09-25 14:30 ` jakub at gcc dot gnu.org
2012-09-25 14:35 ` jakub at gcc dot gnu.org
2012-09-25 18:04 ` pinskia at gcc dot gnu.org
2012-09-25 21:57 ` jakub at gcc dot gnu.org
2012-09-26 10:53 ` kretz at kde dot org
2012-09-27 10:48 ` jakub at gcc dot gnu.org
2012-09-27 10:54 ` jakub at gcc dot gnu.org
2012-09-27 10:54 ` jakub at gcc dot gnu.org
2013-04-12 16:29 ` jakub 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).