public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/kubaneko/heads/histogram)] Use histogram in loop vectorizer heuristics
@ 2023-05-01 22:14 Jan Hubicka
0 siblings, 0 replies; only message in thread
From: Jan Hubicka @ 2023-05-01 22:14 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:e4287fa88d78d5569ad8948378bf7d4395b6f157
commit e4287fa88d78d5569ad8948378bf7d4395b6f157
Author: Honza <jh@ryzen3.suse.cz>
Date: Tue May 2 00:13:52 2023 +0200
Use histogram in loop vectorizer heuristics
Diff:
---
gcc/tree-ssa-loop-ivcanon.cc | 1 +
gcc/tree-vect-loop.cc | 33 ++++++++++++++++++++++++++++++++-
2 files changed, 33 insertions(+), 1 deletion(-)
diff --git a/gcc/tree-ssa-loop-ivcanon.cc b/gcc/tree-ssa-loop-ivcanon.cc
index d5a10bb5aff..1fde151551b 100644
--- a/gcc/tree-ssa-loop-ivcanon.cc
+++ b/gcc/tree-ssa-loop-ivcanon.cc
@@ -1115,6 +1115,7 @@ try_peel_loop (class loop *loop,
gcov_type rest = sum;
gcov_type psum = 0;
int good_percentage = param_profile_histogram_peel_prcnt;
+ /* TODO: Fix. Profile size needs to be stored in the counters. */
for (int i = 0; i < param_profile_histogram_size_lin; i++)
{
psum += (*(loop->counters->hist))[i];
diff --git a/gcc/tree-vect-loop.cc b/gcc/tree-vect-loop.cc
index c172b466809..140bafad28c 100644
--- a/gcc/tree-vect-loop.cc
+++ b/gcc/tree-vect-loop.cc
@@ -2070,6 +2070,37 @@ vect_analyze_loop_costing (loop_vec_info loop_vinfo,
return 0;
}
+ bool use_estimate = true;
+ /* With histogram we can determine how often the vectorized loop will be
+ reached. */
+ if (loop->counters
+ /* TODO: For epilogue we can compute new histogram. */
+ && !LOOP_VINFO_EPILOGUE_P (loop_vinfo)
+ && loop->counters->sum
+ /* TODO: Fix. Profile size needs to be stored in the counters. */
+ && min_profitable_estimate <= param_profile_histogram_size_lin)
+ {
+ gcov_type psum = 0;
+ for (int i = 0; i < min_profitable_estimate; i++)
+ psum += (*(loop->counters->hist))[i];
+ /* TODO: This is less precise than needed. If histogram was also
+ storing number of executions of the loop header (which may
+ be different from loop->header->count if i.e. inlining happen).
+ We could compute expected nunber of execution of the vectorized
+ loop. */
+ if (psum == loop->counters->sum
+ || !maybe_hot_count_p (cfun, loop->header->count.apply_scale
+ (loop->counters->sum - psum,
+ loop->counters->sum)))
+ {
+ dump_printf_loc (MSG_MISSED_OPTIMIZATION, vect_location,
+ "not vectorized: according to loop histogram "
+ "the vectorized loop would be cold.\n");
+ return 0;
+ }
+ use_estimate = false;
+ }
+
HOST_WIDE_INT estimated_niter;
/* If we are vectorizing an epilogue then we know the maximum number of
@@ -2078,7 +2109,7 @@ vect_analyze_loop_costing (loop_vec_info loop_vinfo,
if (LOOP_VINFO_EPILOGUE_P (loop_vinfo))
estimated_niter
= vect_vf_for_cost (LOOP_VINFO_ORIG_LOOP_INFO (loop_vinfo)) - 1;
- else
+ else if (use_estimate)
{
estimated_niter = estimated_stmt_executions_int (loop);
if (estimated_niter == -1)
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-05-01 22:14 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-05-01 22:14 [gcc(refs/users/kubaneko/heads/histogram)] Use histogram in loop vectorizer heuristics Jan Hubicka
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).