From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: by sourceware.org (Postfix, from userid 1075) id 11256385840C; Sat, 22 Apr 2023 09:05:22 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 11256385840C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1682154323; bh=a9fnqXkgVLLW/rwQvk8rI3ljE2m8LOazR4AVdooQdh4=; h=From:To:Subject:Date:From; b=dG9olaocdkksswDQ3LBj/zXgCQlorcxubF3GlbBLUpjh6HiOqt9HSZL53fltlnpnl DB8h9fJWwYN1U6nNviobZD95WF+mB4aPklGz+IJW8BYeErABevaH1CzYS7GGlkFrnb pcGBie8bV1Vs4G1C0CCQ/+Wd8xEHxVSBfKlDyKzI= 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)] Improve optimization info on peeling. X-Act-Checkin: gcc X-Git-Author: Honza X-Git-Refname: refs/users/kubaneko/heads/histogram X-Git-Oldrev: 1525af68c65e3f184397d9943ca3dce60ad5e18e X-Git-Newrev: 9acda1e1fddf725b71bce3c817abc0737bcabb23 Message-Id: <20230422090523.11256385840C@sourceware.org> Date: Sat, 22 Apr 2023 09:05:22 +0000 (GMT) List-Id: https://gcc.gnu.org/g:9acda1e1fddf725b71bce3c817abc0737bcabb23 commit 9acda1e1fddf725b71bce3c817abc0737bcabb23 Author: Honza Date: Sat Apr 22 11:05:01 2023 +0200 Improve optimization info on peeling. Diff: --- gcc/tree-ssa-loop-ivcanon.cc | 42 ++++++++++++++++++++++++++++++------------ 1 file changed, 30 insertions(+), 12 deletions(-) diff --git a/gcc/tree-ssa-loop-ivcanon.cc b/gcc/tree-ssa-loop-ivcanon.cc index 90f97d0d3fc..9c8443fd8e6 100644 --- a/gcc/tree-ssa-loop-ivcanon.cc +++ b/gcc/tree-ssa-loop-ivcanon.cc @@ -989,7 +989,7 @@ estimated_peeled_sequence_size (struct loop_size *size, static bool try_peel_loop (class loop *loop, edge exit, tree niter, bool may_be_zero, - HOST_WIDE_INT maxiter) + HOST_WIDE_INT maxiter, dump_user_location_t locus) { HOST_WIDE_INT npeel; struct loop_size size; @@ -1035,10 +1035,25 @@ try_peel_loop (class loop *loop, /* Check if there is an estimate on the number of iterations. */ npeel = estimated_loop_iterations_int (loop); + if (npeel < 0) + npeel = likely_max_loop_iterations_int (loop); + if (npeel >= 0 && maxiter >= 0 && maxiter <= npeel) + { + if (dump_file) + fprintf (dump_file, "Not peeling: upper bound is known so can " + "unroll completely\n"); + return false; + } auto_vec good_peels; auto_vec prcnt; prcnt.safe_push (0); bool histogram_peeling = loop->counters != NULL; + if (!loop->counters && loop->header->count.reliable_p () + && loop->header->count.nonzero_p () + && dump_enabled_p ()) + dump_printf_loc (MSG_MISSED_OPTIMIZATION | MSG_PRIORITY_USER_FACING, locus, + "missing loop histogram for loop %d.\n", loop->num); + HOST_WIDE_INT nonhistogram_npeel = npeel + 1; if (histogram_peeling && loop->counters->sum != 0) { gcov_type sum = loop->counters->sum; @@ -1076,8 +1091,6 @@ try_peel_loop (class loop *loop, } } - if (npeel < 0) - npeel = likely_max_loop_iterations_int (loop); if (npeel < 0) { if (dump_file) @@ -1085,13 +1098,6 @@ try_peel_loop (class loop *loop, "estimated\n"); return false; } - if (maxiter >= 0 && maxiter <= npeel) - { - if (dump_file) - fprintf (dump_file, "Not peeling: upper bound is known so can " - "unroll completely\n"); - return false; - } /* We want to peel estimated number of iterations + 1 (so we never enter the loop on quick path). Check against PARAM_MAX_PEEL_TIMES @@ -1165,7 +1171,19 @@ try_peel_loop (class loop *loop, loop->num, (int) npeel); } - // adjust loop estimates for peeling npeel times + if (dump_enabled_p ()) + { + if (nonhistogram_npeel != npeel) + dump_printf_loc (MSG_OPTIMIZED_LOCATIONS | MSG_PRIORITY_USER_FACING, locus, + "peeled loop %d, %i times using histogram (without histogram would peel %i times).\n", loop->num, (int)npeel, (int)nonhistogram_npeel); + else if (histogram_peeling) + dump_printf_loc (MSG_OPTIMIZED_LOCATIONS | MSG_PRIORITY_USER_FACING, locus, + "peeled loop %d, %i times with histogram.\n", loop->num, (int)npeel); + else + dump_printf_loc (MSG_OPTIMIZED_LOCATIONS | MSG_PRIORITY_USER_FACING, locus, + "peeled loop %d, %i times.\n", loop->num, (int)npeel); + } + adjust_loop_estimates_minus (loop, npeel, true); profile_count entry_count = profile_count::zero (); @@ -1309,7 +1327,7 @@ canonicalize_loop_induction_variables (class loop *loop, create_canonical_iv (loop, exit, iv_niter); } if (ul == UL_ALL) - modified |= try_peel_loop (loop, exit, niter, may_be_zero, maxiter); + modified |= try_peel_loop (loop, exit, niter, may_be_zero, maxiter, locus); return modified; }