public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/47825] New: SSE bitwise operations on floats work -g, fail -O3
@ 2011-02-20 17:03 cck0011 at yahoo dot com
  2011-02-20 17:36 ` [Bug c/47825] " rguenth at gcc dot gnu.org
                   ` (7 more replies)
  0 siblings, 8 replies; 9+ messages in thread
From: cck0011 at yahoo dot com @ 2011-02-20 17:03 UTC (permalink / raw)
  To: gcc-bugs

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

           Summary: SSE bitwise operations on floats work -g, fail -O3
           Product: gcc
           Version: 4.3.2
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: cck0011@yahoo.com


Created attachment 23413
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=23413
.i file

Hi folks,

  I'm trying the vec_sel() example using SSE (bitwise and, or, andnot) to
select bits from two vectors to build a third. It works under -g, but fails
under -O3.
What am I missing?

thanks.


gcc -v
Using built-in specs.
Target: i386-redhat-linux
Configured with: ../configure --prefix=/usr --mandir=/usr/share/man
--infodir=/usr/share/info --with-bugurl=http://bugzilla.redhat.com/bugzilla
--enable-bootstrap --enable-shared --enable-threads=posix
--enable-checking=release --with-system-zlib --enable-__cxa_atexit
--disable-libunwind-exceptions
--enable-languages=c,c++,objc,obj-c++,java,fortran,ada --enable-java-awt=gtk
--disable-dssi --enable-plugin
--with-java-home=/usr/lib/jvm/java-1.5.0-gcj-1.5.0.0/jre
--enable-libgcj-multifile --enable-java-maintainer-mode
--with-ecj-jar=/usr/share/java/eclipse-ecj.jar --disable-libjava-multilib
--with-cpu=generic --build=i386-redhat-linux
Thread model: posix
gcc version 4.3.2 20081105 (Red Hat 4.3.2-7) (GCC)

works under:
  cc -g -o setel setel.c  -msse -mmmx -pedantic -Wall

fails under:
  cc -O3 -o setel setel.c  -msse -mmmx -pedantic -Wall


.i file attached


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

* [Bug c/47825] SSE bitwise operations on floats work -g, fail -O3
  2011-02-20 17:03 [Bug c/47825] New: SSE bitwise operations on floats work -g, fail -O3 cck0011 at yahoo dot com
@ 2011-02-20 17:36 ` rguenth at gcc dot gnu.org
  2011-02-20 17:42 ` cck0011 at yahoo dot com
                   ` (6 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-02-20 17:36 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |RESOLVED
         Resolution|                            |INVALID

--- Comment #1 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-02-20 17:22:58 UTC ---
You are violating aliasing rules.  Add may_alias to the attributes of your
float array.


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

* [Bug c/47825] SSE bitwise operations on floats work -g, fail -O3
  2011-02-20 17:03 [Bug c/47825] New: SSE bitwise operations on floats work -g, fail -O3 cck0011 at yahoo dot com
  2011-02-20 17:36 ` [Bug c/47825] " rguenth at gcc dot gnu.org
