public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/108677] New: wrong vectorization (when copy constructor is present?)
@ 2023-02-05 14:38 vincenzo.innocente at cern dot ch
  2023-02-05 19:26 ` [Bug tree-optimization/108677] " pinskia at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: vincenzo.innocente at cern dot ch @ 2023-02-05 14:38 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 108677
           Summary: wrong vectorization (when copy constructor is
                    present?)
           Product: gcc
           Version: 12.2.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: vincenzo.innocente at cern dot ch
  Target Milestone: ---

in this real life code

#include<cmath>

struct trig_pair {
   double CosPhi;
   double SinPhi;

   trig_pair() : CosPhi(1.), SinPhi(0.) {}
   trig_pair(const trig_pair &tp) : CosPhi(tp.CosPhi), SinPhi(tp.SinPhi) {}
   trig_pair(const double C, const double S) : CosPhi(C), SinPhi(S) {}
   trig_pair(const double phi) : CosPhi(cos(phi)), SinPhi(sin(phi)) {}

   //Return trig_pair fo angle increased by angle of tp.
   trig_pair Add(const trig_pair &tp) {
      return trig_pair(this->CosPhi*tp.CosPhi - this->SinPhi*tp.SinPhi,
                       this->SinPhi*tp.CosPhi + this->CosPhi*tp.SinPhi);
   }
};

trig_pair *TrigArr;

void FillTrigArr(trig_pair tp, unsigned MaxM)
{
//Fill TrigArr with trig_pair(jp*phi)
   if (!TrigArr) return;;
   TrigArr[1] = tp;
   for (unsigned jp = 2; jp <= MaxM; ++jp) TrigArr[jp] = TrigArr[jp-1].Add(tp);
}


gcc vectorize the loop even if a dependency is present...[1]
It will not if I comment out the copy contructor...[2]


[1]
https://godbolt.org/z/vhPeh35n5

[2]
https://godbolt.org/z/YPjdYdqG8

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

* [Bug tree-optimization/108677] wrong vectorization (when copy constructor is present?)
  2023-02-05 14:38 [Bug tree-optimization/108677] New: wrong vectorization (when copy constructor is present?) vincenzo.innocente at cern dot ch
@ 2023-02-05 19:26 ` pinskia at gcc dot gnu.org
  2023-02-05 19:37 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-02-05 19:26 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|wrong-code                  |missed-optimization

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
>gcc vectorize the loop even if a dependency is present...[1]

What dependency? TrigArr cannot point to tp.

Also it is just doing just doing SLP, the vectorization is fine here even.
It is only doing basic block form.


IR:

  _2 = jp_31 + 4294967295;
  _3 = (long unsigned int) _2;
  _4 = _3 * 16;
  _5 = TrigArr.0_1 + _4;
  vect__22.19_48 = MEM <vector(2) double> [(double *)_5];
  vect__22.23_43 = VEC_PERM_EXPR <vect__22.19_48, vect__22.19_48, { 1, 0 }>;
  vect__20.15_54 = MEM <const vector(2) double> [(double *)tp_14(D)];
  vect__20.16_53 = VEC_PERM_EXPR <vect__20.15_54, vect__20.15_54, { 0, 0 }>;
  vect__20.27_38 = VEC_PERM_EXPR <vect__20.15_54, vect__20.15_54, { 1, 1 }>;
  vect__27.28_37 = vect__20.27_38 * vect__22.23_43;
  vect__57.29_36 = .VEC_FMADDSUB (vect__20.16_53, vect__22.19_48,
vect__27.28_37);
  _7 = (long unsigned int) jp_31;
  _8 = _7 * 16;
  _9 = TrigArr.0_1 + _8;
  MEM <vector(2) double> [(double *)_9] = vect__57.29_36;

_5 is &TrigArr[jp-1], _9 is &TrigArr[jp]

This looks fine to me.

As not doing SLP without the copy constructor, it seems like the IR changes and
forced the load from tp_14 outside of the loop which caused SLP not do to the
load there ...

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

