public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [PATCH] VECT: Change flow of decrement IV
@ 2023-05-30 11:28 juzhe.zhong
  2023-05-30 11:31 ` Richard Sandiford
  0 siblings, 1 reply; 26+ messages in thread
From: juzhe.zhong @ 2023-05-30 11:28 UTC (permalink / raw)
  To: gcc-patches; +Cc: richard.sandiford, rguenther, linkw, Ju-Zhe Zhong

From: Ju-Zhe Zhong <juzhe.zhong@rivai.ai>

Follow Richi's suggestion, I change current decrement IV flow from:

do {
   remain -= MIN (vf, remain);
} while (remain != 0);

into:

do {
   old_remain = remain;
   len = MIN (vf, remain);
   remain -= vf;
} while (old_remain >= vf);

to enhance SCEV.

ALL tests (decrement IV) of RVV are passed.
Ok for trunk?

gcc/ChangeLog:

        * tree-vect-loop-manip.cc (vect_set_loop_controls_directly): Change decrement IV flow.
        (vect_set_loop_condition_partial_vectors): Ditto.

---
 gcc/tree-vect-loop-manip.cc | 40 +++++++++++++++++++++++++------------
 1 file changed, 27 insertions(+), 13 deletions(-)

diff --git a/gcc/tree-vect-loop-manip.cc b/gcc/tree-vect-loop-manip.cc
index acf3642ceb2..ef28711c58f 100644
--- a/gcc/tree-vect-loop-manip.cc
+++ b/gcc/tree-vect-loop-manip.cc
@@ -483,7 +483,7 @@ vect_set_loop_controls_directly (class loop *loop, loop_vec_info loop_vinfo,
 				 gimple_stmt_iterator loop_cond_gsi,
 				 rgroup_controls *rgc, tree niters,
 				 tree niters_skip, bool might_wrap_p,
-				 tree *iv_step)
+				 tree *iv_step, tree *compare_step)
 {
   tree compare_type = LOOP_VINFO_RGROUP_COMPARE_TYPE (loop_vinfo);
   tree iv_type = LOOP_VINFO_RGROUP_IV_TYPE (loop_vinfo);
@@ -538,24 +538,26 @@ vect_set_loop_controls_directly (class loop *loop, loop_vec_info loop_vinfo,
 	   ...
 	   vect__4.8_28 = .LEN_LOAD (_17, 32B, _36, 0);
 	   ...
-	   ivtmp_35 = ivtmp_9 - _36;
+	   ivtmp_35 = ivtmp_9 - POLY_INT_CST [4, 4];
 	   ...
-	   if (ivtmp_35 != 0)
-	     goto <bb 4>; [83.33%]
+	   if (ivtmp_9 > POLY_INT_CST [4, 4])
+	     goto <bb 6>; [83.33%]
 	   else
-	     goto <bb 5>; [16.67%]
+	     goto <bb 7>; [16.67%]
       */
       nitems_total = gimple_convert (preheader_seq, iv_type, nitems_total);
       tree step = rgc->controls.length () == 1 ? rgc->controls[0]
 					       : make_ssa_name (iv_type);
       /* Create decrement IV.  */
-      create_iv (nitems_total, MINUS_EXPR, step, NULL_TREE, loop, &incr_gsi,
-		 insert_after, &index_before_incr, &index_after_incr);
+      create_iv (nitems_total, MINUS_EXPR, nitems_step, NULL_TREE, loop,
+		 &incr_gsi, insert_after, &index_before_incr,
+		 &index_after_incr);
       gimple_seq_add_stmt (header_seq, gimple_build_assign (step, MIN_EXPR,
 							    index_before_incr,
 							    nitems_step));
       *iv_step = step;
-      return index_after_incr;
+      *compare_step = nitems_step;
+      return index_before_incr;
     }
 
   /* Create increment IV.  */
@@ -825,6 +827,7 @@ vect_set_loop_condition_partial_vectors (class loop *loop,
      arbitrarily pick the last.  */
   tree test_ctrl = NULL_TREE;
   tree iv_step = NULL_TREE;
+  tree compare_step = NULL_TREE;
   rgroup_controls *rgc;
   rgroup_controls *iv_rgc = nullptr;
   unsigned int i;
@@ -861,7 +864,7 @@ vect_set_loop_condition_partial_vectors (class loop *loop,
 						 &preheader_seq, &header_seq,
 						 loop_cond_gsi, rgc, niters,
 						 niters_skip, might_wrap_p,
-						 &iv_step);
+						 &iv_step, &compare_step);
 
 	    iv_rgc = rgc;
 	  }
@@ -884,11 +887,22 @@ vect_set_loop_condition_partial_vectors (class loop *loop,
 
   /* Get a boolean result that tells us whether to iterate.  */
   edge exit_edge = single_exit (loop);
-  tree_code code = (exit_edge->flags & EDGE_TRUE_VALUE) ? EQ_EXPR : NE_EXPR;
+  gcond *cond_stmt;
   tree zero_ctrl = build_zero_cst (TREE_TYPE (test_ctrl));
-  gcond *cond_stmt = gimple_build_cond (code, test_ctrl, zero_ctrl,
-					NULL_TREE, NULL_TREE);
-  gsi_insert_before (&loop_cond_gsi, cond_stmt, GSI_SAME_STMT);
+  if (LOOP_VINFO_USING_DECREMENTING_IV_P (loop_vinfo))
+    {
+      gcc_assert (compare_step);
+      cond_stmt = gimple_build_cond (GT_EXPR, test_ctrl, compare_step,
+				     NULL_TREE, NULL_TREE);
+      gsi_insert_before (&loop_cond_gsi, cond_stmt, GSI_SAME_STMT);
+    }
+  else
+    {
+      tree_code code = (exit_edge->flags & EDGE_TRUE_VALUE) ? EQ_EXPR : NE_EXPR;
+      cond_stmt
+	= gimple_build_cond (code, test_ctrl, zero_ctrl, NULL_TREE, NULL_TREE);
+      gsi_insert_before (&loop_cond_gsi, cond_stmt, GSI_SAME_STMT);
+    }
 
   /* The loop iterates (NITERS - 1) / VF + 1 times.
      Subtract one from this to get the latch count.  */
-- 
2.36.1


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

end of thread, other threads:[~2023-05-31 12:17 UTC | newest]

Thread overview: 26+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-30 11:28 [PATCH] VECT: Change flow of decrement IV juzhe.zhong
2023-05-30 11:31 ` Richard Sandiford
2023-05-30 11:36   ` juzhe.zhong
2023-05-30 11:41     ` Richard Sandiford
     [not found]     ` <5C7770CA9FB40F7E+8BE427DD-97DA-4B93-A73A-8CDD1D92089B@rivai.ai>
2023-05-30 12:01       ` Richard Sandiford
     [not found]     ` <685EE879E20B3272+6338EB42-0A9D-4147-993D-99DC8FF7C832@rivai.ai>
2023-05-30 12:33       ` Richard Biener
2023-05-30 12:37         ` 钟居哲
     [not found]           ` <FA43CAC5-BCCE-42AF-8A6B-E69F1A496F5C@suse.de>
2023-05-30 22:51             ` 钟居哲
2023-05-30 14:13         ` 钟居哲
2023-05-30 14:47         ` 钟居哲
2023-05-30 15:05         ` 钟居哲
2023-05-31  1:42           ` juzhe.zhong
2023-05-31  6:41             ` Richard Biener
2023-05-31  6:50               ` juzhe.zhong
2023-05-31  7:38                 ` Kewen.Lin
2023-05-31  7:50                   ` juzhe.zhong
2023-05-31  7:28               ` Richard Sandiford
2023-05-31  7:36                 ` juzhe.zhong
2023-05-31  8:44                   ` Richard Biener
2023-05-31  7:38                 ` Richard Biener
2023-05-31  7:49                   ` juzhe.zhong
2023-05-31  9:01                   ` Richard Sandiford
2023-05-31  9:30                     ` juzhe.zhong
2023-05-31 10:53                       ` Richard Biener
2023-05-31 12:16                         ` 钟居哲
2023-05-30 11:38   ` juzhe.zhong

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).