From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7880) id 4245D385840F; Thu, 23 Feb 2023 23:22:58 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 4245D385840F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677194578; bh=2nJ7wxPxTXFBfb+PqYk8QQ7Jk8ZaU9Z+7PjE6BaVntg=; h=From:To:Subject:Date:From; b=elCTIWcCS3YckhkHMjDGx5BE5s5M/+4c8QRPsnJX29FPK4ZTq5/HPAayi7tJVpI7V Jheln2zLBfzceHTLgobSFFa6uQiPSVD0rbHeFASQ2IqU+K0/RPAXL/6qohfr4IGu/o S7qu8JDlHeOsaQCJoL1DfFTVeKvVKJ3SkW826810= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Ondrej Kubanek To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/kubaneko/heads/histogram)] added primitive peeling and stuff X-Act-Checkin: gcc X-Git-Author: kubaneko X-Git-Refname: refs/users/kubaneko/heads/histogram X-Git-Oldrev: 50eb12a4b3ca567a1c019170ee90e1bd7f69993b X-Git-Newrev: 1cf1f75ee797626b86ee0fcb35936726e8f2b801 Message-Id: <20230223232258.4245D385840F@sourceware.org> Date: Thu, 23 Feb 2023 23:22:58 +0000 (GMT) List-Id: https://gcc.gnu.org/g:1cf1f75ee797626b86ee0fcb35936726e8f2b801 commit 1cf1f75ee797626b86ee0fcb35936726e8f2b801 Author: kubaneko Date: Thu Feb 23 17:04:31 2023 +0000 added primitive peeling and stuff Diff: --- gcc/cfgloop.h | 2 +- gcc/tree-profile.cc | 7 +++++-- gcc/tree-ssa-loop-ivcanon.cc | 30 ++++++++++++++++-------------- 3 files changed, 22 insertions(+), 17 deletions(-) diff --git a/gcc/cfgloop.h b/gcc/cfgloop.h index 6c8ff14a3e8..0c9c82c6ed3 100644 --- a/gcc/cfgloop.h +++ b/gcc/cfgloop.h @@ -297,7 +297,7 @@ public: reused. */ basic_block former_header; - histogram_counters* counters=NULL; + histogram_counters* counters; }; /* Set if the loop is known to be infinite. */ diff --git a/gcc/tree-profile.cc b/gcc/tree-profile.cc index 1f2cc3ab5cc..d38ad80ba0f 100644 --- a/gcc/tree-profile.cc +++ b/gcc/tree-profile.cc @@ -170,7 +170,7 @@ gimple_init_gcov_profiler (void) /* void (*) (gcov_type *, gcov_type) */ histogram_profiler_fn_type = build_function_type_list (void_type_node, - gcov_type_ptr, gcov_type_node, + gcov_type_ptr, gcov_type_node, gcov_type_node, NULL_TREE); fn_name = concat ("__gcov_histogram_profiler", fn_suffix, NULL); tree_histogram_profiler_fn = build_fn_decl (fn_name, histogram_profiler_fn_type); @@ -364,11 +364,14 @@ gimple_gen_histogram_profiler (histogram_value value, unsigned tag) // , edge_de auto lp = value->hvalue.lp; gcc_assert(lp); tree ref_ptr = tree_coverage_counter_addr (tag, 0); + tree hist_size = build_int_cst_type (gcov_type_node, + param_profile_histogram_size_lin + (gcov_type(param_profile_histogram_size)<<32)); gcall *call; auto_vec exits = get_loop_exit_edges (lp); for ( auto exit : exits ){ if (!(exit->flags & (EDGE_COMPLEX | EDGE_FAKE))) { - call = gimple_build_call (tree_histogram_profiler_fn, 2, ref_ptr, value->hvalue.value); + call = gimple_build_call (tree_histogram_profiler_fn, 3, ref_ptr, + value->hvalue.value, hist_size); gsi_insert_seq_on_edge (exit, call); } } diff --git a/gcc/tree-ssa-loop-ivcanon.cc b/gcc/tree-ssa-loop-ivcanon.cc index bb95cdd491d..38f947f9e8a 100644 --- a/gcc/tree-ssa-loop-ivcanon.cc +++ b/gcc/tree-ssa-loop-ivcanon.cc @@ -1037,20 +1037,22 @@ try_peel_loop (class loop *loop, npeel = estimated_loop_iterations_int (loop); // linear part most common number - //bool histogram_peeling=loop->counters!=NULL; - //if (histogram_peeling){ - // gcov_type max=0; - // int most_common=-1; - // for (int i=0;i<8; i++){ - // if (loop->counters->hist[i]>=max){ - // most_common=i; - // } - // } - // if (most_common>0) - // { - // npeel=most_common+1; - // } - //} + // peels if in linear portion there is more then 90% of iterations + bool histogram_peeling=loop->counters!=NULL; + if (histogram_peeling){ + gcov_type psum=0; + gcov_type sum=loop->counters->sum; + if (sum!=0){ + for (int i=0;icounters->hist))[i]; + if ((100*psum)/sum>=90) + { + npeel=i; + continue; + } + } + } + } if (npeel < 0) npeel = likely_max_loop_iterations_int (loop);