public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/55213] New: vectorizer ignores __restrict__
@ 2012-11-05 11:51 vincenzo.innocente at cern dot ch
  2012-11-05 12:11 ` [Bug tree-optimization/55213] " jakub at gcc dot gnu.org
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: vincenzo.innocente at cern dot ch @ 2012-11-05 11:51 UTC (permalink / raw)
  To: gcc-bugs


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

             Bug #: 55213
           Summary: vectorizer ignores __restrict__
    Classification: Unclassified
           Product: gcc
           Version: 4.8.0
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: vincenzo.innocente@cern.ch


I raised this issue before, still I think that with vectorization becoming more
and more common aliasing starts to become an issue for both code-size and
speed.

for all the loops below the compiler emits alias checks.
My desire would be that foo produces optimal code (possibly with much less
__restrict__ in the code than what I used below), 
still even in the others functions __restrict__ is ignored

compiled as
c++ -Ofast -c soa.cc -std=gnu++11 -ftree-vectorizer-verbose=1 -Wall
-march=corei7
with gcc version 4.8.0 20121028 (experimental) [trunk revision 192889] (GCC) 

#include<cstdint>
struct Soa {

  uint32_t * mem;
  uint32_t ns;
  uint32_t cp;
  int const * __restrict__   i() const  __restrict__ { return (int const*
__restrict__)(mem);}
  float const * __restrict__ f() const  __restrict__ { return (float const*
__restrict__)(mem+cp);}
  float const * __restrict__ g() const  __restrict__ { return (float const*
__restrict__)(mem+2*cp);}

};


void foo(Soa const &  __restrict__  soa, float * __restrict__ res) {
  for(std::size_t i=0; i!=soa.ns; ++i)
    res[i] = soa.f()[i]+soa.g()[i];
}

void bar(Soa const & __restrict__ soa, float * __restrict__ res) {
  float const * __restrict__ f = soa.f(); float const * __restrict__ g =
soa.g();
  int n = soa.ns; for(int i=0; i!=n; ++i)
    res[i] = f[i]+g[i];
}


inline
void add(float const * __restrict__ f, float const * __restrict__ g,float *
__restrict__ res,int n) {
  for(int i=0; i!=n; ++i)
    res[i] = f[i]+g[i];
}

void add(Soa const & __restrict__ soa, float * __restrict__ res) {
   add(soa.f(),soa.g(),res,soa.ns);
}


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

* [Bug tree-optimization/55213] vectorizer ignores __restrict__
  2012-11-05 11:51 [Bug tree-optimization/55213] New: vectorizer ignores __restrict__ vincenzo.innocente at cern dot ch
@ 2012-11-05 12:11 ` jakub at gcc dot gnu.org
  2012-11-05 13:29 ` vincenzo.innocente at cern dot ch
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: jakub at gcc dot gnu.org @ 2012-11-05 12:11 UTC (permalink / raw)
  To: gcc-bugs


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

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

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

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> 2012-11-05 12:11:20 UTC ---
Please see PR49279.


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

* [Bug tree-optimization/55213] vectorizer ignores __restrict__
  2012-11-05 11:51 [Bug tree-optimization/55213] New: vectorizer ignores __restrict__ vincenzo.innocente at cern dot ch
  2012-11-05 12:11 ` [Bug tree-optimization/55213] " jakub at gcc dot gnu.org
@ 2012-11-05 13:29 ` vincenzo.innocente at cern dot ch
  2012-11-20 18:06 ` josh.m.conner at gmail dot com
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: vincenzo.innocente at cern dot ch @ 2012-11-05 13:29 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #2 from vincenzo Innocente <vincenzo.innocente at cern dot ch> 2012-11-05 13:28:51 UTC ---
reading PR49279 it seems to me  that gcc should NOT emit runtime alias checks,
Instead I see 
15: create runtime check for data references *_12 and *_9
15: create runtime check for data references *_14 and *_9
15: created 2 versioning for alias checks.

etc for all three loops.


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

* [Bug tree-optimization/55213] vectorizer ignores __restrict__
  2012-11-05 11:51 [Bug tree-optimization/55213] New: vectorizer ignores __restrict__ vincenzo.innocente at cern dot ch
  2012-11-05 12:11 ` [Bug tree-optimization/55213] " jakub at gcc dot gnu.org
  2012-11-05 13:29 ` vincenzo.innocente at cern dot ch
