]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
VECT: Add tree_code into "creat_iv" and allow it can handle MINUS_EXPR IV
authorPan Li <pan2.li@intel.com>
Thu, 11 May 2023 10:50:56 +0000 (18:50 +0800)
committerPan Li <pan2.li@intel.com>
Thu, 11 May 2023 11:06:44 +0000 (19:06 +0800)
This patch is going to be commited after bootstrap && regression on X86
PASSED.

Thanks Richards.

gcc/ChangeLog:

* cfgloopmanip.cc (create_empty_loop_on_edge): Add PLUS_EXPR.
* gimple-loop-interchange.cc
(tree_loop_interchange::map_inductions_to_loop): Ditto.
* tree-ssa-loop-ivcanon.cc (create_canonical_iv): Ditto.
* tree-ssa-loop-ivopts.cc (create_new_iv): Ditto.
* tree-ssa-loop-manip.cc (create_iv): Ditto.
(tree_transform_and_unroll_loop): Ditto.
(canonicalize_loop_ivs): Ditto.
* tree-ssa-loop-manip.h (create_iv): Ditto.
* tree-vect-data-refs.cc (vect_create_data_ref_ptr): Ditto.
* tree-vect-loop-manip.cc (vect_set_loop_controls_directly):
Ditto.
(vect_set_loop_condition_normal): Ditto.
* tree-vect-loop.cc (vect_create_epilog_for_reduction): Ditto.
* tree-vect-stmts.cc (vectorizable_store): Ditto.
(vectorizable_load): Ditto.

Signed-off-by: Juzhe Zhong <juzhe.zhong@rivai.ai>
gcc/cfgloopmanip.cc
gcc/gimple-loop-interchange.cc
gcc/tree-ssa-loop-ivcanon.cc
gcc/tree-ssa-loop-ivopts.cc
gcc/tree-ssa-loop-manip.cc
gcc/tree-ssa-loop-manip.h
gcc/tree-vect-data-refs.cc
gcc/tree-vect-loop-manip.cc
gcc/tree-vect-loop.cc
gcc/tree-vect-stmts.cc

index 0e3ad8ed742afc16ff73e5c3015609aec37361eb..6e09dcbb0b1864bc64ffd570a4b923f50c3819b5 100644 (file)
@@ -826,7 +826,7 @@ create_empty_loop_on_edge (edge entry_edge,
     }
 
   gsi = gsi_last_bb (loop_header);
