public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/105781] New: GCC does not unroll auto-vectorized loops.
@ 2022-05-30 22:37 denis.yaroshevskij at gmail dot com
  2022-05-30 22:42 ` [Bug middle-end/105781] " pinskia at gcc dot gnu.org
                   ` (5 more replies)
  0 siblings, 6 replies; 7+ messages in thread
From: denis.yaroshevskij at gmail dot com @ 2022-05-30 22:37 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 105781
           Summary: GCC does not unroll auto-vectorized loops.
           Product: gcc
           Version: 13.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: denis.yaroshevskij at gmail dot com
  Target Milestone: ---

Even when vectorizing very simple loops, gcc uses unroll factor of 1.
Clang unrolls 8, for context.

Example: 

void double_elements(int* f, int* l, int v) {
    while (f != l) {
        *f = *f + *f;
        ++f;
    }
}


https://godbolt.org/z/hTx84essY

In many measurements unrolling such code by a factor of 4 is beneficial.

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

* [Bug middle-end/105781] GCC does not unroll auto-vectorized loops.
  2022-05-30 22:37 [Bug c++/105781] New: GCC does not unroll auto-vectorized loops denis.yaroshevskij at gmail dot com
@ 2022-05-30 22:42 ` pinskia at gcc dot gnu.org
  2022-05-30 23:27 ` pinskia at gcc dot gnu.org
                   ` (4 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-05-30 22:42 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|c++                         |middle-end
           Keywords|                            |missed-optimization

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Unrolling happens with -funroll-loops really. Gcc does some unrolling by
default at -O2 and some more at -O3 but you need the extra flag to get the most
really.

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

* [Bug middle-end/105781] GCC does not unroll auto-vectorized loops.
  2022-05-30 22:37 [Bug c++/105781] New: GCC does not unroll auto-vectorized loops denis.yaroshevskij at gmail dot com
  2022-05-30 22:42 ` [Bug middle-end/105781] " pinskia at gcc dot gnu.org
@ 2022-05-30 23:27 ` pinskia at gcc dot gnu.org
  2022-05-31  0:15 ` denis.yaroshevskij at gmail dot com
                   ` (3 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: pinskia at gcc dot gnu.org @ 2022-05-30 23:27 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Severity|normal                      |enhancement

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Yes adding -funroll-loops unrolls the loops as expected.

I don't think there is anything to do here really.

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

* [Bug middle-end/105781] GCC does not unroll auto-vectorized loops.
  2022-05-30 22:37 [Bug c++/105781] New: GCC does not unroll auto-vectorized loops denis.yaroshevskij at gmail dot com
  2022-05-30 22:42 ` [Bug middle-end/105781] " pinskia at gcc dot gnu.org
  2022-05-30 23:27 ` pinskia at gcc dot gnu.org
@ 2022-05-31  0:15 ` denis.yaroshevskij at gmail dot com
  2022-05-31  1:33 ` crazylht at gmail dot com
                   ` (2 subsequent siblings)
  5 siblings, 0 replies; 7+ messages in thread
From: denis.yaroshevskij at gmail dot com @ 2022-05-31  0:15 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 from Denis Yaroshevskiy <denis.yaroshevskij at gmail dot com> ---
Thank you, feel free to close then

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

* [Bug middle-end/105781] GCC does not unroll auto-vectorized loops.
  2022-05-30 22:37 [Bug c++/105781] New: GCC does not unroll auto-vectorized loops denis.yaroshevskij at gmail dot com
                   ` (2 preceding siblings ...)
  2022-05-31  0:15 ` denis.yaroshevskij at gmail dot com
@ 2022-05-31  1:33 ` crazylht at gmail dot com
  2022-05-31  7:14 ` denis.yaroshevskij at gmail dot com
  2022-06-01 11:49 ` rguenth at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: crazylht at gmail dot com @ 2022-05-31  1:33 UTC (permalink / raw)
  To: gcc-bugs

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

Hongtao.liu <crazylht at gmail dot com> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |crazylht at gmail dot com

--- Comment #4 from Hongtao.liu <crazylht at gmail dot com> ---
Just note we can also use *#pragma GCC unroll n* to specify the unrolling
factor.

#pragma GCC unroll 4
void double_elements(int* f, int* l, int v) {
    while (f != l) {
        *f = *f + *f;
        ++f;
    }
}

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

* [Bug middle-end/105781] GCC does not unroll auto-vectorized loops.
  2022-05-30 22:37 [Bug c++/105781] New: GCC does not unroll auto-vectorized loops denis.yaroshevskij at gmail dot com
                   ` (3 preceding siblings ...)
  2022-05-31  1:33 ` crazylht at gmail dot com
@ 2022-05-31  7:14 ` denis.yaroshevskij at gmail dot com
  2022-06-01 11:49 ` rguenth at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: denis.yaroshevskij at gmail dot com @ 2022-05-31  7:14 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Denis Yaroshevskiy <denis.yaroshevskij at gmail dot com> ---
Pragma is not going to be used in 99.9% of cases.
TBH I think that gcc should not require -funroll-loops at least on O3. This is
not a well known flag and people expect O3 to be max speed at the expense of
size.

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

* [Bug middle-end/105781] GCC does not unroll auto-vectorized loops.
  2022-05-30 22:37 [Bug c++/105781] New: GCC does not unroll auto-vectorized loops denis.yaroshevskij at gmail dot com
                   ` (4 preceding siblings ...)
  2022-05-31  7:14 ` denis.yaroshevskij at gmail dot com
@ 2022-06-01 11:49 ` rguenth at gcc dot gnu.org
  5 siblings, 0 replies; 7+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-06-01 11:49 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from Richard Biener <rguenth at gcc dot gnu.org> ---
The issue is cost modeling which is what the existing -funroll-[all-]loops RTL
unrolling lacks.  The vectorizer meanwhile can unroll vectorized loops by means
of increasing the vectorization factor which the target can suggest by
adjusting m_suggested_unroll_factor in the finish_cost hook.  See the aarch64
port for an example.

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

end of thread, other threads:[~2022-06-01 11:49 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-05-30 22:37 [Bug c++/105781] New: GCC does not unroll auto-vectorized loops denis.yaroshevskij at gmail dot com
2022-05-30 22:42 ` [Bug middle-end/105781] " pinskia at gcc dot gnu.org
2022-05-30 23:27 ` pinskia at gcc dot gnu.org
2022-05-31  0:15 ` denis.yaroshevskij at gmail dot com
2022-05-31  1:33 ` crazylht at gmail dot com
2022-05-31  7:14 ` denis.yaroshevskij at gmail dot com
2022-06-01 11:49 ` rguenth 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).