From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1075) id 6E8AE3858D1E; Mon, 1 May 2023 22:14:28 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 6E8AE3858D1E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682979268; bh=MuNE1W4aB7IY/cIZPGsy3AKeLeBYd+VZ+heJuFdXtyU=; h=From:To:Subject:Date:From; b=xG5jQPGI3pD17UEIoJNIgms8clLU17Wj69qK7klsof6kQg+stLpGCLzVnYPYBrRws yf/hUEJ2x2d8XoOHRiE+DkBa8+2q20WqdpkvjwCMQGyFokoRLlBMxuXTsImUr+DvA6 nOTaU9uBf6eQhJKxb88Gk05L6u205GA+YMHBvB04= Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: Jan Hubicka To: gcc-cvs@gcc.gnu.org Subject: [gcc(refs/users/kubaneko/heads/histogram)] Use histogram in loop vectorizer heuristics X-Act-Checkin: gcc X-Git-Author: Honza X-Git-Refname: refs/users/kubaneko/heads/histogram X-Git-Oldrev: b37d3aa26581cc6145ee8be6c82ad81f203f313a X-Git-Newrev: e4287fa88d78d5569ad8948378bf7d4395b6f157 Message-Id: <20230501221428.6E8AE3858D1E@sourceware.org> Date: Mon, 1 May 2023 22:14:28 +0000 (GMT) List-Id: https://gcc.gnu.org/g:e4287fa88d78d5569ad8948378bf7d4395b6f157 commit e4287fa88d78d5569ad8948378bf7d4395b6f157 Author: Honza 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)