public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
From: "rguenth at gcc dot gnu.org" <gcc-bugzilla@gcc.gnu.org>
To: gcc-bugs@gcc.gnu.org
Subject: [Bug tree-optimization/103029] [12 regression] gcc.dg/vect/pr82436.c ICEs on r12-4818
Date: Tue, 02 Nov 2021 15:56:51 +0000	[thread overview]
Message-ID: <bug-103029-4-8JKL1ZOPNQ@http.gcc.gnu.org/bugzilla/> (raw)
In-Reply-To: <bug-103029-4@http.gcc.gnu.org/bugzilla/>

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

--- Comment #5 from Richard Biener <rguenth at gcc dot gnu.org> ---
The gimple_lv_adjust_loop_header_phi comment isn't relevant but what is is the
association between PHI node argument and SLP node index from the analysis
phase,
in particular for backedges.  See vect_schedule_scc which does

  /* Now fixup the backedge def of the vectorized PHIs in this SCC.  */
  slp_tree phi_node;
  FOR_EACH_VEC_ELT (phis_to_fixup, i, phi_node)
    {
      gphi *phi = as_a <gphi *> (SLP_TREE_REPRESENTATIVE (phi_node)->stmt);
      edge_iterator ei;
      edge e;
      FOR_EACH_EDGE (e, ei, gimple_bb (phi)->preds)
        {
          unsigned dest_idx = e->dest_idx;
          child = SLP_TREE_CHILDREN (phi_node)[dest_idx];
          if (!child || SLP_TREE_DEF_TYPE (child) != vect_internal_def)
            continue;

but here

(gdb) p e
$14 = <edge 0x7ffff63c0690 (10 -> 9)>
(gdb) p e->dest_idx
$12 = 0
(gdb) p debug (phi_node)
pr82436.c:20:5: note: node 0x3448ba8 (max_nunits=2, refcnt=1)
pr82436.c:20:5: note: op template: w_lsm.7_73 = PHI <_58(10), 0.0(25)>
pr82436.c:20:5: note:   stmt 0 w_lsm.7_73 = PHI <_58(10), 0.0(25)>
pr82436.c:20:5: note:   stmt 1 y_lsm.6_74 = PHI <_61(10), 0.0(25)>
pr82436.c:20:5: note:   children (nil) 0x34487f0

so in fact the entry edge edge now has the backedge SLP node.

I think the former dance redirecting edges back and forth made the edge
order consistent but nothing really forced it the same order as the
original loop which could have either order as well.

In fact the old code seems to reliably put the entry edge first
(but we start with the entry edge second with the very first version)
but the new code manages to swap the edges on the _old_ loop
which I think is something we should try to avoid.

That happens when we loop_redirect_edge (latch_edge, nloop->header);

I suppose without making loop_version entirely SSA dependent we can
for the moment mostly ensure we end up with the same order but not
necessarily avoid changing the original IL order.

diff --git a/gcc/tree-cfg.c b/gcc/tree-cfg.c
index 8ed8c69b5b1..81b0dcb7006 100644
--- a/gcc/tree-cfg.c
+++ b/gcc/tree-cfg.c
@@ -9044,6 +9044,23 @@ gimple_lv_adjust_loop_header_phi (basic_block first,
basic_block second,
       def = PHI_ARG_DEF (phi2, e2->dest_idx);
       add_phi_arg (phi1, def, e, gimple_phi_arg_location_from_edge (phi2,
e2));
     }
+
+  /* If the edges into the old and new loop end up at different PHI arg
+     indices swap one by redirecting it to its own destination.  */
+  if (e->dest_idx != e2->dest_idx)
+    {
+      if (e->dest_idx == 0)
+       {
+         ssa_redirect_edge (e, e->dest);
+         flush_pending_stmts (e);
+       }
+      else
+       {
+         gcc_assert (e2->dest_idx == 0);
+         ssa_redirect_edge (e2, e2->dest);
+         flush_pending_stmts (e2);
+       }
+    }
 }

ensures this and fixes the testcase.  As said it would be desirable to
preserve the original loop PHI argument order.

A way to have the vectorizer less fragile would of course be also appreciated.

I am testing the above.

  parent reply	other threads:[~2021-11-02 15:56 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-11-01 18:43 [Bug tree-optimization/103029] New: " seurer at gcc dot gnu.org
2021-11-01 18:46 ` [Bug tree-optimization/103029] " seurer at gcc dot gnu.org
2021-11-02  3:46 ` luoxhu at gcc dot gnu.org
2021-11-02  6:04 ` luoxhu at gcc dot gnu.org
2021-11-02  7:45 ` rguenth at gcc dot gnu.org
2021-11-02 15:56 ` rguenth at gcc dot gnu.org [this message]
2021-11-02 17:49 ` cvs-commit at gcc dot gnu.org
2021-11-02 17:50 ` rguenth at gcc dot gnu.org
2021-11-03  1:22 ` luoxhu at gcc dot gnu.org

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=bug-103029-4-8JKL1ZOPNQ@http.gcc.gnu.org/bugzilla/ \
    --to=gcc-bugzilla@gcc.gnu.org \
    --cc=gcc-bugs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).