public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/40141]  New: accessing aliased __m128 miscompiles
@ 2009-05-14  9:40 kretz at kde dot org
  2009-05-14 11:04 ` [Bug middle-end/40141] [4.3 Regression] " rguenth at gcc dot gnu dot org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: kretz at kde dot org @ 2009-05-14  9:40 UTC (permalink / raw)
  To: gcc-bugs

Testcase:

#include <emmintrin.h>
#include <stdio.h>

typedef float floatA __attribute__((__may_alias__));

int main()
{
    __m128 x = _mm_setzero_ps();
    int i;
    for (i = 0; i < 4; ++i) {
        const float xx = ((floatA*)&x)[i];
        if (xx != 0.f) {
            printf("%d: %f\n", i, xx);
            return -1;
        }
    }
    return 0;
}

This fails with -O2, as well as with -O2 -fno-strict-aliasing. It works with
-O1 and -O0.

The generated assembly shows that the stack is created but not initialized and
then read from and checked whether it's 0.

If instead of
        const float xx = ((floatA*)&x)[i];
you write
        const float xx = ((floatA*)&x)[0];
(or any other constant between 0 and 3) then the testcase doesn't fail.

Tested versions:
4.2.4: doesn't fail
4.3.2: fails
4.3.3: fails
4.4.0: doesn't fail


-- 
           Summary: accessing aliased __m128 miscompiles
           Product: gcc
           Version: 4.3.3
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
        AssignedTo: unassigned at gcc dot gnu dot org
        ReportedBy: kretz at kde dot org
 GCC build triplet: x86_64-unknown-linux-gnu
  GCC host triplet: x86_64-unknown-linux-gnu
GCC target triplet: x86_64-unknown-linux-gnu


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


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

* [Bug middle-end/40141] [4.3 Regression] accessing aliased __m128 miscompiles
  2009-05-14  9:40 [Bug c/40141] New: accessing aliased __m128 miscompiles kretz at kde dot org
@ 2009-05-14 11:04 ` rguenth at gcc dot gnu dot org
  2009-05-14 14:50 ` rguenth at gcc dot gnu dot org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-05-14 11:04 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #1 from rguenth at gcc dot gnu dot org  2009-05-14 11:04 -------
Confirmed.  That's the SMTs do not include ref-all stuff bug so DCE removes
the initialization.

extern void abort (void);
typedef int __m128 __attribute__((vector_size(16), may_alias));
typedef float floatA __attribute__((may_alias));

int main()
{
  __m128 x = { 0, 0, 0, 0 };
  int i;
  for (i = 0; i < 4; ++i) {
      const float xx = ((floatA*)&x)[i];
      if (xx != 0.f)
        abort ();
  }
  return 0;
}

works without may_alias on __m128 for a strange reason.

I'll find the patch that fixed this.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         AssignedTo|unassigned at gcc dot gnu   |rguenth at gcc dot gnu dot
                   |dot org                     |org
             Status|UNCONFIRMED                 |ASSIGNED
          Component|c                           |middle-end
     Ever Confirmed|0                           |1
           Keywords|                            |alias, wrong-code
   Last reconfirmed|0000-00-00 00:00:00         |2009-05-14 11:04:20
               date|                            |
            Summary|accessing aliased __m128    |[4.3 Regression] accessing
                   |miscompiles                 |aliased __m128 miscompiles
   Target Milestone|---                         |4.3.4


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


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

* [Bug middle-end/40141] [4.3 Regression] accessing aliased __m128 miscompiles
  2009-05-14  9:40 [Bug c/40141] New: accessing aliased __m128 miscompiles kretz at kde dot org
  2009-05-14 11:04 ` [Bug middle-end/40141] [4.3 Regression] " rguenth at gcc dot gnu dot org
