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 r12-4989] tree-optimization/103102 - fix error in vectorizer refactoring
Date: Mon,  8 Nov 2021 09:06:38 +0000 (GMT)	[thread overview]
Message-ID: <20211108090638.36710385800C@sourceware.org> (raw)

https://gcc.gnu.org/g:51152076338bc60b8bda8f061be2db97ea5b78de

commit r12-4989-g51152076338bc60b8bda8f061be2db97ea5b78de
Author: Richard Biener <rguenther@suse.de>
Date:   Mon Nov 8 09:08:12 2021 +0100

    tree-optimization/103102 - fix error in vectorizer refactoring
    
    This fixes an oversight that caused vectorized epilogues to have
    versioning for niters applied.
    
    2021-11-08  Richard Biener  <rguenther@suse.de>
    
            * tree-vectorizer.h (vect_create_loop_vinfo): Add main_loop_info
            parameter.
            * tree-vect-loop.c (vect_create_loop_vinfo): Likewise.  Set
            LOOP_VINFO_ORIG_LOOP_INFO and conditionalize set of
            LOOP_VINFO_NITERS_ASSUMPTIONS.
            (vect_analyze_loop_1): Adjust.
            (vect_analyze_loop): Move loop constraint setting and
            SCEV/niter reset here from vect_create_loop_vinfo to perform
            it only once.
            (vect_analyze_loop_form): Move dumping of symbolic niters
            here from vect_create_loop_vinfo.

Diff:
---
 gcc/tree-vect-loop.c  | 58 ++++++++++++++++++++++++++-------------------------
 gcc/tree-vectorizer.h |  3 ++-
 2 files changed, 32 insertions(+), 29 deletions(-)

diff --git a/gcc/tree-vect-loop.c b/gcc/tree-vect-loop.c
index b56b7a4a386..ede9aff0522 100644
--- a/gcc/tree-vect-loop.c
+++ b/gcc/tree-vect-loop.c
@@ -1464,6 +1464,18 @@ vect_analyze_loop_form (class loop *loop, vect_loop_form_info *info)
       (info->loop_cond,
        "not vectorized: number of iterations = 0.\n");
 
+  if (!(tree_fits_shwi_p (info->number_of_iterations)
+	&& tree_to_shwi (info->number_of_iterations) > 0))
+    {
+      if (dump_enabled_p ())
+	{
+	  dump_printf_loc (MSG_NOTE, vect_location,
+			   "Symbolic number of iterations is ");
+	  dump_generic_expr (MSG_NOTE, TDF_DETAILS, info->number_of_iterations);
+	  dump_printf (MSG_NOTE, "\n");
+	}
+    }
+
   return opt_result::success ();
 }
 
@@ -1472,36 +1484,17 @@ vect_analyze_loop_form (class loop *loop, vect_loop_form_info *info)
 
 loop_vec_info
 vect_create_loop_vinfo (class loop *loop, vec_info_shared *shared,
-			const vect_loop_form_info *info)
+			const vect_loop_form_info *info,
+			loop_vec_info main_loop_info)
 {
   loop_vec_info loop_vinfo = new _loop_vec_info (loop, shared);
   LOOP_VINFO_NITERSM1 (loop_vinfo) = info->number_of_iterationsm1;
   LOOP_VINFO_NITERS (loop_vinfo) = info->number_of_iterations;
   LOOP_VINFO_NITERS_UNCHANGED (loop_vinfo) = info->number_of_iterations;
-  if (!integer_onep (info->assumptions))
-    {
-      /* We consider to vectorize this loop by versioning it under
-	 some assumptions.  In order to do this, we need to clear
-	 existing information computed by scev and niter analyzer.  */
-      scev_reset_htab ();
-      free_numbers_of_iterations_estimates (loop);
-      /* Also set flag for this loop so that following scev and niter
-	 analysis are done under the assumptions.  */
-      loop_constraint_set (loop, LOOP_C_FINITE);
-      /* Also record the assumptions for versioning.  */
-      LOOP_VINFO_NITERS_ASSUMPTIONS (loop_vinfo) = info->assumptions;
-    }
-
-  if (!LOOP_VINFO_NITERS_KNOWN_P (loop_vinfo))
-    {
-      if (dump_enabled_p ())
-        {
-          dump_printf_loc (MSG_NOTE, vect_location,
-			   "Symbolic number of iterations is ");
-	  dump_generic_expr (MSG_NOTE, TDF_DETAILS, info->number_of_iterations);
-          dump_printf (MSG_NOTE, "\n");
-        }
-    }
+  LOOP_VINFO_ORIG_LOOP_INFO (loop_vinfo) = main_loop_info;
+  /* Also record the assumptions for versioning.  */
+  if (!integer_onep (info->assumptions) && !main_loop_info)
+    LOOP_VINFO_NITERS_ASSUMPTIONS (loop_vinfo) = info->assumptions;
 
   stmt_vec_info loop_cond_info = loop_vinfo->lookup_stmt (info->loop_cond);
   STMT_VINFO_TYPE (loop_cond_info) = loop_exit_ctrl_vec_info_type;
@@ -2903,9 +2896,7 @@ vect_analyze_loop_1 (class loop *loop, vec_info_shared *shared,
 		     bool &fatal)
 {
   loop_vec_info loop_vinfo
-    = vect_create_loop_vinfo (loop, shared, loop_form_info);
-  if (main_loop_vinfo)
-    LOOP_VINFO_ORIG_LOOP_INFO (loop_vinfo) = main_loop_vinfo;
+    = vect_create_loop_vinfo (loop, shared, loop_form_info, main_loop_vinfo);
 
   machine_mode vector_mode = vector_modes[mode_i];
   loop_vinfo->vector_mode = vector_mode;
@@ -2997,6 +2988,17 @@ vect_analyze_loop (class loop *loop, vec_info_shared *shared)
 			 "bad loop form.\n");
       return opt_loop_vec_info::propagate_failure (res);
     }
+  if (!integer_onep (loop_form_info.assumptions))
+    {
+      /* We consider to vectorize this loop by versioning it under
+	 some assumptions.  In order to do this, we need to clear
+	 existing information computed by scev and niter analyzer.  */
+      scev_reset_htab ();
+      free_numbers_of_iterations_estimates (loop);
+      /* Also set flag for this loop so that following scev and niter
+	 analysis are done under the assumptions.  */
+      loop_constraint_set (loop, LOOP_C_FINITE);
+    }
 
   auto_vector_modes vector_modes;
   /* Autodetect first vector size we try.  */
diff --git a/gcc/tree-vectorizer.h b/gcc/tree-vectorizer.h
index 7d3d3935c95..b552e9dccce 100644
--- a/gcc/tree-vectorizer.h
+++ b/gcc/tree-vectorizer.h
@@ -2160,7 +2160,8 @@ struct vect_loop_form_info
 };
 extern opt_result vect_analyze_loop_form (class loop *, vect_loop_form_info *);
 extern loop_vec_info vect_create_loop_vinfo (class loop *, vec_info_shared *,
-					     const vect_loop_form_info *);
+					     const vect_loop_form_info *,
+					     loop_vec_info = nullptr);
 extern bool vectorizable_live_operation (vec_info *,
 					 stmt_vec_info, gimple_stmt_iterator *,
 					 slp_tree, slp_instance, int,


                 reply	other threads:[~2021-11-08  9:06 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=20211108090638.36710385800C@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).