aboutsummaryrefslogtreecommitdiff
path: root/gcc/tree-vect-loop.cc
diff options
context:
space:
mode:
authorHao Liu OS <hliu@os.amperecomputing.com>2023-07-06 10:04:46 -0600
committerJeff Law <jlaw@ventanamicro.com>2023-07-06 10:04:46 -0600
commit224fd59b2dc8a5fa78a309a09863afe9b3cf2111 (patch)
tree4c78a652002dcf12e2e24c935e5e240fbcae5115 /gcc/tree-vect-loop.cc
parentb90a70984a9beee39b41f842b56926f9db2069ca (diff)
downloadgcc-224fd59b2dc8a5fa78a309a09863afe9b3cf2111.zip
gcc-224fd59b2dc8a5fa78a309a09863afe9b3cf2111.tar.gz
gcc-224fd59b2dc8a5fa78a309a09863afe9b3cf2111.tar.bz2
Vect: use a small step to calculate induction for the unrolled loop (PR tree-optimization/110449)
If a loop is unrolled by n times during vectoriation, two steps are used to calculate the induction variable: - The small step for the unrolled ith-copy: vec_1 = vec_iv + (VF/n * Step) - The large step for the whole loop: vec_loop = vec_iv + (VF * Step) This patch calculates an extra vec_n to replace vec_loop: vec_n = vec_prev + (VF/n * S) = vec_iv + (VF/n * S) * n = vec_loop. So that we can save the large step register and related operations. gcc/ChangeLog: PR tree-optimization/110449 * tree-vect-loop.cc (vectorizable_induction): use vec_n to replace vec_loop for the unrolled loop. gcc/testsuite/ChangeLog: * gcc.target/aarch64/pr110449.c: New testcase.
Diffstat (limited to 'gcc/tree-vect-loop.cc')
-rw-r--r--gcc/tree-vect-loop.cc21
1 files changed, 18 insertions, 3 deletions
diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index 36d19a5..7d917bf 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -10098,7 +10098,7 @@ vectorizable_induction (loop_vec_info loop_vinfo,
new_vec, step_vectype, NULL);
vec_def = induc_def;
- for (i = 1; i < ncopies; i++)
+ for (i = 1; i < ncopies + 1; i++)
{
/* vec_i = vec_prev + vec_step */
gimple_seq stmts = NULL;
@@ -10108,8 +10108,23 @@ vectorizable_induction (loop_vec_info loop_vinfo,
vec_def = gimple_convert (&stmts, vectype, vec_def);
gsi_insert_seq_before (&si, stmts, GSI_SAME_STMT);
- new_stmt = SSA_NAME_DEF_STMT (vec_def);
- STMT_VINFO_VEC_STMTS (stmt_info).safe_push (new_stmt);
+ if (i < ncopies)
+ {
+ new_stmt = SSA_NAME_DEF_STMT (vec_def);
+ STMT_VINFO_VEC_STMTS (stmt_info).safe_push (new_stmt);
+ }
+ else
+ {
+ /* vec_1 = vec_iv + (VF/n * S)
+ vec_2 = vec_1 + (VF/n * S)
+ ...
+ vec_n = vec_prev + (VF/n * S) = vec_iv + VF * S = vec_loop
+
+ vec_n is used as vec_loop to save the large step register and
+ related operations. */
+ add_phi_arg (induction_phi, vec_def, loop_latch_edge (iv_loop),
+ UNKNOWN_LOCATION);
+ }
}
}