@ 2009-05-14 14:50 ` rguenth at gcc dot gnu dot org
  2009-05-15 11:09 ` rguenth at gcc dot gnu dot org
  2009-05-21 10:27 ` rguenth at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-05-14 14:50 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #2 from rguenth at gcc dot gnu dot org  2009-05-14 14:50 -------
For 4.4 this was fixed by

2008-04-29  Richard Guenther  <rguenther@suse.de>

        * tree-ssa-alias.c (finalize_ref_all_pointers): Remove.
        (compute_may_aliases): Do not call finalize_ref_all_pointers.
        (compute_flow_insensitive_aliasing): Do not treat
        PTR_IS_REF_ALL pointers special.
        (get_smt_for): Likewise.
        (may_alias_p): Re-structure.
        (is_escape_site): A ref-all pointer conversion is not an escape site.
        * tree-ssa-structalias.c (find_what_p_points_to): Do not treat
        PTR_IS_REF_ALL pointers special.
        * tree-ssa-structalias.h (struct alias_info): Remove
        ref_all_symbol_mem_tag field.
        (PTR_IS_REF_ALL): Remove.

eventually exposing PRs 38151 and 38246.  Which were fixed by

2008-11-25  Richard Guenther  <rguenther@suse.de>

        PR middle-end/38151
        PR middle-end/38236
        * tree-ssa-alias.c (struct alias_info): Remove written_vars.
        Remove dereferenced_ptrs_store and dereferenced_ptrs_load
        in favor of dereferenced_ptrs.
        (init_alias_info): Adjust.
        (delete_alias_info): Likewise.
        (compute_flow_insensitive_aliasing): Properly
        include all aliased variables.
        (update_alias_info_1): Use dereferenced_ptrs.
        (setup_pointers_and_addressables): Likewise.
        (get_smt_for): Honor ref-all pointers and pointers with known alias
        set properly.
        * config/i386/i386.c (ix86_gimplify_va_arg): Use ref-all pointers.


-- 


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


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

* [Bug middle-end/40141] [4.3 Regression] accessing aliased __m128 miscompiles
  2009-05-14  9:40 [Bug c/40141] New: accessing aliased __m128 miscompiles kretz at kde dot org
  2009-05-14 11:04 ` [Bug middle-end/40141] [4.3 Regression] " rguenth at gcc dot gnu dot org
  2009-05-14 14:50 ` rguenth at gcc dot gnu dot org
@ 2009-05-15 11:09 ` rguenth at gcc dot gnu dot org
  2009-05-21 10:27 ` rguenth at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-05-15 11:09 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #3 from rguenth at gcc dot gnu dot org  2009-05-15 11:09 -------
Created an attachment (id=17873)
 --> (http://gcc.gnu.org/bugzilla/attachment.cgi?id=17873&action=view)
patch

This is a patch backporting the fix and followups necessary to fix the fallout
(and the new testcases).


-- 


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


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

* [Bug middle-end/40141] [4.3 Regression] accessing aliased __m128 miscompiles
  2009-05-14  9:40 [Bug c/40141] New: accessing aliased __m128 miscompiles kretz at kde dot org
                   ` (2 preceding siblings ...)
  2009-05-15 11:09 ` rguenth at gcc dot gnu dot org
@ 2009-05-21 10:27 ` rguenth at gcc dot gnu dot org
  3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu dot org @ 2009-05-21 10:27 UTC (permalink / raw)
  To: gcc-bugs



------- Comment #4 from rguenth at gcc dot gnu dot org  2009-05-21 10:27 -------
Patch was posted and rejected as too invasive for 4.3.  Distributors can apply
the referenced patch.

Thus, WONTFIX for 4.3, fixed for 4.4.


-- 

rguenth at gcc dot gnu dot org changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                URL|                            |http://gcc.gnu.org/ml/gcc-
                   |                            |patches/2009-
                   |                            |05/msg00925.html
             Status|ASSIGNED                    |RESOLVED
      Known to fail|                            |4.3.3
      Known to work|                            |4.4.0
         Resolution|                            |FIXED
   Target Milestone|4.3.4                       |4.4.0


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


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

end of thread, other threads:[~2009-05-21 10:27 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2009-05-14  9:40 [Bug c/40141] New: accessing aliased __m128 miscompiles kretz at kde dot org
2009-05-14 11:04 ` [Bug middle-end/40141] [4.3 Regression] " rguenth at gcc dot gnu dot org
2009-05-14 14:50 ` rguenth at gcc dot gnu dot org
2009-05-15 11:09 ` rguenth at gcc dot gnu dot org
2009-05-21 10:27 ` rguenth at gcc dot gnu dot 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).