@ 2012-11-20 18:06 ` josh.m.conner at gmail dot com
  2012-11-29 22:18 ` josh.m.conner at gmail dot com
  2012-11-30  7:45 ` Joost.VandeVondele at mat dot ethz.ch
  4 siblings, 0 replies; 6+ messages in thread
From: josh.m.conner at gmail dot com @ 2012-11-20 18:06 UTC (permalink / raw)
  To: gcc-bugs


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

Joshua Conner <josh.m.conner at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |josh.m.conner at gmail dot
                   |                            |com

--- Comment #3 from Joshua Conner <josh.m.conner at gmail dot com> 2012-11-20 18:05:26 UTC ---
I'm running into a similar problem in code like this:

void
inner (float * restrict x, float * restrict y, int n)
{
  int i;

  for (i = 0; i < n; i++)
    x[i] *= y[i];
}

void
outer (float *arr, int offset, int bytes)
{
  inner (&arr[0], &arr[offset], bytes);
}

In the out-of-line instance of inner(), no alias detection code is generated
(correctly, since the pointers are restricted).

When inner() is inlined into outer(), however, alias detection code is
unnecessarily generated.  This alone isn't a terrible penalty except that the
generation of a versioned loop to handle aliasing prevents us from performing
loop peeling for alignment, and so we end up with a vectorized unaligned loop
with poor performance.

Note that the place where I'm actually running into the problem is in fortran,
where pointer arguments are implicitly non-aliasing.


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

* [Bug tree-optimization/55213] vectorizer ignores __restrict__
  2012-11-05 11:51 [Bug tree-optimization/55213] New: vectorizer ignores __restrict__ vincenzo.innocente at cern dot ch
                   ` (2 preceding siblings ...)
  2012-11-20 18:06 ` josh.m.conner at gmail dot com
@ 2012-11-29 22:18 ` josh.m.conner at gmail dot com
  2012-11-30  7:45 ` Joost.VandeVondele at mat dot ethz.ch
  4 siblings, 0 replies; 6+ messages in thread
From: josh.m.conner at gmail dot com @ 2012-11-29 22:18 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #4 from Joshua Conner <josh.m.conner at gmail dot com> 2012-11-29 22:17:50 UTC ---
I'm also seeing this same issue in libgfortran's matmul_r8.c, where the inner
loop has an aliasing check even though all of the pointer dereferences are via
restricted pointers.  Again, the problem is worse because the aliasing
versioning prevents us from doing vector alignment peeling.


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

* [Bug tree-optimization/55213] vectorizer ignores __restrict__
  2012-11-05 11:51 [Bug tree-optimization/55213] New: vectorizer ignores __restrict__ vincenzo.innocente at cern dot ch
                   ` (3 preceding siblings ...)
  2012-11-29 22:18 ` josh.m.conner at gmail dot com
@ 2012-11-30  7:45 ` Joost.VandeVondele at mat dot ethz.ch
  4 siblings, 0 replies; 6+ messages in thread
From: Joost.VandeVondele at mat dot ethz.ch @ 2012-11-30  7:45 UTC (permalink / raw)
  To: gcc-bugs


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

Joost VandeVondele <Joost.VandeVondele at mat dot ethz.ch> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |Joost.VandeVondele at mat
                   |                            |dot ethz.ch

--- Comment #5 from Joost VandeVondele <Joost.VandeVondele at mat dot ethz.ch> 2012-11-30 07:45:08 UTC ---
Something similar was reported in PR47341 which adds some analysis.


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

end of thread, other threads:[~2012-11-30  7:45 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-11-05 11:51 [Bug tree-optimization/55213] New: vectorizer ignores __restrict__ vincenzo.innocente at cern dot ch
2012-11-05 12:11 ` [Bug tree-optimization/55213] " jakub at gcc dot gnu.org
2012-11-05 13:29 ` vincenzo.innocente at cern dot ch
2012-11-20 18:06 ` josh.m.conner at gmail dot com
2012-11-29 22:18 ` josh.m.conner at gmail dot com
2012-11-30  7:45 ` Joost.VandeVondele at mat dot ethz.ch

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).