public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug tree-optimization/96698] New: aarch64: ICE during GIMPLE pass:vect
@ 2020-08-19  1:43 yangyang305 at huawei dot com
  2020-08-19 10:16 ` [Bug tree-optimization/96698] " marxin at gcc dot gnu.org
                   ` (6 more replies)
  0 siblings, 7 replies; 8+ messages in thread
From: yangyang305 at huawei dot com @ 2020-08-19  1:43 UTC (permalink / raw)
  To: gcc-bugs

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

            Bug ID: 96698
           Summary: aarch64: ICE during GIMPLE pass:vect
           Product: gcc
           Version: 11.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: tree-optimization
          Assignee: unassigned at gcc dot gnu.org
          Reporter: yangyang305 at huawei dot com
  Target Milestone: ---

Hi, gcc-trunk ICEs when compiling the following testcase with -O3:

void test(int a, int* i) {
  for (; a < 5; ++a) {
    int b = 0;
    int c = 0;
    for (; b != -11; b--)
      for (int d = 0; d ==0; d++) {
        *i += c & a;
        c = b;
      }
  }
}

during GIMPLE pass: vect
/home/yangyang/Testcase/ICE-274/test.c: In function ‘test’:
/home/yangyang/Testcase/ICE-274/test.c:1:6: internal compiler error: in
vect_transform_stmt, at tree-vect-stmts.c:10940
    1 | void test(int a, int* i) {
      |      ^~~~
0xf229ab vect_transform_stmt(vec_info*, _stmt_vec_info*, gimple_stmt_iterator*,
_slp_tree*, _slp_instance*)
        ../../gcc/tree-vect-stmts.c:10940
0xf3cdcb vect_transform_loop(_loop_vec_info*, gimple*)
        ../../gcc/tree-vect-loop.c:8972
0xf5aafb try_vectorize_loop_1
        ../../gcc/tree-vectorizer.c:1093
0xf5b7b7 vectorize_loops()
        ../../gcc/tree-vectorizer.c:1230
Please submit a full bug report,
with preprocessed source if appropriate.
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.

There are two PHIs in the inner loop:

<bb 5> [local count: 719407024]:
  # b_26 = PHI <0(4), b_15(10)>
  # c_27 = PHI <0(4), b_26(10)>

# c_27 = PHI <0(4), b_26(10)> is detected to be a vectorizable nested cycle by
vect_is_simple_reduction,  which seems to be wrong. Also # b_26 = PHI <0(4),
b_15(10)> is marked as the reduc_def of # c_27 = PHI <0(4), b_26(10)>, so when
doing vect_transform_stmt for it, gcc tries to add args for the vector version
of  # b_26 = PHI <0(4), b_15(10)> which has not been generated yet, leading to
the ICE.

This  failure was introduced by the following commit:
https://gcc.gnu.org/git/?p=gcc.git;a=commit;h=4a8841c0413d52261a8d024577381582d07a866a

    tree-vect-loop.c (vect_is_simple_reduction): Simplify and allow stmts other
than GIMPLE_ASSIGN in nested cycles.

    2019-10-09  Richard Biener  <rguenther@suse.de>

    * tree-vect-loop.c (vect_is_simple_reduction): Simplify and
    allow stmts other than GIMPLE_ASSIGN in nested cycles.

    * gcc.dg/vect/vect-outer-call-1.c: New testcase.

It simplifies and refactors vect_is_simple_reduction to make sure to not reject
nested cycle vectorization just beacuse there are calls in the innermost loop.
However, the analysis of phi nodes is moved from above the analysis of nested
cycles to below the analysis of nested cycles,  which seems to be irrelevant to
the purpose of this commit and results in the ICE.

I have prepared the following patch to fix this problem, this patch simply
moves the analysis of phi nodes above the analysis of nested cycle. Bootstrap
and tested on both aarch64 and x86 Linux platform, no new regression witnessed.

diff -uprN a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c
--- a/gcc/tree-vect-loop.c
+++ b/gcc/tree-vect-loop.c
@@ -3348,28 +3348,6 @@ vect_is_simple_reduction (loop_vec_info loop_info,
stmt_vec_info phi_info,
        }
     }

