public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Richard Biener <rguenth@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc r14-8953] tree-optimization/113902 - fix VUSE update in move_early_exit_stmts
Date: Tue, 13 Feb 2024 11:43:41 +0000 (GMT)	[thread overview]
Message-ID: <20240213114341.0D6443858291@sourceware.org> (raw)

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

commit r14-8953-gaab45e2bbec340201f8faaccfa24756bc09cb7db
Author: Richard Biener <rguenther@suse.de>
Date:   Tue Feb 13 11:38:48 2024 +0100

    tree-optimization/113902 - fix VUSE update in move_early_exit_stmts
    
    The following adjusts move_early_exit_stmts to track the last seen
    VUSE instead of getting it from the last store which could be a PHI
    where gimple_vuse doesn't work.
    
            PR tree-optimization/113902
            * tree-vect-loop.cc (move_early_exit_stmts): Track
            last_seen_vuse for VUSE updating.
    
            * gcc.dg/vect/pr113902.c: New testcase.

Diff:
---
 gcc/testsuite/gcc.dg/vect/pr113902.c | 15 +++++++++++++++
 gcc/tree-vect-loop.cc                | 12 +++++++-----
 2 files changed, 22 insertions(+), 5 deletions(-)

diff --git a/gcc/testsuite/gcc.dg/vect/pr113902.c b/gcc/testsuite/gcc.dg/vect/pr113902.c
new file mode 100644
index 000000000000..a2fe3df26e20
--- /dev/null
+++ b/gcc/testsuite/gcc.dg/vect/pr113902.c
@@ -0,0 +1,15 @@
+/* { dg-do compile } */
+/* { dg-add-options vect_early_break } */
+
+int g_66, g_80_2;
+void func_1func_41(int p_43)
+{
+lbl_1434:
+  g_80_2 = 0;
+  for (; g_80_2 <= 7; g_80_2 += 1) {
+    g_66 = 0;
+    for (; g_66 <= 7; g_66 += 1)
+      if (p_43)
+        goto lbl_1434;
+  }
+}
diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index 367077965fd9..9e26b09504df 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -11787,6 +11787,7 @@ move_early_exit_stmts (loop_vec_info loop_vinfo)
   basic_block dest_bb = LOOP_VINFO_EARLY_BRK_DEST_BB (loop_vinfo);
   gimple_stmt_iterator dest_gsi = gsi_after_labels (dest_bb);
 
+  tree last_seen_vuse = NULL_TREE;
   for (gimple *stmt : LOOP_VINFO_EARLY_BRK_STORES (loop_vinfo))
     {
       /* We have to update crossed degenerate virtual PHIs.  Simply
@@ -11805,6 +11806,7 @@ move_early_exit_stmts (loop_vec_info loop_vinfo)
 	    }
 	  auto gsi = gsi_for_stmt (stmt);
 	  remove_phi_node (&gsi, true);
+	  last_seen_vuse = vuse;
 	  continue;
 	}
 
@@ -11819,17 +11821,17 @@ move_early_exit_stmts (loop_vec_info loop_vinfo)
 
       gimple_stmt_iterator stmt_gsi = gsi_for_stmt (stmt);
       gsi_move_before (&stmt_gsi, &dest_gsi, GSI_NEW_STMT);
+      last_seen_vuse = gimple_vuse (stmt);
     }
 
   /* Update all the stmts with their new reaching VUSES.  */
-  tree vuse
-    = gimple_vuse (LOOP_VINFO_EARLY_BRK_STORES (loop_vinfo).last ());
   for (auto p : LOOP_VINFO_EARLY_BRK_VUSES (loop_vinfo))
     {
       if (dump_enabled_p ())
 	  dump_printf_loc (MSG_NOTE, vect_location,
-			   "updating vuse to %T for load %G", vuse, p);
-      gimple_set_vuse (p, vuse);
+			   "updating vuse to %T for load %G",
+			   last_seen_vuse, p);
+      gimple_set_vuse (p, last_seen_vuse);
       update_stmt (p);
     }
 
@@ -11837,7 +11839,7 @@ move_early_exit_stmts (loop_vec_info loop_vinfo)
   for (edge e : get_loop_exit_edges (LOOP_VINFO_LOOP  (loop_vinfo)))
     if (!dominated_by_p (CDI_DOMINATORS, e->src, dest_bb))
       if (gphi *phi = get_virtual_phi (e->dest))
-	SET_PHI_ARG_DEF_ON_EDGE (phi, e, vuse);
+	SET_PHI_ARG_DEF_ON_EDGE (phi, e, last_seen_vuse);
 }
 
 /* Function vect_transform_loop.

                 reply	other threads:[~2024-02-13 11:43 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

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=20240213114341.0D6443858291@sourceware.org \
    --to=rguenth@gcc.gnu.org \
    --cc=gcc-cvs@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).