@ 2011-02-20 17:42 ` cck0011 at yahoo dot com
  2011-02-20 18:08 ` rguenth at gcc dot gnu.org
                   ` (5 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: cck0011 at yahoo dot com @ 2011-02-20 17:42 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from cck0011 at yahoo dot com 2011-02-20 17:35:56 UTC ---
Created attachment 23414
  --> http://gcc.gnu.org/bugzilla/attachment.cgi?id=23414
source file with _may_alias_ attribute added

Hi Richard,

  thanks for replying. I added _may_alias_; no change in results.

  What am I missing?

  Source attached.

Thanks!


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

* [Bug c/47825] SSE bitwise operations on floats work -g, fail -O3
  2011-02-20 17:03 [Bug c/47825] New: SSE bitwise operations on floats work -g, fail -O3 cck0011 at yahoo dot com
  2011-02-20 17:36 ` [Bug c/47825] " rguenth at gcc dot gnu.org
  2011-02-20 17:42 ` cck0011 at yahoo dot com
@ 2011-02-20 18:08 ` rguenth at gcc dot gnu.org
  2011-02-20 18:57 ` cck0011 at yahoo dot com
                   ` (4 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-02-20 18:08 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-02-20 17:42:41 UTC ---
Probably the same on maskarray.  You should also try to update GCC to
4.3.5.


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

* [Bug c/47825] SSE bitwise operations on floats work -g, fail -O3
  2011-02-20 17:03 [Bug c/47825] New: SSE bitwise operations on floats work -g, fail -O3 cck0011 at yahoo dot com
                   ` (2 preceding siblings ...)
  2011-02-20 18:08 ` rguenth at gcc dot gnu.org
@ 2011-02-20 18:57 ` cck0011 at yahoo dot com
  2011-02-21 10:44 ` [Bug target/47825] " rguenth at gcc dot gnu.org
                   ` (3 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: cck0011 at yahoo dot com @ 2011-02-20 18:57 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from cck0011 at yahoo dot com 2011-02-20 18:22:46 UTC ---
(In reply to comment #3)
> Probably the same on maskarray.  You should also try to update GCC to
> 4.3.5.

Hi Richard,

  added to maskarray as well: no change in results. Adding option
-fno-strict-aliasing fixes it as well. I'm confused: since _mm_store_ps
explicitly copies into floatarray why is aliasing an issue?

thanks!


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

* [Bug target/47825] SSE bitwise operations on floats work -g, fail -O3
  2011-02-20 17:03 [Bug c/47825] New: SSE bitwise operations on floats work -g, fail -O3 cck0011 at yahoo dot com
                   ` (3 preceding siblings ...)
  2011-02-20 18:57 ` cck0011 at yahoo dot com
@ 2011-02-21 10:44 ` rguenth at gcc dot gnu.org
  2011-02-21 14:26 ` hjl.tools at gmail dot com
                   ` (2 subsequent siblings)
  7 siblings, 0 replies; 9+ messages in thread
From: rguenth at gcc dot gnu.org @ 2011-02-21 10:44 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Target|                            |x86_64-*-*
             Status|RESOLVED                    |REOPENED
   Last reconfirmed|                            |2011.02.21 10:40:58
                 CC|                            |hjl at gcc dot gnu.org
          Component|c                           |target
         Resolution|INVALID                     |
     Ever Confirmed|0                           |1

--- Comment #5 from Richard Guenther <rguenth at gcc dot gnu.org> 2011-02-21 10:40:58 UTC ---
The issue is that maskarray is initialized as array of ints but then you
load it as array of floats, the scheduler re-orders those so you see
a load from uninitialized stack:

test_setelement:
.LFB546:
        subq    $40, %rsp
.LCFI0:
        movaps  16(%rsp), %xmm0
        movl    $0, 16(%rsp)
        movl    $0, 20(%rsp)
        movaps  %xmm0, %xmm1
        andnps  .LC1(%rip), %xmm0
        movl    $0, 24(%rsp)
        movl    $-1, 28(%rsp)
...

what is a bit inconsistent is that for mm_load_pd we use a type that
allows aliasing:

/* The Intel API is flexible enough that we must allow aliasing with other
   vector types, and their scalar components.  */
typedef long long __m128i __attribute__ ((__vector_size__ (16),
__may_alias__));
typedef double __m128d __attribute__ ((__vector_size__ (16), __may_alias__));

...

/* Load two DPFP values from P.  The address must be 16-byte aligned.  */
extern __inline __m128d __attribute__((__gnu_inline__, __always_inline__,
__artificial__))
_mm_load_pd (double const *__P)
{
  return *(__m128d *)__P;
}

but for mm_load_ps we don't:

/* Internal data types for implementing the intrinsics.  */
typedef float __v4sf __attribute__ ((__vector_size__ (16)));

...

/* Load four SPFP values from P.  The address must be 16-byte aligned.  */
extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__,
__artificial__))
_mm_load_ps (float const *__P)
{
  return (__m128) *(__v4sf *)__P;
}


re-opening to investigate that.  HJ, are the SSE1 intrinsics not
aliasing in the Intel API?  The above snippets are from trunk.


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

* [Bug target/47825] SSE bitwise operations on floats work -g, fail -O3
  2011-02-20 17:03 [Bug c/47825] New: SSE bitwise operations on floats work -g, fail -O3 cck0011 at yahoo dot com
                   ` (4 preceding siblings ...)
  2011-02-21 10:44 ` [Bug target/47825] " rguenth at gcc dot gnu.org
