public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
From: Jan Hubicka <hubicka@gcc.gnu.org>
To: gcc-cvs@gcc.gnu.org
Subject: [gcc(refs/users/kubaneko/heads/histogram)] Improve optimization info on peeling.
Date: Sat, 22 Apr 2023 09:05:22 +0000 (GMT)	[thread overview]
Message-ID: <20230422090523.11256385840C@sourceware.org> (raw)

https://gcc.gnu.org/g:9acda1e1fddf725b71bce3c817abc0737bcabb23

commit 9acda1e1fddf725b71bce3c817abc0737bcabb23
Author: Honza <jh@ryzen3.suse.cz>
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<int> good_peels;
   auto_vec<int> 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;
 }

                 reply	other threads:[~2023-04-22  9:05 UTC|newest]

Thread overview: [no followups] expand[flat|nested]  mbox.gz  Atom feed

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20230422090523.11256385840C@sourceware.org \
    --to=hubicka@gcc.gnu.org \
    --cc=gcc-cvs@gcc.gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
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).