public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/98774] New: gcc -O3 does not vectorize multiplication
@ 2021-01-20 22:13 vanyacpp at gmail dot com
  2021-01-21  2:36 ` [Bug tree-optimization/98774] gcc -O3 does not vectorize some operations crazylht at gmail dot com
                   ` (4 more replies)
  0 siblings, 5 replies; 6+ messages in thread
From: vanyacpp at gmail dot com @ 2021-01-20 22:13 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 98774
           Summary: gcc -O3 does not vectorize multiplication
           Product: gcc
           Version: 10.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vanyacpp at gmail dot com
  Target Milestone: ---

Created attachment 50014
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=50014&action=edit
nbody-update-velocity.cpp

In the following sample GCC (-O3 -ffast-math) fails to vectorize operations.
The results is that GCC 10.2 does 8 mulsd, while clang 11.0 does 4 mulpd.

struct vec3 { double x, y, z; };

void update_velocities(vec3* __restrict velocity,
                       double const* __restrict mass,
                       vec3 const* __restrict dpos,
                       double const* __restrict mag)
{
    velocity[0] -= dpos[0] * (mass[1] * mag[0]);
    velocity[1] += dpos[0] * (mass[0] * mag[0]);
}

See an attachment for the complete sample.

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

* [Bug tree-optimization/98774] gcc -O3 does not vectorize some operations
  2021-01-20 22:13 [Bug tree-optimization/98774] New: gcc -O3 does not vectorize multiplication vanyacpp at gmail dot com
@ 2021-01-21  2:36 ` crazylht at gmail dot com
  2021-01-21  7:54 ` rguenth at gcc dot gnu.org
                   ` (3 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: crazylht at gmail dot com @ 2021-01-21  2:36 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Hongtao.liu <crazylht at gmail dot com> ---
It's fixed in current trunk https://godbolt.org/z/63576n

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

* [Bug tree-optimization/98774] gcc -O3 does not vectorize some operations
  2021-01-20 22:13 [Bug tree-optimization/98774] New: gcc -O3 does not vectorize multiplication vanyacpp at gmail dot com
  2021-01-21  2:36 ` [Bug tree-optimization/98774] gcc -O3 does not vectorize some operations crazylht at gmail dot com
@ 2021-01-21  7:54 ` rguenth at gcc dot gnu.org
  2021-01-27 10:24 ` vanyacpp at gmail dot com
                   ` (2 subsequent siblings)
  4 siblings, 0 replies; 6+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-01-21  7:54 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |missed-optimization
   Last reconfirmed|                            |2021-01-21
             Status|UNCONFIRMED                 |NEW
             Blocks|                            |53947
     Ever confirmed|0                           |1

--- Comment #2 from Richard Biener <rguenth at gcc dot gnu.org> ---
There's

t.ii:21:9: note:   ==> examining statement: a$x_1 = *dpos_10(D).x;
t.ii:21:9: missed:   BB vectorization with gaps at the end of a load is not
supported
t.ii:27:6: missed:   not vectorized: relevant stmt not supported: a$x_1 =
*dpos_10(D).x;
t.ii:21:9: note:   Building vector operands of 0x4047278 from scalars instead

which we eventually can improve.  With AVX2 we split into one AVX and one SSE
part and then run into a duplicate PR where we end up with conflicting
vector types for a load which we do not yet support.  We then end up with
only vectorizing the AVX part.


Referenced Bugs:

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=53947
[Bug 53947] [meta-bug] vectorizer missed-optimizations

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

* [Bug tree-optimization/98774] gcc -O3 does not vectorize some operations
  2021-01-20 22:13 [Bug tree-optimization/98774] New: gcc -O3 does not vectorize multiplication vanyacpp at gmail dot com
  2021-01-21  2:36 ` [Bug tree-optimization/98774] gcc -O3 does not vectorize some operations crazylht at gmail dot com
  2021-01-21  7:54 ` rguenth at gcc dot gnu.org
@ 2021-01-27 10:24 ` vanyacpp at gmail dot com
  2021-09-14 18:21 ` vanyacpp at gmail dot com
  2021-09-14 18:28 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: vanyacpp at gmail dot com @ 2021-01-27 10:24 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Ivan Sorokin <vanyacpp at gmail dot com> ---
(In reply to Hongtao.liu from comment #1)
> It's fixed in current trunk https://godbolt.org/z/63576n

I can confirm that now GCC does use packed multiplication mulpd. Although it is
used somewhat inefficiently. The original program contained 8 multiplications
and clang does 4 packed multiplication. GCC trunk does 6 packed
multiplications.

https://godbolt.org/z/EabPxT

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

* [Bug tree-optimization/98774] gcc -O3 does not vectorize some operations
  2021-01-20 22:13 [Bug tree-optimization/98774] New: gcc -O3 does not vectorize multiplication vanyacpp at gmail dot com
                   ` (2 preceding siblings ...)
  2021-01-27 10:24 ` vanyacpp at gmail dot com
@ 2021-09-14 18:21 ` vanyacpp at gmail dot com
  2021-09-14 18:28 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: vanyacpp at gmail dot com @ 2021-09-14 18:21 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #4 from Ivan Sorokin <vanyacpp at gmail dot com> ---
I retested the sample on GCC 11.2.

https://godbolt.org/z/xrarP3zbY

Compared to Clang 12.0.1 GCC still generates 6 more instructions in total and
does 6 mulpd against Clang's 4 mulpd.

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

* [Bug tree-optimization/98774] gcc -O3 does not vectorize some operations
  2021-01-20 22:13 [Bug tree-optimization/98774] New: gcc -O3 does not vectorize multiplication vanyacpp at gmail dot com
                   ` (3 preceding siblings ...)
  2021-09-14 18:21 ` vanyacpp at gmail dot com
@ 2021-09-14 18:28 ` pinskia at gcc dot gnu.org
  4 siblings, 0 replies; 6+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-09-14 18:28 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
For the trunk (without -ffast-math), the perms are done too early:
  vect__5.32_53 = VEC_PERM_EXPR <vect__2.31_52, vect__2.31_52, { 1, 1 }>;
  vect__5.33_54 = VEC_PERM_EXPR <vect__2.31_52, vect__2.31_52, { 1, 0 }>;
  vect__5.34_55 = VEC_PERM_EXPR <vect__2.31_52, vect__2.31_52, { 0, 0 }>;
  _3 = *mag_9(D);
  _58 = {_3, _3};
  vect__4.35_59 = vect__5.32_53 * _58;
  vect__4.35_60 = vect__5.33_54 * _58;
  vect__4.35_61 = vect__5.34_55 * _58;

With -ffast-math:
  a$x_1 = *dpos_10(D).x;
  a$y_11 = *dpos_10(D).y;
  _49 = {a$x_1, a$y_11};
  _35 = _49 * _58;
And the PERM is done too early the same way ..

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

end of thread, other threads:[~2021-09-14 18:28 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-01-20 22:13 [Bug tree-optimization/98774] New: gcc -O3 does not vectorize multiplication vanyacpp at gmail dot com
2021-01-21  2:36 ` [Bug tree-optimization/98774] gcc -O3 does not vectorize some operations crazylht at gmail dot com
2021-01-21  7:54 ` rguenth at gcc dot gnu.org
2021-01-27 10:24 ` vanyacpp at gmail dot com
2021-09-14 18:21 ` vanyacpp at gmail dot com
2021-09-14 18:28 ` 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).