public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/kubaneko/heads/histogram)] extracted adjust_loop_estimates_minus
@ 2023-04-07 18:04 Ondrej Kubanek
0 siblings, 0 replies; only message in thread
From: Ondrej Kubanek @ 2023-04-07 18:04 UTC (permalink / raw)
To: gcc-cvs
https://gcc.gnu.org/g:03be06fc3fb7a7242825de72132c37caec2d3ee6
commit 03be06fc3fb7a7242825de72132c37caec2d3ee6
Author: kubaneko <kubanek0ondrej@gmail.com>
Date: Fri Apr 7 18:04:30 2023 +0000
extracted adjust_loop_estimates_minus
Diff:
---
gcc/cfgloop.cc | 42 +++++++++++++++++++++++++++++++++++++++---
gcc/cfgloop.h | 1 +
gcc/tree-ssa-loop-ivcanon.cc | 35 +++++------------------------------
3 files changed, 45 insertions(+), 33 deletions(-)
diff --git a/gcc/cfgloop.cc b/gcc/cfgloop.cc
index 3b31792551f..32ff0959ae9 100644
--- a/gcc/cfgloop.cc
+++ b/gcc/cfgloop.cc
@@ -2210,8 +2210,9 @@ unsigned int hist_index(gcov_type_unsigned val){
}
}
-void histogram_counters_minus_upper_bound (histogram_counters* hist_c, gcov_type_unsigned difference){
- if (!hist_c || difference==0)
+void histogram_counters_minus_upper_bound (histogram_counters* hist_c,
+ gcov_type_unsigned difference){
+ if (difference==0 || hist_c->sum==0)
return;
auto& hist=*(hist_c->hist);
hist_c->adjusted=true;
@@ -2259,7 +2260,7 @@ void histogram_counters_minus_upper_bound (histogram_counters* hist_c, gcov_type
}
void histogram_counters_div_upper_bound (histogram_counters* hist_c, unsigned int divisor){
- if (hist_c==NULL || divisor<2)
+ if (hist_c->sum==0 || divisor<2)
return;
auto& hist=*(hist_c->hist);
hist_c->adjusted=true;
@@ -2278,4 +2279,39 @@ void histogram_counters_div_upper_bound (histogram_counters* hist_c, unsigned in
hist[ind]+=hist[i];
hist[i]=0;
}
+
+}
+
+// adjust estimates after peeling npeel times
+// also used in copy header optimization
+void adjust_loop_estimates_minus ( class loop* loop, unsigned HOST_WIDE_INT npeel)
+{
+ if (loop->any_estimate)
+ {
+ if (wi::ltu_p (npeel, loop->nb_iterations_estimate))
+ loop->nb_iterations_estimate -= npeel;
+ else
+ loop->nb_iterations_estimate = 0;
+ }
+ if (loop->any_upper_bound)
+ {
+ if (wi::ltu_p (npeel, loop->nb_iterations_upper_bound))
+ loop->nb_iterations_upper_bound -= npeel;
+ else
+ loop->nb_iterations_upper_bound = 0;
+ }
+ if (loop->counters){
+ histogram_counters_minus_upper_bound(loop->counters,npeel);
+ }
+ if (loop->any_likely_upper_bound)
+ {
+ if (wi::ltu_p (npeel, loop->nb_iterations_likely_upper_bound))
+ loop->nb_iterations_likely_upper_bound -= npeel;
+ else
+ {
+ loop->any_estimate = true;
+ loop->nb_iterations_estimate = 0;
+ loop->nb_iterations_likely_upper_bound = 0;
+ }
+ }
}
diff --git a/gcc/cfgloop.h b/gcc/cfgloop.h
index 26bb04932bb..99c1dffe09e 100644
--- a/gcc/cfgloop.h
+++ b/gcc/cfgloop.h
@@ -931,6 +931,7 @@ extern int bb_loop_depth (const_basic_block);
extern void histogram_counters_minus_upper_bound
(histogram_counters* hist_c, gcov_type_unsigned difference);
extern void histogram_counters_div_upper_bound (histogram_counters* hist_c, unsigned int divisor);
+extern void adjust_loop_estimates_minus ( class loop* loop, unsigned HOST_WIDE_INT npeel);
/* Converts VAL to widest_int. */
diff --git a/gcc/tree-ssa-loop-ivcanon.cc b/gcc/tree-ssa-loop-ivcanon.cc
index 46722e63a48..37111ea02ac 100644
--- a/gcc/tree-ssa-loop-ivcanon.cc
+++ b/gcc/tree-ssa-loop-ivcanon.cc
@@ -1099,7 +1099,7 @@ try_peel_loop (class loop *loop,
// maybe we need to again tree_estimate_loop_size?
// or wrong loading
while (!good_peels.is_empty() &&
- (estimated_peeled_sequence_size (&size, (int) npeel) > param_max_peeled_insns))
+ ((int)estimated_peeled_sequence_size (&size, (int) npeel) > param_max_peeled_insns))
{
npeel=good_peels.pop();
++npeel;
@@ -1147,35 +1147,9 @@ try_peel_loop (class loop *loop,
fprintf (dump_file, "Peeled loop %d, %i times.\n",
loop->num, (int) npeel);
}
- // ASLJKJLDSADHASDLJASKLDJASLKDJLSAKJDDSALJDSLK
- if (loop->any_estimate)
- {
- if (wi::ltu_p (npeel, loop->nb_iterations_estimate))
- loop->nb_iterations_estimate -= npeel;
- else
- loop->nb_iterations_estimate = 0;
- }
- if (loop->any_upper_bound)
- {
- if (wi::ltu_p (npeel, loop->nb_iterations_upper_bound))
- loop->nb_iterations_upper_bound -= npeel;
- else
- loop->nb_iterations_upper_bound = 0;
- }
- if (loop->counters){
- histogram_counters_minus_upper_bound(loop->counters,npeel);
- }
- if (loop->any_likely_upper_bound)
- {
- if (wi::ltu_p (npeel, loop->nb_iterations_likely_upper_bound))
- loop->nb_iterations_likely_upper_bound -= npeel;
- else
- {
- loop->any_estimate = true;
- loop->nb_iterations_estimate = 0;
- loop->nb_iterations_likely_upper_bound = 0;
- }
- }
+
+ // adjust loop estimates for peeling npeel times
+ adjust_loop_estimates_minus(loop, npeel);
profile_count entry_count = profile_count::zero ();
@@ -1194,6 +1168,7 @@ try_peel_loop (class loop *loop,
bitmap_set_bit (peeled_loops, loop->num);
return true;
}
+
/* Adds a canonical induction variable to LOOP if suitable.
CREATE_IV is true if we may create a new iv. UL determines
which loops we are allowed to completely unroll. If TRY_EVAL is true, we try
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2023-04-07 18:04 UTC | newest]
Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2023-04-07 18:04 [gcc(refs/users/kubaneko/heads/histogram)] extracted adjust_loop_estimates_minus Ondrej Kubanek
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).