public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c++/103544] New: compiler crashes when trying to vectorize loop
@ 2021-12-03 17:20 monad at posteo dot net
  2021-12-03 20:13 ` [Bug c++/103544] " pinskia at gcc dot gnu.org
                   ` (10 more replies)
  0 siblings, 11 replies; 12+ messages in thread
From: monad at posteo dot net @ 2021-12-03 17:20 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 103544
           Summary: compiler crashes when trying to vectorize loop
           Product: gcc
           Version: 11.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: monad at posteo dot net
  Target Milestone: ---

the following program crashes g++:


int crash_me(char* ptr, size_t size){
    std::array<short, 16> result = {0};

    size_t no_iters = 0;
    for(size_t i = 0; i < size - 12; i+= 13){
        for(size_t j = 0; j < 12; j++){
            result[j] += ptr[i + j] - '0';
        }
        no_iters++;
    }

    int result_int = 0;
    for(int j = 0; j < 12; j++){
        int bit_value = result[j] > no_iters/2 ? 1 : 0;
        result_int |= bit_value;
    }

    return result_int;
}




it results in:


during GIMPLE pass: vect
<source>: In function 'int crash_me(char*, size_t)':
<source>:4:5: internal compiler error: in vect_transform_reduction, at
tree-vect-loop.c:7378
    4 | int crash_me(char* ptr, size_t size){
      |     ^~~~~~~~
0x1786229 internal_error(char const*, ...)
        ???:0
0x678608 fancy_abort(char const*, int, char const*)
        ???:0
0xf53cdc vect_transform_reduction(_loop_vec_info*, _stmt_vec_info*,
gimple_stmt_iterator*, gimple**, _slp_tree*)
        ???:0
0xf4936d vect_transform_stmt(vec_info*, _stmt_vec_info*, gimple_stmt_iterator*,
_slp_tree*, _slp_instance*)
        ???:0
0xf861ee vect_schedule_slp(vec_info*, vec<_slp_instance*, va_heap, vl_ptr>)
        ???:0
0xf64ed0 vect_transform_loop(_loop_vec_info*, gimple*)
        ???:0
0xf90d61 vectorize_loops()
        ???:0





optimization flags used: -O3 -march=haswell
g++ version: 11.1 on my local machine, 11.2 on godbolt. 
godbolt link: https://godbolt.org/z/WjPbcE4sa

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

* [Bug c++/103544] compiler crashes when trying to vectorize loop
  2021-12-03 17:20 [Bug c++/103544] New: compiler crashes when trying to vectorize loop monad at posteo dot net
@ 2021-12-03 20:13 ` pinskia at gcc dot gnu.org
  2021-12-03 20:16 ` [Bug tree-optimization/103544] [11/12 Regression] " pinskia at gcc dot gnu.org
                   ` (9 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-03 20:13 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #1 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Testcase:
#include <array>
#include <immintrin.h>

int crash_me(char* ptr, size_t size){
    std::array<short, 16> result = {0};

    size_t no_iters = 0;
    for(size_t i = 0; i < size - 12; i+= 13){
        for(size_t j = 0; j < 12; j++){
            result[j] += ptr[i + j] - '0';
        }
        no_iters++;
    }

    int result_int = 0;
    for(int j = 0; j < 12; j++){
        int bit_value = result[j] > no_iters/2 ? 1 : 0;
        result_int |= bit_value;
    }

    return result_int;
}

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

* [Bug tree-optimization/103544] [11/12 Regression] compiler crashes when trying to vectorize loop
  2021-12-03 17:20 [Bug c++/103544] New: compiler crashes when trying to vectorize loop monad at posteo dot net
  2021-12-03 20:13 ` [Bug c++/103544] " pinskia at gcc dot gnu.org
@ 2021-12-03 20:16 ` pinskia at gcc dot gnu.org
  2021-12-06  8:20 ` rguenth at gcc dot gnu.org
                   ` (8 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: pinskia at gcc dot gnu.org @ 2021-12-03 20:16 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
          Component|c++                         |tree-optimization
      Known to work|                            |10.1.0, 10.3.0
   Last reconfirmed|                            |2021-12-03
            Summary|compiler crashes when       |[11/12 Regression] compiler
                   |trying to vectorize loop    |crashes when trying to
                   |                            |vectorize loop
           Keywords|                            |ice-on-valid-code
             Status|UNCONFIRMED                 |NEW
   Target Milestone|---                         |11.3
      Known to fail|                            |11.1.0, 11.2.0
     Ever confirmed|0                           |1

--- Comment #2 from Andrew Pinski <pinskia at gcc dot gnu.org> ---
Testcase without any headers:
int crash_me(char* ptr, unsigned long size){
    short result[16] = {0};

    unsigned long no_iters = 0;
    for(unsigned long i = 0; i < size - 12; i+= 13){
        for(unsigned long j = 0; j < 12; j++){
            result[j] += ptr[i + j] - '0';
        }
        no_iters++;
    }

    int result_int = 0;
    for(int j = 0; j < 12; j++){
        int bit_value = result[j] > no_iters/2 ? 1 : 0;
        result_int |= bit_value;
    }

    return result_int;
}

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

* [Bug tree-optimization/103544] [11/12 Regression] compiler crashes when trying to vectorize loop
  2021-12-03 17:20 [Bug c++/103544] New: compiler crashes when trying to vectorize loop monad at posteo dot net
  2021-12-03 20:13 ` [Bug c++/103544] " pinskia at gcc dot gnu.org
  2021-12-03 20:16 ` [Bug tree-optimization/103544] [11/12 Regression] " pinskia at gcc dot gnu.org
@ 2021-12-06  8:20 ` rguenth at gcc dot gnu.org
  2021-12-06  9:52 ` rguenth at gcc dot gnu.org
                   ` (7 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-12-06  8:20 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |rguenth at gcc dot gnu.org

--- Comment #3 from Richard Biener <rguenth at gcc dot gnu.org> ---
I will have a look.

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

* [Bug tree-optimization/103544] [11/12 Regression] compiler crashes when trying to vectorize loop
  2021-12-03 17:20 [Bug c++/103544] New: compiler crashes when trying to vectorize loop monad at posteo dot net
                   ` (2 preceding siblings ...)
  2021-12-06  8:20 ` rguenth at gcc dot gnu.org
@ 2021-12-06  9:52 ` rguenth at gcc dot gnu.org
  2021-12-06 10:41 ` rguenth at gcc dot gnu.org
                   ` (6 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-12-06  9:52 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Priority|P3                          |P2

--- Comment #4 from Richard Biener <rguenth at gcc dot gnu.org> ---
  if (!single_defuse_cycle
      && !lane_reduc_code_p
      && reduction_type != FOLD_LEFT_REDUCTION)
    {
      stmt_vec_info tem
        = vect_stmt_to_vectorize (STMT_VINFO_REDUC_DEF (phi_info));
      if (slp_node && REDUC_GROUP_FIRST_ELEMENT (tem))
        {
          gcc_assert (!REDUC_GROUP_NEXT_ELEMENT (tem));
          tem = REDUC_GROUP_FIRST_ELEMENT (tem);
        }
      STMT_VINFO_DEF_TYPE (vect_orig_stmt (tem)) = vect_internal_def;
      STMT_VINFO_DEF_TYPE (tem) = vect_internal_def;

fails to work here, because we end up visiting the reduction stmt before the
reduction PHI because we have a hybrid use that makes another entry into the
SLP graph, reaching the reduction stmt over the backedge.

But the above relies on us doing the reduction analysis on the PHI node before
the analysis of the reduction stmt.

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

* [Bug tree-optimization/103544] [11/12 Regression] compiler crashes when trying to vectorize loop
  2021-12-03 17:20 [Bug c++/103544] New: compiler crashes when trying to vectorize loop monad at posteo dot net
                   ` (3 preceding siblings ...)
  2021-12-06  9:52 ` rguenth at gcc dot gnu.org
@ 2021-12-06 10:41 ` rguenth at gcc dot gnu.org
  2021-12-06 11:53 ` cvs-commit at gcc dot gnu.org
                   ` (5 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-12-06 10:41 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> ---
Hmm, or rather the reduction path with chain starts in midst of the cycle
because
it has a leading conversion embedded which we don't represent.  But the
reduction path detection fails so we instead discover a SLP reduction but now
with the "wrong" leading stmt.  We'd have to reverse engineer the original
which can be quite complicated (see how vectorizable_reduction walks the
chain).  For an initial fix that can be backported do simple.

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

* [Bug tree-optimization/103544] [11/12 Regression] compiler crashes when trying to vectorize loop
  2021-12-03 17:20 [Bug c++/103544] New: compiler crashes when trying to vectorize loop monad at posteo dot net
                   ` (4 preceding siblings ...)
  2021-12-06 10:41 ` rguenth at gcc dot gnu.org
@ 2021-12-06 11:53 ` cvs-commit at gcc dot gnu.org
  2021-12-06 11:54 ` [Bug tree-optimization/103544] [11 " rguenth at gcc dot gnu.org
                   ` (4 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2021-12-06 11:53 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #6 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:

https://gcc.gnu.org/g:ee01694151edc7e8aef84dc3c484469e2ae443a0

commit r12-5803-gee01694151edc7e8aef84dc3c484469e2ae443a0
Author: Richard Biener <rguenther@suse.de>
Date:   Mon Dec 6 11:43:28 2021 +0100

    tree-optimization/103544 - SLP reduction chain as SLP reduction issue

    When SLP reduction chain vectorization support added handling of
    an outer conversion in the chain picking a failed reduction up
    as SLP reduction that broke the invariant that the whole reduction
    was forward reachable.  The following plugs that hole noting
    a future enhancement possibility.

    2021-12-06  Richard Biener  <rguenther@suse.de>

            PR tree-optimization/103544
            * tree-vect-slp.c (vect_analyze_slp): Only add a SLP reduction
            opportunity if the stmt in question is the reduction root.
            (dot_slp_tree): Add missing check for NULL child.

            * gcc.dg/vect/pr103544.c: New testcase.

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

* [Bug tree-optimization/103544] [11 Regression] compiler crashes when trying to vectorize loop
  2021-12-03 17:20 [Bug c++/103544] New: compiler crashes when trying to vectorize loop monad at posteo dot net
                   ` (5 preceding siblings ...)
  2021-12-06 11:53 ` cvs-commit at gcc dot gnu.org
@ 2021-12-06 11:54 ` rguenth at gcc dot gnu.org
  2022-01-04  9:16 ` cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2021-12-06 11:54 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
            Summary|[11/12 Regression] compiler |[11 Regression] compiler
                   |crashes when trying to      |crashes when trying to
                   |vectorize loop              |vectorize loop
      Known to work|                            |12.0

--- Comment #7 from Richard Biener <rguenth at gcc dot gnu.org> ---
Fixed on trunk sofar.

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

* [Bug tree-optimization/103544] [11 Regression] compiler crashes when trying to vectorize loop
  2021-12-03 17:20 [Bug c++/103544] New: compiler crashes when trying to vectorize loop monad at posteo dot net
                   ` (6 preceding siblings ...)
  2021-12-06 11:54 ` [Bug tree-optimization/103544] [11 " rguenth at gcc dot gnu.org
@ 2022-01-04  9:16 ` cvs-commit at gcc dot gnu.org
  2022-02-17 10:13 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  10 siblings, 0 replies; 12+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-01-04  9:16 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #8 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The master branch has been updated by Richard Biener <rguenth@gcc.gnu.org>:

https://gcc.gnu.org/g:1a15451da14410bf2bd6ec8f5baba1014638c67a

commit r12-6203-g1a15451da14410bf2bd6ec8f5baba1014638c67a
Author: Richard Biener <rguenther@suse.de>
Date:   Tue Jan 4 10:12:47 2022 +0100

    tree-optimization/103864 - SLP reduction of reductions with conversions

    This generalizes the fix for PR103544 to also cover reductions that
    are not reduction chains and does not consider reductions wrapped in
    sign conversions for SLP reduction handling.

    2022-01-04  Richard Biener  <rguenther@suse.de>

            PR tree-optimization/103864
            PR tree-optimization/103544
            * tree-vect-slp.c (vect_analyze_slp_instance): Exclude
            reductions wrapped in conversions from SLP handling.
            (vect_analyze_slp): Revert PR103544 change.

            * gcc.dg/vect/pr103864.c: New testcase.

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

* [Bug tree-optimization/103544] [11 Regression] compiler crashes when trying to vectorize loop
  2021-12-03 17:20 [Bug c++/103544] New: compiler crashes when trying to vectorize loop monad at posteo dot net
                   ` (7 preceding siblings ...)
  2022-01-04  9:16 ` cvs-commit at gcc dot gnu.org
@ 2022-02-17 10:13 ` cvs-commit at gcc dot gnu.org
  2022-02-17 10:13 ` cvs-commit at gcc dot gnu.org
  2022-02-17 10:14 ` rguenth at gcc dot gnu.org
  10 siblings, 0 replies; 12+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-02-17 10:13 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #9 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Richard Biener
<rguenth@gcc.gnu.org>:

https://gcc.gnu.org/g:d1dc0f6222ecb6eda674e708235c7bc0d90fa987

commit r11-9584-gd1dc0f6222ecb6eda674e708235c7bc0d90fa987
Author: Richard Biener <rguenther@suse.de>
Date:   Mon Dec 6 11:43:28 2021 +0100

    tree-optimization/103544 - SLP reduction chain as SLP reduction issue

    When SLP reduction chain vectorization support added handling of
    an outer conversion in the chain picking a failed reduction up
    as SLP reduction that broke the invariant that the whole reduction
    was forward reachable.  The following plugs that hole noting
    a future enhancement possibility.

    2021-12-06  Richard Biener  <rguenther@suse.de>

            PR tree-optimization/103544
            * tree-vect-slp.c (vect_analyze_slp): Only add a SLP reduction
            opportunity if the stmt in question is the reduction root.

            * gcc.dg/vect/pr103544.c: New testcase.

    (cherry picked from commit ee01694151edc7e8aef84dc3c484469e2ae443a0)

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

* [Bug tree-optimization/103544] [11 Regression] compiler crashes when trying to vectorize loop
  2021-12-03 17:20 [Bug c++/103544] New: compiler crashes when trying to vectorize loop monad at posteo dot net
                   ` (8 preceding siblings ...)
  2022-02-17 10:13 ` cvs-commit at gcc dot gnu.org
@ 2022-02-17 10:13 ` cvs-commit at gcc dot gnu.org
  2022-02-17 10:14 ` rguenth at gcc dot gnu.org
  10 siblings, 0 replies; 12+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2022-02-17 10:13 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #10 from CVS Commits <cvs-commit at gcc dot gnu.org> ---
The releases/gcc-11 branch has been updated by Richard Biener
<rguenth@gcc.gnu.org>:

https://gcc.gnu.org/g:c08d4266e48d52b7f8d16c79d3471be40ff56acc

commit r11-9585-gc08d4266e48d52b7f8d16c79d3471be40ff56acc
Author: Richard Biener <rguenther@suse.de>
Date:   Tue Jan 4 10:12:47 2022 +0100

    tree-optimization/103864 - SLP reduction of reductions with conversions

    This generalizes the fix for PR103544 to also cover reductions that
    are not reduction chains and does not consider reductions wrapped in
    sign conversions for SLP reduction handling.

    2022-01-04  Richard Biener  <rguenther@suse.de>

            PR tree-optimization/103864
            PR tree-optimization/103544
            * tree-vect-slp.c (vect_analyze_slp_instance): Exclude
            reductions wrapped in conversions from SLP handling.
            (vect_analyze_slp): Revert PR103544 change.

            * gcc.dg/vect/pr103864.c: New testcase.

    (cherry picked from commit 1a15451da14410bf2bd6ec8f5baba1014638c67a)

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

* [Bug tree-optimization/103544] [11 Regression] compiler crashes when trying to vectorize loop
  2021-12-03 17:20 [Bug c++/103544] New: compiler crashes when trying to vectorize loop monad at posteo dot net
                   ` (9 preceding siblings ...)
  2022-02-17 10:13 ` cvs-commit at gcc dot gnu.org
@ 2022-02-17 10:14 ` rguenth at gcc dot gnu.org
  10 siblings, 0 replies; 12+ messages in thread
From: rguenth at gcc dot gnu.org @ 2022-02-17 10:14 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to work|                            |11.2.1
             Status|ASSIGNED                    |RESOLVED
         Resolution|---                         |FIXED

--- Comment #11 from Richard Biener <rguenth at gcc dot gnu.org> ---
Fixed.

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

end of thread, other threads:[~2022-02-17 10:14 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-12-03 17:20 [Bug c++/103544] New: compiler crashes when trying to vectorize loop monad at posteo dot net
2021-12-03 20:13 ` [Bug c++/103544] " pinskia at gcc dot gnu.org
2021-12-03 20:16 ` [Bug tree-optimization/103544] [11/12 Regression] " pinskia at gcc dot gnu.org
2021-12-06  8:20 ` rguenth at gcc dot gnu.org
2021-12-06  9:52 ` rguenth at gcc dot gnu.org
2021-12-06 10:41 ` rguenth at gcc dot gnu.org
2021-12-06 11:53 ` cvs-commit at gcc dot gnu.org
2021-12-06 11:54 ` [Bug tree-optimization/103544] [11 " rguenth at gcc dot gnu.org
2022-01-04  9:16 ` cvs-commit at gcc dot gnu.org
2022-02-17 10:13 ` cvs-commit at gcc dot gnu.org
2022-02-17 10:13 ` cvs-commit at gcc dot gnu.org
2022-02-17 10:14 ` 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).