-  /* If we are vectorizing an inner reduction we are executing that
-     in the original order only in case we are not dealing with a
-     double reduction.  */
-  if (nested_in_vect_loop && !inner_loop_of_double_reduc)
-    {
-      if (dump_enabled_p ())
-       report_vect_op (MSG_NOTE, def_stmt_info->stmt,
-                       "detected nested cycle: ");
-      return def_stmt_info;
-    }
-
-  /* If this isn't a nested cycle or if the nested cycle reduction value
-     is used ouside of the inner loop we cannot handle uses of the reduction
-     value.  */
-  if (nlatch_def_loop_uses > 1 || nphi_def_loop_uses > 1)
-    {
-      if (dump_enabled_p ())
-       dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
-                        "reduction used in loop.\n");
-      return NULL;
-    }
-
   /* If DEF_STMT is a phi node itself, we expect it to have a single argument
      defined in the inner loop.  */
   if (gphi *def_stmt = dyn_cast <gphi *> (def_stmt_info->stmt))
@@ -3405,6 +3383,28 @@ vect_is_simple_reduction (loop_vec_info loop_info,
stmt_vec_info phi_info,
       return NULL;
     }

+  /* If we are vectorizing an inner reduction we are executing that
+     in the original order only in case we are not dealing with a
+     double reduction.  */
+  if (nested_in_vect_loop && !inner_loop_of_double_reduc)
+    {
+      if (dump_enabled_p ())
+       report_vect_op (MSG_NOTE, def_stmt_info->stmt,
+                       "detected nested cycle: ");
+      return def_stmt_info;
+    }
+
+  /* If this isn't a nested cycle or if the nested cycle reduction value
+     is used ouside of the inner loop we cannot handle uses of the reduction
+     value.  */
+  if (nlatch_def_loop_uses > 1 || nphi_def_loop_uses > 1)
+    {
+      if (dump_enabled_p ())
+       dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
+                       "reduction used in loop.\n");
+      return NULL;
+    }

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

* [Bug tree-optimization/96698] aarch64: ICE during GIMPLE pass:vect
  2020-08-19  1:43 [Bug tree-optimization/96698] New: aarch64: ICE during GIMPLE pass:vect yangyang305 at huawei dot com
@ 2020-08-19 10:16 ` marxin at gcc dot gnu.org
  2020-08-24  9:07 ` [Bug tree-optimization/96698] [10/11 Regression] " rguenth at gcc dot gnu.org
                   ` (5 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: marxin at gcc dot gnu.org @ 2020-08-19 10:16 UTC (permalink / raw)
  To: gcc-bugs

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

Martin Liška <marxin at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |marxin at gcc dot gnu.org,
                   |                            |rguenth at gcc dot gnu.org
             Status|UNCONFIRMED                 |NEW
     Ever confirmed|0                           |1
   Last reconfirmed|                            |2020-08-19

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

* [Bug tree-optimization/96698] [10/11 Regression] ICE during GIMPLE pass:vect
  2020-08-19  1:43 [Bug tree-optimization/96698] New: aarch64: ICE during GIMPLE pass:vect yangyang305 at huawei dot com
  2020-08-19 10:16 ` [Bug tree-optimization/96698] " marxin at gcc dot gnu.org