@ 2011-02-21 14:26 ` hjl.tools at gmail dot com
  2011-02-22  1:53 ` cck0011 at yahoo dot com
  2021-08-13 23:23 ` pinskia at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: hjl.tools at gmail dot com @ 2011-02-21 14:26 UTC (permalink / raw)
  To: gcc-bugs

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

H.J. Lu <hjl.tools at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|hjl at gcc dot gnu.org      |hjl.tools at gmail dot com,
                   |                            |ubizjak at gmail dot com

--- Comment #6 from H.J. Lu <hjl.tools at gmail dot com> 2011-02-21 13:53:02 UTC ---
(In reply to comment #5)

> /* Load four SPFP values from P.  The address must be 16-byte aligned.  */
> extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__,
> __artificial__))
> _mm_load_ps (float const *__P)
> {
>   return (__m128) *(__v4sf *)__P;
> }
> 
> 
> re-opening to investigate that.  HJ, are the SSE1 intrinsics not
> aliasing in the Intel API?  The above snippets are from trunk.

It is a bug and should be fixed.


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

* [Bug target/47825] SSE bitwise operations on floats work -g, fail -O3
  2011-02-20 17:03 [Bug c/47825] New: SSE bitwise operations on floats work -g, fail -O3 cck0011 at yahoo dot com
                   ` (5 preceding siblings ...)
  2011-02-21 14:26 ` hjl.tools at gmail dot com
@ 2011-02-22  1:53 ` cck0011 at yahoo dot com
  2021-08-13 23:23 ` pinskia at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: cck0011 at yahoo dot com @ 2011-02-22  1:53 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #7 from cck0011 at yahoo dot com 2011-02-22 00:54:17 UTC ---
(In reply to comment #5)
> The issue is that maskarray is initialized as array of ints but then you
> load it as array of floats, the scheduler re-orders those so you see
> a load from uninitialized stack:
> 
[looks puzzled; reads info page for gcc -fstrict-aliasing for the N + 1th time;
sudden look of comprehension dawns...]

"taking a pointer and casting gives undefined result..."

 Thank you Richard. That makes sense now given the context... -)

Thanks folks!


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

* [Bug target/47825] SSE bitwise operations on floats work -g, fail -O3
  2011-02-20 17:03 [Bug c/47825] New: SSE bitwise operations on floats work -g, fail -O3 cck0011 at yahoo dot com
                   ` (6 preceding siblings ...)
  2011-02-22  1:53 ` cck0011 at yahoo dot com
@ 2021-08-13 23:23 ` pinskia at gcc dot gnu.org
  7 siblings, 0 replies; 9+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-13 23:23 UTC (permalink / raw)
  To: gcc-bugs

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

Andrew Pinski <pinskia at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |FIXED
   Target Milestone|---                         |7.0
             Status|REOPENED                    |RESOLVED

--- Comment #8 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Fixed for GCC 7+ by r7-2885.
@@ -921,14 +924,14 @@ _mm_load_ps1 (float const *__P)
 extern __inline __m128 __attribute__((__gnu_inline__, __always_inline__,
__artificial__))
 _mm_load_ps (float const *__P)
 {
-  return (__m128) *(__v4sf *)__P;
+  return *(__m128 *)__P;
 }

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

end of thread, other threads:[~2021-08-13 23:23 UTC | newest]

Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2011-02-20 17:03 [Bug c/47825] New: SSE bitwise operations on floats work -g, fail -O3 cck0011 at yahoo dot com
2011-02-20 17:36 ` [Bug c/47825] " rguenth at gcc dot gnu.org
2011-02-20 17:42 ` cck0011 at yahoo dot com
2011-02-20 18:08 ` rguenth at gcc dot gnu.org
2011-02-20 18:57 ` cck0011 at yahoo dot com
2011-02-21 10:44 ` [Bug target/47825] " rguenth at gcc dot gnu.org
2011-02-21 14:26 ` hjl.tools at gmail dot com
2011-02-22  1:53 ` cck0011 at yahoo dot com
2021-08-13 23:23 ` pinskia 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).