public inbox for gcc-cvs@sourceware.org
help / color / mirror / Atom feed
* [gcc(refs/users/aoliva/heads/testme)] Cap frequency of recursive calls by 90%
@ 2020-08-06  6:38 Alexandre Oliva
  0 siblings, 0 replies; only message in thread
From: Alexandre Oliva @ 2020-08-06  6:38 UTC (permalink / raw)
  To: gcc-cvs

https://gcc.gnu.org/g:13cdbb6a97c3d853cd380e5a03be8e0d35966c1e

commit 13cdbb6a97c3d853cd380e5a03be8e0d35966c1e
Author: Jan Hubicka <jh@suse.cz>
Date:   Sat Aug 1 17:02:24 2020 +0200

    Cap frequency of recursive calls by 90%
    
            * predict.c (estimate_bb_frequencies): Cap recursive calls by 90%.

Diff:
---
 gcc/predict.c | 25 ++++++++++++++++++++++++-
 1 file changed, 24 insertions(+), 1 deletion(-)

diff --git a/gcc/predict.c b/gcc/predict.c
index a7ae977c866..0a317a7a4ac 100644
--- a/gcc/predict.c
+++ b/gcc/predict.c
@@ -3892,7 +3892,30 @@ estimate_bb_frequencies (bool force)
       cfun->cfg->count_max = profile_count::uninitialized ();
       FOR_BB_BETWEEN (bb, ENTRY_BLOCK_PTR_FOR_FN (cfun), NULL, next_bb)
 	{
-	  sreal tmp = BLOCK_INFO (bb)->frequency * freq_max + sreal (1, -1);
+	  sreal tmp = BLOCK_INFO (bb)->frequency;
+	  if (tmp >= 1)
+	    {
+	      gimple_stmt_iterator gsi;
+	      tree decl;
+
+	      /* Self recursive calls can not have frequency greater than 1
+		 or program will never terminate.  This will result in an
+		 inconsistent bb profile but it is better than greatly confusing
+		 IPA cost metrics.  */
+	      for (gsi = gsi_start_bb (bb); !gsi_end_p (gsi); gsi_next (&gsi))
+		if (is_gimple_call (gsi_stmt (gsi))
+		    && (decl = gimple_call_fndecl (gsi_stmt (gsi))) != NULL
+		    && recursive_call_p (current_function_decl, decl))
+		  {
+		    if (dump_file)
+		      fprintf (dump_file, "Dropping frequency of recursive call"
+			       " in bb %i from %f\n", bb->index,
+			       tmp.to_double ());
+		    tmp = (sreal)9 / (sreal)10;
+		    break;
+		  }
+	    }
+	  tmp = tmp * freq_max + sreal (1, -1);
 	  profile_count count = profile_count::from_gcov_type (tmp.to_int ());	
 
 	  /* If we have profile feedback in which this function was never


^ permalink raw reply	[flat|nested] only message in thread

only message in thread, other threads:[~2020-08-06  6:38 UTC | newest]

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2020-08-06  6:38 [gcc(refs/users/aoliva/heads/testme)] Cap frequency of recursive calls by 90% Alexandre Oliva

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).