[gcc r16-6133] vect: Relax known iteration number constraint
Victor Do Nascimento
victorldn@gcc.gnu.org
Mon Dec 15 15:29:12 GMT 2025
https://gcc.gnu.org/g:ca8d97f8cb8d282c190183e9c297d5e0490bab4e
commit r16-6133-gca8d97f8cb8d282c190183e9c297d5e0490bab4e
Author: Victor Do Nascimento <victor.donascimento@arm.com>
Date: Thu May 8 15:28:05 2025 +0100
vect: Relax known iteration number constraint
At present we reject uncounted loops outright when doing initial loop
analysis in `vect_analyze_loop_form'.
We have the following gating condition that causes rejection of a
given loop:
if (integer_zerop (info->assumptions)
|| !info->number_of_iterations
|| chrec_contains_undetermined (info->number_of_iterations))
We can do away with this check altogether, but not without problems,
allowing many malformed loops through which ought to be rejected as
early as possible.
We observe that a common thread running through these malformed loops
is the absence of any scalar evolution between iterations.
We have therefore adjusted the analysis replacing the checks on
`niters' for a test for the presence of scalar evolution in the loop,
which can be detected via the presence of phi nodes in the loop.
gcc/ChangeLog:
* tree-vect-loop.cc (vect_analyze_loop_form): Relax niters
condition.
Diff:
---
gcc/tree-vect-loop.cc | 31 ++++++++++++++++++++++++++++---
1 file changed, 28 insertions(+), 3 deletions(-)
diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index 9b435c78c21b..00b21ecfc958 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -1473,6 +1473,20 @@ vect_analyze_loop_form (class loop *loop, gimple *loop_vectorized_call,
"not vectorized:"
" unsupported control flow in loop.\n");
}
+
+ /* Check if we have any control flow that doesn't leave the loop. */
+ bool has_phi = false;
+ for (unsigned i = 0; i < loop->num_nodes; i++)
+ if (!gimple_seq_empty_p (phi_nodes (bbs[i])))
+ {
+ has_phi = true;
+ break;
+ }
+ if (!has_phi)
+ return opt_result::failure_at (vect_location,
+ "not vectorized:"
+ " no scalar evolution detected in loop.\n");
+
free (bbs);
/* Different restrictions apply when we are considering an inner-most loop,
@@ -1597,9 +1611,20 @@ vect_analyze_loop_form (class loop *loop, gimple *loop_vectorized_call,
std::swap (info->conds[0], info->conds[i]);
}
- if (integer_zerop (info->assumptions)
- || !info->number_of_iterations
- || chrec_contains_undetermined (info->number_of_iterations))
+ if (chrec_contains_undetermined (info->number_of_iterations))
+ {
+ if (dump_enabled_p ())
+ dump_printf_loc (MSG_NOTE, vect_location,
+ "Loop being analyzed as uncounted.\n");
+ if (loop->inner)
+ return opt_result::failure_at
+ (vect_location,
+ "not vectorized: outer loop vectorization of uncounted loops"
+ " is unsupported.\n");
+ return opt_result::success ();
+ }
+
+ if (integer_zerop (info->assumptions))
return opt_result::failure_at
(info->conds[0],
"not vectorized: number of iterations cannot be computed.\n");
More information about the Gcc-cvs
mailing list