-  create_iv (initial_value, stride, iv, loop, &gsi, false,
+  create_iv (initial_value, PLUS_EXPR, stride, iv, loop, &gsi, false,
             iv_before, iv_after);
 
   /* Insert loop exit condition.  */
index 1b77bfd46b2068ac6dcc7ca3b3aefe679ae0ef30..e5590374e5921f43dbe590487f610308162f9b35 100644 (file)
@@ -1185,7 +1185,7 @@ tree_loop_interchange::map_inductions_to_loop (loop_cand &src, loop_cand &tgt)
          tree var_before, var_after;
          tree base = unshare_expr (iv->init_expr);
          tree step = unshare_expr (iv->step);
-         create_iv (base, step, SSA_NAME_VAR (iv->var),
+         create_iv (base, PLUS_EXPR, step, SSA_NAME_VAR (iv->var),
                     tgt.m_loop, &incr_pos, false, &var_before, &var_after);
          bitmap_set_bit (m_dce_seeds, SSA_NAME_VERSION (var_before));
          bitmap_set_bit (m_dce_seeds, SSA_NAME_VERSION (var_after));
index f678de41cb083b525b16767e49bec6a94a8e9dff..6a962a9f5030794052e2846ad3ee7e72d29873bf 100644 (file)
@@ -113,7 +113,7 @@ create_canonical_iv (class loop *loop, edge exit, tree niter,
                       niter,
                       build_int_cst (type, 1));
   incr_at = gsi_last_bb (in->src);
-  create_iv (niter,
+  create_iv (niter, PLUS_EXPR,
             build_int_cst (type, -1),
             NULL_TREE, loop,
             &incr_at, false, var_before, &var);
index 324703054b5d9470ee9118bcbad7169d0618253b..6fbd2d5931892a1995fa629659cc96c8dd624512 100644 (file)
@@ -7267,7 +7267,7 @@ create_new_iv (struct ivopts_data *data, struct iv_cand *cand)
 
   base = unshare_expr (cand->iv->base);
 
-  create_iv (base, unshare_expr (cand->iv->step),
+  create_iv (base, PLUS_EXPR, unshare_expr (cand->iv->step),
             cand->var_before, data->current_loop,
             &incr_pos, after, &cand->var_before, &cand->var_after);
 }
index 598e2189f6cb956fff402e1c7d31c028e7440c7c..f336d22243346ba865c2f48fa7d802debb9a9ea6 100644 (file)
@@ -47,7 +47,9 @@ along with GCC; see the file COPYING3.  If not see
    so that we can free them all at once.  */
 static bitmap_obstack loop_renamer_obstack;
 
-/* Creates an induction variable with value BASE + STEP * iteration in LOOP.
+/* Creates an induction variable with value BASE (+/-) STEP * iteration in LOOP.
+   If INCR_OP is PLUS_EXPR, the induction variable is BASE + STEP * iteration.
+   If INCR_OP is MINUS_EXPR, the induction variable is BASE - STEP * iteration.
    It is expected that neither BASE nor STEP are shared with other expressions
    (unless the sharing rules allow this).  Use VAR as a base var_decl for it
    (if NULL, a new temporary will be created).  The increment will occur at
@@ -57,16 +59,16 @@ static bitmap_obstack loop_renamer_obstack;
    VAR_AFTER (unless they are NULL).  */
 
 void
-create_iv (tree base, tree step, tree var, class loop *loop,
-          gimple_stmt_iterator *incr_pos, bool after,
-          tree *var_before, tree *var_after)
+create_iv (tree base, tree_code incr_op, tree step, tree var, class loop *loop,
+          gimple_stmt_iterator *incr_pos, bool after, tree *var_before,
+          tree *var_after)
 {
   gassign *stmt;
   gphi *phi;
   tree initial, step1;
   gimple_seq stmts;
   tree vb, va;
-  enum tree_code incr_op = PLUS_EXPR;
+  gcc_assert (incr_op == PLUS_EXPR || incr_op == MINUS_EXPR);
   edge pe = loop_preheader_edge (loop);
 
   if (var != NULL_TREE)
@@ -93,7 +95,7 @@ create_iv (tree base, tree step, tree var, class loop *loop,
          step1 = fold_build1 (NEGATE_EXPR, TREE_TYPE (step), step);
          if (tree_int_cst_lt (step1, step))
            {
-             incr_op = MINUS_EXPR;
+             incr_op = (incr_op == PLUS_EXPR ? MINUS_EXPR : PLUS_EXPR);
              step = step1;
            }
        }
@@ -104,7 +106,7 @@ create_iv (tree base, tree step, tree var, class loop *loop,
          if (!tree_expr_nonnegative_warnv_p (step, &ovf)
              && may_negate_without_overflow_p (step))
            {
-             incr_op = MINUS_EXPR;
+             incr_op = (incr_op == PLUS_EXPR ? MINUS_EXPR : PLUS_EXPR);
              step = fold_build1 (NEGATE_EXPR, TREE_TYPE (step), step);
            }
        }
@@ -1365,7 +1367,7 @@ tree_transform_and_unroll_loop (class loop *loop, unsigned factor,
       tree ctr_before, ctr_after;
       gimple_stmt_iterator bsi = gsi_last_nondebug_bb (new_exit->src);
       exit_if = as_a <gcond *> (gsi_stmt (bsi));
-      create_iv (exit_base, exit_step, NULL_TREE, loop,
+      create_iv (exit_base, PLUS_EXPR, exit_step, NULL_TREE, loop,
                 &bsi, false, &ctr_before, &ctr_after);
       gimple_cond_set_code (exit_if, exit_cmp);
       gimple_cond_set_lhs (exit_if, ctr_after);
@@ -1580,8 +1582,8 @@ canonicalize_loop_ivs (class loop *loop, tree *nit, bool bump_in_latch)
     gsi = gsi_last_bb (loop->latch);
   else
     gsi = gsi_last_nondebug_bb (loop->header);
-  create_iv (build_int_cst_type (type, 0), build_int_cst (type, 1), NULL_TREE,
-            loop, &gsi, bump_in_latch, &var_before, NULL);
+  create_iv (build_int_cst_type (type, 0), PLUS_EXPR, build_int_cst (type, 1),
+            NULL_TREE, loop, &gsi, bump_in_latch, &var_before, NULL);
 
   rewrite_all_phi_nodes_with_iv (loop, var_before);
 
index d49273a39874762b4e80a004f022a197df5e2e63..bda09f51d5619420331c513a9906831c779fd2b4 100644 (file)
@@ -22,8 +22,8 @@ along with GCC; see the file COPYING3.  If not see
 
 typedef void (*transform_callback)(class loop *, void *);
 
-extern void create_iv (tree, tree, tree, class loop *, gimple_stmt_iterator *,
-                      bool, tree *, tree *);
+extern void create_iv (tree, tree_code, tree, tree, class loop *,
+                      gimple_stmt_iterator *, bool, tree *, tree *);
 extern void rewrite_into_loop_closed_ssa (bitmap, unsigned);
 extern void verify_loop_closed_ssa (bool, class loop * = NULL);
 
index 6721ab6efc4f029be8e2315c31ba87d94230cda5..5c9103b16e594e48311832557ada568e10cc8623 100644 (file)
@@ -5099,7 +5099,7 @@ vect_create_data_ref_ptr (vec_info *vinfo, stmt_vec_info stmt_info,
 
       standard_iv_increment_position (loop, &incr_gsi, &insert_after);
 
-      create_iv (aggr_ptr_init,
+      create_iv (aggr_ptr_init, PLUS_EXPR,
                 fold_convert (aggr_ptr_type, iv_step),
                 aggr_ptr, loop, &incr_gsi, insert_after,
                 &indx_before_incr, &indx_after_incr);
@@ -5129,9 +5129,9 @@ vect_create_data_ref_ptr (vec_info *vinfo, stmt_vec_info stmt_info,
     {
       standard_iv_increment_position (containing_loop, &incr_gsi,
                                      &insert_after);
-      create_iv (aptr, fold_convert (aggr_ptr_type, DR_STEP (dr)), aggr_ptr,
-                containing_loop, &incr_gsi, insert_after, &indx_before_incr,
-                &indx_after_incr);
+      create_iv (aptr, PLUS_EXPR, fold_convert (aggr_ptr_type, DR_STEP (dr)),
+                aggr_ptr, containing_loop, &incr_gsi, insert_after,
+                &indx_before_incr, &indx_after_incr);
       incr = gsi_stmt (incr_gsi);
 
       /* Copy the points-to information if it exists. */
index 44bd5f2c805776110c33f8432044dd19ca4f36ec..ff6159e08d58f67e1f2d1bbddc0234d179b11b6c 100644 (file)
@@ -468,8 +468,9 @@ vect_set_loop_controls_directly (class loop *loop, loop_vec_info loop_vinfo,
   gimple_stmt_iterator incr_gsi;
   bool insert_after;
   standard_iv_increment_position (loop, &incr_gsi, &insert_after);
-  create_iv (build_int_cst (iv_type, 0), nitems_step, NULL_TREE, loop,
-            &incr_gsi, insert_after, &index_before_incr, &index_after_incr);
+  create_iv (build_int_cst (iv_type, 0), PLUS_EXPR, nitems_step, NULL_TREE,
+            loop, &incr_gsi, insert_after, &index_before_incr,
+            &index_after_incr);
 
   tree zero_index = build_int_cst (compare_type, 0);
   tree test_index, test_limit, first_limit;
@@ -893,7 +894,7 @@ vect_set_loop_condition_normal (class loop *loop, tree niters, tree step,
     }
 
   standard_iv_increment_position (loop, &incr_gsi, &insert_after);
-  create_iv (init, step, NULL_TREE, loop,
+  create_iv (init, PLUS_EXPR, step, NULL_TREE, loop,
              &incr_gsi, insert_after, &indx_before_incr, &indx_after_incr);
   indx_after_incr = force_gimple_operand_gsi (&loop_cond_gsi, indx_after_incr,
                                              true, NULL_TREE, true,
index 6ea0f21fd1303febb6dfb69381cc01d50bb73554..ed0166fedab356d3eef546a059477e17fab27fa5 100644 (file)
@@ -5567,7 +5567,7 @@ vect_create_epilog_for_reduction (loop_vec_info loop_vinfo,
       gimple_stmt_iterator incr_gsi;
       bool insert_after;
       standard_iv_increment_position (loop, &incr_gsi, &insert_after);
-      create_iv (series_vect, vec_step, NULL_TREE, loop, &incr_gsi,
+      create_iv (series_vect, PLUS_EXPR, vec_step, NULL_TREE, loop, &incr_gsi,
                 insert_after, &indx_before_incr, &indx_after_incr);
 
       /* Next create a new phi node vector (NEW_PHI_TREE) which starts
index 61a2da4ecee9c449c1469cab3c4cfa1a782471d5..7313191b0db8fdae696b6c6a55a8a0724423837c 100644 (file)
@@ -8286,7 +8286,7 @@ vectorizable_store (vec_info *vinfo,
 
       stride_base = cse_and_gimplify_to_preheader (loop_vinfo, stride_base);
       ivstep = cse_and_gimplify_to_preheader (loop_vinfo, ivstep);
-      create_iv (stride_base, ivstep, NULL,
+      create_iv (stride_base, PLUS_EXPR, ivstep, NULL,
                 loop, &incr_gsi, insert_after,
                 &offvar, NULL);
       incr = gsi_stmt (incr_gsi);
@@ -9457,7 +9457,7 @@ vectorizable_load (vec_info *vinfo,
 
       stride_base = cse_and_gimplify_to_preheader (loop_vinfo, stride_base);
       ivstep = cse_and_gimplify_to_preheader (loop_vinfo, ivstep);
-      create_iv (stride_base, ivstep, NULL,
+      create_iv (stride_base, PLUS_EXPR, ivstep, NULL,
                 loop, &incr_gsi, insert_after,
                 &offvar, NULL);