From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 7880) id DB489385843D; Thu, 23 Feb 2023 18:38:11 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org DB489385843D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1677177491; bh=N6PVKd5PTGKuNXsoxD+1mW+pqWWRQMthdYW4hX3kd90=; h=From:To:Subject:Date:From; b=Ll+Y2UjrVIpTyeAo9f2lwAIbb2lh5PqO2SAqiJ8EJ3EEI1AX4DslqjuyHj0yD75BS oQNWo0Ej3FeAj+U0+ezEKXLKWZ8BqqWS7wEMjUnVAZG5Pb+uqwKNunVyEq8p/+B8zh J8u0IpTkSFa6QXlnkWH+4Ku+Lc17bDM/CtYmU9l4= 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: 5a66b477b098de4322228e60de94d43f3b85409a X-Git-Newrev: 4bcaa73f688cbd2dc330e60a36cbf4dc8c9537a8 Message-Id: <20230223183811.DB489385843D@sourceware.org> Date: Thu, 23 Feb 2023 18:38:11 +0000 (GMT) List-Id: https://gcc.gnu.org/g:4bcaa73f688cbd2dc330e60a36cbf4dc8c9537a8 commit 4bcaa73f688cbd2dc330e60a36cbf4dc8c9537a8 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 0ee603893e7..187edd30b31 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 95f1f70fd7c..6f4f3712246 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 c36efe28dc2..be489f3197e 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);