public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/54978] New: Add ability to provide vectorized functions
@ 2012-10-18 17:51 ddesics at gmail dot com
  2012-10-19  8:46 ` [Bug tree-optimization/54978] " rguenth at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: ddesics at gmail dot com @ 2012-10-18 17:51 UTC (permalink / raw)
  To: gcc-bugs


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

             Bug #: 54978
           Summary: Add ability to provide vectorized functions
    Classification: Unclassified
           Product: gcc
           Version: unknown
            Status: UNCONFIRMED
          Severity: enhancement
          Priority: P3
         Component: tree-optimization
        AssignedTo: unassigned@gcc.gnu.org
        ReportedBy: ddesics@gmail.com


Presently, the auto-vectorizer chokes on any function calls present in a loop. 
It would be nice to be able to provide vectorized versions of functions, as
well as non-vectorized versions, and let the auto-vectorizer notice these.

This is already done for transcendental functions when -mveclibabi is used. 
However, to do this, some standardized form for the vectorized function would
have to be defined. 

For instance, assuming sse type functions with double precision as an example,
this could be done as follows.

C++: the simple case because overloading is available

double fx(double x);
v2df fx(v2df x);

C: this is more difficult, but something should be doable.  To prevent
accidental name overlap, a new function attribute could be used, to define a
vectorized version, i.e.: 

double fx(double x) __attribute__((vectorized_alias(fxv2df)));
v2df fxv2df(v2df x);


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

* [Bug tree-optimization/54978] Add ability to provide vectorized functions
  2012-10-18 17:51 [Bug tree-optimization/54978] New: Add ability to provide vectorized functions ddesics at gmail dot com
@ 2012-10-19  8:46 ` rguenth at gcc dot gnu.org
  2012-10-19 10:01 ` jakub at gcc dot gnu.org
                   ` (2 subsequent siblings)
  3 siblings, 0 replies; 5+ messages in thread
From: rguenth at gcc dot gnu.org @ 2012-10-19  8:46 UTC (permalink / raw)
  To: gcc-bugs


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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |NEW
   Last reconfirmed|                            |2012-10-19
     Ever Confirmed|0                           |1

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> 2012-10-19 08:45:27 UTC ---
Note that the Cilk+ people have something like this in mind (with an
'elemental' attribute).  The ABI (and thus the mangling) would be static,
thus C++ overloading would not work (but the vectorized function name
would be constructed similar to those of the intrinsics for -mveclibabi).
To adjust your example:

double fx (double) __attribute__((vector));

would tell GCC that a function named (for example) fx_v2df is available,
as well as a function named fx_v4df in case AVX is enabled (and a gazillion
more variants dependent on the target capabilities ...).

Another proposal was that GCC builds those variants itself as needed
(obviously only if it can see the function body).  This is what Cilk+
people designed:

double fx (double x) __attribute__((elemental))
{
  ...
}

would mean the function has to be necessarily 'const' (the return value
is only dependent on arguments, it does not read from memory or has
any side-effects) and the compiler can substitute all double types by
appropriate vector types.


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

* [Bug tree-optimization/54978] Add ability to provide vectorized functions
  2012-10-18 17:51 [Bug tree-optimization/54978] New: Add ability to provide vectorized functions ddesics at gmail dot com
  2012-10-19  8:46 ` [Bug tree-optimization/54978] " rguenth at gcc dot gnu.org
@ 2012-10-19 10:01 ` jakub at gcc dot gnu.org
  2012-10-19 16:14 ` ddesics at gmail dot com
  2021-08-16  4:44 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: jakub at gcc dot gnu.org @ 2012-10-19 10:01 UTC (permalink / raw)
  To: gcc-bugs


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

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

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

--- Comment #2 from Jakub Jelinek <jakub at gcc dot gnu.org> 2012-10-19 10:00:52 UTC ---
Why can't the elemental function be pure?  If it just reads some memory, the
vectorized version can use that memory value broadcasted to a vector.


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

* [Bug tree-optimization/54978] Add ability to provide vectorized functions
  2012-10-18 17:51 [Bug tree-optimization/54978] New: Add ability to provide vectorized functions ddesics at gmail dot com
  2012-10-19  8:46 ` [Bug tree-optimization/54978] " rguenth at gcc dot gnu.org
  2012-10-19 10:01 ` jakub at gcc dot gnu.org
@ 2012-10-19 16:14 ` ddesics at gmail dot com
  2021-08-16  4:44 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: ddesics at gmail dot com @ 2012-10-19 16:14 UTC (permalink / raw)
  To: gcc-bugs


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

--- Comment #3 from Daniel Davis <ddesics at gmail dot com> 2012-10-19 16:14:36 UTC ---
Obviously, it would be nice if gcc can build the functions if they are pure
functions.  But that would require somehow knowing that those functions should
be built and having access to the code, which may not be the case for something
like a library.  

On second thought, the attribute would best go with declaration of the
vectorized function.  So, to rewrite my example, 

double fx(double x); 
v2df fx_v2df(v2df x) __attribute__((vectorized_alias(fx,double,16))); 
v4df fx_v4df(v4df x) __attribute__((vectorized_alias(fx,double,32)));

That would let the compiler know exactly what could be replaced, although it
should be able to figure out the argument types from the declarations.

So I see two potential optimizations here.  The first is a way to let the
compiler know that vectorized functions are available.  The second would be to
let the auto-vectorizer create vectorized forms of functions.


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

* [Bug tree-optimization/54978] Add ability to provide vectorized functions
  2012-10-18 17:51 [Bug tree-optimization/54978] New: Add ability to provide vectorized functions ddesics at gmail dot com
                   ` (2 preceding siblings ...)
  2012-10-19 16:14 ` ddesics at gmail dot com
@ 2021-08-16  4:44 ` pinskia at gcc dot gnu.org
  3 siblings, 0 replies; 5+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-08-16  4:44 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
   Target Milestone|---                         |6.0
             Status|NEW                         |RESOLVED
         Resolution|---                         |FIXED

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Fixed in GCC 6 with r6-4931.

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

end of thread, other threads:[~2021-08-16  4:44 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2012-10-18 17:51 [Bug tree-optimization/54978] New: Add ability to provide vectorized functions ddesics at gmail dot com
2012-10-19  8:46 ` [Bug tree-optimization/54978] " rguenth at gcc dot gnu.org
2012-10-19 10:01 ` jakub at gcc dot gnu.org
2012-10-19 16:14 ` ddesics at gmail dot com
2021-08-16  4:44 ` 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).