* [Bug tree-optimization/108677] wrong vectorization (when copy constructor is present?)
  2023-02-05 14:38 [Bug tree-optimization/108677] New: wrong vectorization (when copy constructor is present?) vincenzo.innocente at cern dot ch
  2023-02-05 19:26 ` [Bug tree-optimization/108677] " pinskia at gcc dot gnu.org
@ 2023-02-05 19:37 ` pinskia at gcc dot gnu.org
  2023-02-06  7:53 ` rguenth at gcc dot gnu.org
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-02-05 19:37 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Is the confusing part is the fmaddsub instruction?

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

* [Bug tree-optimization/108677] wrong vectorization (when copy constructor is present?)
  2023-02-05 14:38 [Bug tree-optimization/108677] New: wrong vectorization (when copy constructor is present?) vincenzo.innocente at cern dot ch
  2023-02-05 19:26 ` [Bug tree-optimization/108677] " pinskia at gcc dot gnu.org
  2023-02-05 19:37 ` pinskia at gcc dot gnu.org
@ 2023-02-06  7:53 ` rguenth at gcc dot gnu.org
  2023-02-06  8:55 ` vincenzo.innocente at cern dot ch
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-02-06  7:53 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|UNCONFIRMED                 |WAITING
     Ever confirmed|0                           |1
                 CC|                            |rguenth at gcc dot gnu.org
   Last reconfirmed|                            |2023-02-06

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

* [Bug tree-optimization/108677] wrong vectorization (when copy constructor is present?)
  2023-02-05 14:38 [Bug tree-optimization/108677] New: wrong vectorization (when copy constructor is present?) vincenzo.innocente at cern dot ch
                   ` (2 preceding siblings ...)
  2023-02-06  7:53 ` rguenth at gcc dot gnu.org
@ 2023-02-06  8:55 ` vincenzo.innocente at cern dot ch
  2023-02-06  9:48 ` [Bug tree-optimization/108677] no vectorization when copy constructor is present rguenth at gcc dot gnu.org
  2023-02-06 21:48 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: vincenzo.innocente at cern dot ch @ 2023-02-06  8:55 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from vincenzo Innocente <vincenzo.innocente at cern dot ch> ---
sorry. the original internal bug report was for gcc 7.5
https://godbolt.org/z/9crafbqen

where I think the generated code is indeed wrong (and does not depend on the
presence of the constructor!)

SO, if anything the bug should be changed in: removing constructor inhibit SLP
vectorization?

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

* [Bug tree-optimization/108677] no vectorization when copy constructor is present
  2023-02-05 14:38 [Bug tree-optimization/108677] New: wrong vectorization (when copy constructor is present?) vincenzo.innocente at cern dot ch
                   ` (3 preceding siblings ...)
  2023-02-06  8:55 ` vincenzo.innocente at cern dot ch
@ 2023-02-06  9:48 ` rguenth at gcc dot gnu.org
  2023-02-06 21:48 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2023-02-06  9:48 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|wrong vectorization (when   |no vectorization when copy
                   |copy constructor is         |constructor is present
                   |present?)                   |
             Status|WAITING                     |NEW

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

* [Bug tree-optimization/108677] no vectorization when copy constructor is present
  2023-02-05 14:38 [Bug tree-optimization/108677] New: wrong vectorization (when copy constructor is present?) vincenzo.innocente at cern dot ch
                   ` (4 preceding siblings ...)
  2023-02-06  9:48 ` [Bug tree-optimization/108677] no vectorization when copy constructor is present rguenth at gcc dot gnu.org
@ 2023-02-06 21:48 ` pinskia at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2023-02-06 21:48 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           See Also|                            |https://gcc.gnu.org/bugzill
                   |                            |a/show_bug.cgi?id=85586

--- Comment #4 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
The wrong code could have been PR 85586.

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

end of thread, other threads:[~2023-02-06 21:48 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-02-05 14:38 [Bug tree-optimization/108677] New: wrong vectorization (when copy constructor is present?) vincenzo.innocente at cern dot ch
2023-02-05 19:26 ` [Bug tree-optimization/108677] " pinskia at gcc dot gnu.org
2023-02-05 19:37 ` pinskia at gcc dot gnu.org
2023-02-06  7:53 ` rguenth at gcc dot gnu.org
2023-02-06  8:55 ` vincenzo.innocente at cern dot ch
2023-02-06  9:48 ` [Bug tree-optimization/108677] no vectorization when copy constructor is present rguenth at gcc dot gnu.org
2023-02-06 21:48 ` 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).