@ 2020-08-24  9:07 ` rguenth at gcc dot gnu.org
  2020-08-26 14:02 ` cvs-commit at gcc dot gnu.org
                   ` (4 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-08-24  9:07 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
           Keywords|                            |ice-on-valid-code
   Target Milestone|---                         |10.3
           Priority|P3                          |P2
             Status|NEW                         |ASSIGNED
           Assignee|unassigned at gcc dot gnu.org      |rguenth at gcc dot gnu.org
            Summary|aarch64: ICE during GIMPLE  |[10/11 Regression] ICE
                   |pass:vect                   |during GIMPLE pass:vect

--- Comment #1 from Richard Biener <rguenth at gcc dot gnu.org> ---
The case should be vectorizable - the issue is that the latch updating of the
vectorized reduction PHI happens before this PHI is created.

Confirmed on x86_64 as well.  Also crashes on the GCC 10 branch.

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

* [Bug tree-optimization/96698] [10/11 Regression] ICE during GIMPLE pass:vect
  2020-08-19  1:43 [Bug tree-optimization/96698] New: aarch64: ICE during GIMPLE pass:vect yangyang305 at huawei dot com
  2020-08-19 10:16 ` [Bug tree-optimization/96698] " marxin at gcc dot gnu.org
  2020-08-24  9:07 ` [Bug tree-optimization/96698] [10/11 Regression] " rguenth at gcc dot gnu.org
@ 2020-08-26 14:02 ` cvs-commit at gcc dot gnu.org
  2020-09-04 13:43 ` [Bug tree-optimization/96698] [10 " cvs-commit at gcc dot gnu.org
                   ` (3 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-08-26 14:02 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #2 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:2130efe6ac7beba72d289e3dd145daa10aeaed54

commit r11-2882-g2130efe6ac7beba72d289e3dd145daa10aeaed54
Author: Richard Biener <rguenther@suse.de>
Date:   Wed Aug 26 15:12:17 2020 +0200

    tree-optimization/96698 - fix ICE when vectorizing nested cycles

    This fixes vectorized PHI latch edge updating and delay it until
    all of the loop is code generated to deal with the case that the
    latch def is a PHI in the same block.

    2020-08-26  Richard Biener  <rguenther@suse.de>

            PR tree-optimization/96698
            * tree-vectorizer.h (loop_vec_info::reduc_latch_defs): New.
            (loop_vec_info::reduc_latch_slp_defs): Likewise.
            * tree-vect-stmts.c (vect_transform_stmt): Only record
            stmts to update PHI latches from, perform the update ...
            * tree-vect-loop.c (vect_transform_loop): ... here after
            vectorizing those PHIs.
            (info_for_reduction): Properly handle non-reduction PHIs.

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

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

* [Bug tree-optimization/96698] [10 Regression] ICE during GIMPLE pass:vect
  2020-08-19  1:43 [Bug tree-optimization/96698] New: aarch64: ICE during GIMPLE pass:vect yangyang305 at huawei dot com
                   ` (2 preceding siblings ...)
  2020-08-26 14:02 ` cvs-commit at gcc dot gnu.org
@ 2020-09-04 13:43 ` cvs-commit at gcc dot gnu.org
  2020-12-02 11:41 ` cvs-commit at gcc dot gnu.org
                   ` (2 subsequent siblings)
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-09-04 13:43 UTC (permalink / raw)
  To: gcc-bugs

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

--- Comment #3 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:46a58c779af3055a4b10b285a1f4be28abe4351c

commit r11-3013-g46a58c779af3055a4b10b285a1f4be28abe4351c
Author: Richard Biener <rguenther@suse.de>
Date:   Fri Sep 4 14:35:39 2020 +0200

    tree-optimization/96920 - another ICE when vectorizing nested cycles

    This refines the previous fix for PR96698 by re-doing how and where
    we arrange for setting vectorized cycle PHI backedge values.

    2020-09-04  Richard Biener  <rguenther@suse.de>

            PR tree-optimization/96698
            PR tree-optimization/96920
            * tree-vectorizer.h (loop_vec_info::reduc_latch_defs): Remove.
            (loop_vec_info::reduc_latch_slp_defs): Likewise.
            * tree-vect-stmts.c (vect_transform_stmt): Remove vectorized
            cycle PHI latch code.
            * tree-vect-loop.c (maybe_set_vectorized_backedge_value): New
            helper to set vectorized cycle PHI latch values.
            (vect_transform_loop): Walk over all PHIs again after
            vectorizing them, calling maybe_set_vectorized_backedge_value.
            Call maybe_set_vectorized_backedge_value for each vectorized
            stmt.  Remove delayed update code.
            * tree-vect-slp.c (vect_analyze_slp_instance): Initialize
            SLP instance reduc_phis member.
            (vect_schedule_slp): Set vectorized cycle PHI latch values.

            * gfortran.dg/vect/pr96920.f90: New testcase.
            * gcc.dg/vect/pr96920.c: Likewise.

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

* [Bug tree-optimization/96698] [10 Regression] ICE during GIMPLE pass:vect
  2020-08-19  1:43 [Bug tree-optimization/96698] New: aarch64: ICE during GIMPLE pass:vect yangyang305 at huawei dot com
                   ` (3 preceding siblings ...)
  2020-09-04 13:43 ` [Bug tree-optimization/96698] [10 " cvs-commit at gcc dot gnu.org
@ 2020-12-02 11:41 ` cvs-commit at gcc dot gnu.org
  2020-12-02 11:41 ` cvs-commit at gcc dot gnu.org
  2020-12-02 11:41 ` rguenth at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-12-02 11:41 UTC (permalink / raw)
  To: gcc-bugs

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

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

https://gcc.gnu.org/g:66dd83c8840a9a28f6209922b8abd5783a255207

commit r10-9106-g66dd83c8840a9a28f6209922b8abd5783a255207
Author: Richard Biener <rguenther@suse.de>
Date:   Wed Aug 26 15:12:17 2020 +0200

    tree-optimization/96698 - fix ICE when vectorizing nested cycles

    This fixes vectorized PHI latch edge updating and delay it until
    all of the loop is code generated to deal with the case that the
    latch def is a PHI in the same block.

    2020-08-26  Richard Biener  <rguenther@suse.de>

            PR tree-optimization/96698
            * tree-vectorizer.h (loop_vec_info::reduc_latch_defs): New.
            (loop_vec_info::reduc_latch_slp_defs): Likewise.
            * tree-vect-stmts.c (vect_transform_stmt): Only record
            stmts to update PHI latches from, perform the update ...
            * tree-vect-loop.c (vect_transform_loop): ... here after
            vectorizing those PHIs.
            (info_for_reduction): Properly handle non-reduction PHIs.

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

    (cherry picked from commit 2130efe6ac7beba72d289e3dd145daa10aeaed54)

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

* [Bug tree-optimization/96698] [10 Regression] ICE during GIMPLE pass:vect
  2020-08-19  1:43 [Bug tree-optimization/96698] New: aarch64: ICE during GIMPLE pass:vect yangyang305 at huawei dot com
                   ` (4 preceding siblings ...)
  2020-12-02 11:41 ` cvs-commit at gcc dot gnu.org
@ 2020-12-02 11:41 ` cvs-commit at gcc dot gnu.org
  2020-12-02 11:41 ` rguenth at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: cvs-commit at gcc dot gnu.org @ 2020-12-02 11:41 UTC (permalink / raw)
  To: gcc-bugs

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

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

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

commit r10-9107-ge563687cf9d3d1278f45aaebd03e0f66531076c9
Author: Richard Biener <rguenther@suse.de>
Date:   Fri Sep 4 14:35:39 2020 +0200

    tree-optimization/96920 - another ICE when vectorizing nested cycles

    This refines the previous fix for PR96698 by re-doing how and where
    we arrange for setting vectorized cycle PHI backedge values.

    2020-09-04  Richard Biener  <rguenther@suse.de>

            PR tree-optimization/96698
            PR tree-optimization/96920
            * tree-vectorizer.h (loop_vec_info::reduc_latch_defs): Remove.
            (loop_vec_info::reduc_latch_slp_defs): Likewise.
            * tree-vect-stmts.c (vect_transform_stmt): Remove vectorized
            cycle PHI latch code.
            * tree-vect-loop.c (maybe_set_vectorized_backedge_value): New
            helper to set vectorized cycle PHI latch values.
            (vect_transform_loop): Walk over all PHIs again after
            vectorizing them, calling maybe_set_vectorized_backedge_value.
            Call maybe_set_vectorized_backedge_value for each vectorized
            stmt.  Remove delayed update code.
            * tree-vect-slp.c (vect_analyze_slp_instance): Initialize
            SLP instance reduc_phis member.
            (vect_schedule_slp): Set vectorized cycle PHI latch values.

            * gfortran.dg/vect/pr96920.f90: New testcase.
            * gcc.dg/vect/pr96920.c: Likewise.

    (cherry picked from commit 46a58c779af3055a4b10b285a1f4be28abe4351c)

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

* [Bug tree-optimization/96698] [10 Regression] ICE during GIMPLE pass:vect
  2020-08-19  1:43 [Bug tree-optimization/96698] New: aarch64: ICE during GIMPLE pass:vect yangyang305 at huawei dot com
                   ` (5 preceding siblings ...)
  2020-12-02 11:41 ` cvs-commit at gcc dot gnu.org
@ 2020-12-02 11:41 ` rguenth at gcc dot gnu.org
  6 siblings, 0 replies; 8+ messages in thread
From: rguenth at gcc dot gnu.org @ 2020-12-02 11:41 UTC (permalink / raw)
  To: gcc-bugs

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

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

           What    |Removed                     |Added
----------------------------------------------------------------------------
      Known to fail|                            |10.2.0
      Known to work|                            |10.2.1
         Resolution|---                         |FIXED
             Status|ASSIGNED                    |RESOLVED

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

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

end of thread, other threads:[~2020-12-02 11:41 UTC | newest]

Thread overview: 8+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-19  1:43 [Bug tree-optimization/96698] New: aarch64: ICE during GIMPLE pass:vect yangyang305 at huawei dot com
2020-08-19 10:16 ` [Bug tree-optimization/96698] " marxin at gcc dot gnu.org
2020-08-24  9:07 ` [Bug tree-optimization/96698] [10/11 Regression] " rguenth at gcc dot gnu.org
2020-08-26 14:02 ` cvs-commit at gcc dot gnu.org
2020-09-04 13:43 ` [Bug tree-optimization/96698] [10 " cvs-commit at gcc dot gnu.org
2020-12-02 11:41 ` cvs-commit at gcc dot gnu.org
2020-12-02 11:41 ` cvs-commit at gcc dot gnu.org
2020-12-02 11:41 ` 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).