The following makes uncounted loops not profitable to vectorize
unless there's an estimate on the number of iterations, either
from array sizes, overflow, or PGO, that indicates proftiability.
Or trivial profitability, but that's impossible to reach - Tamars
pending patch might change this in some cases.
I have verified that with PGO we do vectorize the testcase in the PR.
PR tree-optimization/123225
* tree-vect-loop.cc (vect_analyze_loop_costing): For uncounted
loops reject not trivially profitable loops that have no
estimate on the number of scalar iterations.
* gcc.dg/vect/costmodel/x86_64/costmodel-pr123225.c: New testcase.
--- /dev/null
+/* { dg-do compile } */
+/* { dg-additional-options "-msse4" } */
+
+short *
+foo (short *arr)
+{
+ unsigned int pos = 0;
+ while(1)
+ {
+ arr++;
+ if (*arr == 0)
+ break;
+ }
+ return arr;
+}
+
+/* { dg-final { scan-tree-dump-not "optimized" "vect" } } */
return -1;
}
+ /* As we cannot use a runtime check to gate profitability for uncounted
+ loops require either an estimate or if none, at least a profitable
+ vectorization within the first vector iteration (that condition
+ will practically never be true due to the required epilog and
+ likely alignment prologue). */
+ if (LOOP_VINFO_NITERS_UNCOUNTED_P (loop_vinfo)
+ && estimated_niter == -1
+ && min_profitable_estimate > (int) vect_vf_for_cost (loop_vinfo))
+ {
+ if (dump_enabled_p ())
+ dump_printf_loc (MSG_NOTE, vect_location,
+ "not vectorized: no loop iteration estimate on the "
+ "uncounted loop and not trivially profitable.\n");
+ return -1;
+ }
+
return 1;
}