public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* Fix ICE in estimate_bb_frequencies
@ 2017-07-18  7:54 Jan Hubicka
  2017-07-18 10:33 ` Markus Trippelsdorf
  0 siblings, 1 reply; 2+ messages in thread
From: Jan Hubicka @ 2017-07-18  7:54 UTC (permalink / raw)
  To: gcc-patches

Hi,
this patch fixes ICE in estimate_bb_frequencies which triggers because we forget
to compute probability for blocks whose count is earlier statically determined to be
0.

Bootstrapped/regtested x86_64-linux, will commit it shortly.

Honza

	PR middle-end/81462
	* predict.c (set_even_probabilities): Cleanup; do not affect
	probabilities that are already known.
	(combine_predictions_for_bb): Call even when count is set.

	* g++.dg/torture/pr81462.C: New testcase.

Index: predict.c
===================================================================
--- predict.c	(revision 250295)
+++ predict.c	(working copy)
@@ -817,16 +817,25 @@ static void
 set_even_probabilities (basic_block bb,
 			hash_set<edge> *unlikely_edges = NULL)
 {
-  unsigned nedges = 0;
+  unsigned nedges = 0, unlikely_count = 0;
   edge e = NULL;
   edge_iterator ei;
+  profile_probability all = profile_probability::always ();
 
   FOR_EACH_EDGE (e, ei, bb->succs)
-    if (!unlikely_executed_edge_p (e))
-      nedges ++;
+    if (e->probability.initialized_p ())
+      all -= e->probability;
+    else if (!unlikely_executed_edge_p (e))
+      {
+        nedges ++;
+        if (unlikely_edges != NULL && unlikely_edges->contains (e))
+	  {
+	    all -= profile_probability::very_unlikely ();
+	    unlikely_count++;
+	  }
+      }
 
   /* Make the distribution even if all edges are unlikely.  */
-  unsigned unlikely_count = unlikely_edges ? unlikely_edges->elements () : 0;
   if (unlikely_count == nedges)
     {
       unlikely_edges = NULL;
@@ -836,13 +845,14 @@ set_even_probabilities (basic_block bb,
   unsigned c = nedges - unlikely_count;
 
   FOR_EACH_EDGE (e, ei, bb->succs)
-    if (!unlikely_executed_edge_p (e))
+    if (e->probability.initialized_p ())
+      ;
+    else if (!unlikely_executed_edge_p (e))
       {
 	if (unlikely_edges != NULL && unlikely_edges->contains (e))
 	  e->probability = profile_probability::very_unlikely ();
 	else
-	  e->probability = profile_probability::guessed_always ()
-				.apply_scale (1, c);
+	  e->probability = all.apply_scale (1, c).guessed ();
       }
     else
       e->probability = profile_probability::never ();
@@ -1151,7 +1161,7 @@ combine_predictions_for_bb (basic_block
 	  if (pred->ep_probability <= PROB_VERY_UNLIKELY)
 	    unlikely_edges.add (pred->ep_edge);
 
-      if (!bb->count.initialized_p () && !dry_run)
+      if (!dry_run)
 	set_even_probabilities (bb, &unlikely_edges);
       clear_bb_predictions (bb);
       if (dump_file)
Index: testsuite/g++.dg/torture/pr81462.C
===================================================================
--- testsuite/g++.dg/torture/pr81462.C	(revision 0)
+++ testsuite/g++.dg/torture/pr81462.C	(working copy)
@@ -0,0 +1,17 @@
+// { dg-do compile }
+// { dg-options "-O1 -fno-ipa-pure-const" }
+struct B {
+        B* self;
+        B() : self( this ) { self->f(); }
+        virtual void f() = 0;
+    };
+
+    struct D : B
+    {
+        void f() {}
+    };
+
+    int main()
+    {
+        D d;
+    }

^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: Fix ICE in estimate_bb_frequencies
  2017-07-18  7:54 Fix ICE in estimate_bb_frequencies Jan Hubicka
@ 2017-07-18 10:33 ` Markus Trippelsdorf
  0 siblings, 0 replies; 2+ messages in thread
From: Markus Trippelsdorf @ 2017-07-18 10:33 UTC (permalink / raw)
  To: Jan Hubicka; +Cc: gcc-patches

On 2017.07.18 at 09:54 +0200, Jan Hubicka wrote:
> Hi,
> this patch fixes ICE in estimate_bb_frequencies which triggers because we forget
> to compute probability for blocks whose count is earlier statically determined to be
> 0.
> 
> Bootstrapped/regtested x86_64-linux, will commit it shortly.

It also fixes both testcases from PR81318.

However the following testcase still ICEs:

trippels@gcc2-power8 linux % cat main.i
int a;
extern void fn4();
__attribute__((__cold__)) void fn1();
void fn2() { fn1(); }
void fn3() {
  fn2();
  if (a)
    fn4();
}

trippels@gcc2-power8 linux % gcc -O2 -c main.i
during GIMPLE pass: profile_estimate
main.i: In function ‘fn3’:
main.i:9:1: internal compiler error: in to_reg_br_prob_base, at profile-count.h:189

-- 
Markus

^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2017-07-18 10:33 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-07-18  7:54 Fix ICE in estimate_bb_frequencies Jan Hubicka
2017-07-18 10:33 ` Markus Trippelsdorf

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