This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Avoid negative frequencies and out of range probabilities


Hi,
the roundoff errors or inacuraties in estimated scheduels may drive
us to negative values in frequencies that later causes funny things
to happen.
This patch adds checking for this and avoids them on places they
can be constructed.

Installed to cfg branch, regtested/bootstrapped i386

	* cfgclenaup.c (try_forward_edges, try_crossjump_to_edge):
	Never produce negative counts/frequencies.
	* cfgrtl.c (verify_flow_info): Check frequncies.

Index: cfgcleanup.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cfgcleanup.c,v
retrieving revision 1.18.2.2
diff -c -3 -p -r1.18.2.2 cfgcleanup.c
*** cfgcleanup.c	2001/11/12 17:57:41	1.18.2.2
--- cfgcleanup.c	2001/11/13 15:24:30
*************** try_forward_edges (mode, b)
*** 455,462 ****
--- 455,468 ----
  	    {
  	      edge t;
  	      first->count -= edge_count;
+ 	      if (first->count < 0)
+ 		first->count = 0;
  	      first->succ->count -= edge_count;
+ 	      if (first->succ->count < 0)
+ 		first->succ->count = 0;
  	      first->frequency -= edge_frequency;
+ 	      if (first->frequency < 0)
+ 		first->frequency = 0;
  	      if (first->succ->succ_next)
  		t = threaded_edge;
  	      else
*************** try_crossjump_to_edge (mode, e1, e2)
*** 1134,1141 ****
--- 1140,1153 ----
        if (FORWARDER_BLOCK_P (s2->dest))
  	{
  	  s2->dest->succ->count -= s2->count;
+ 	  if (s2->dest->succ->count < 0)
+ 	    s2->dest->succ->count = 0;
  	  s2->dest->count -= s2->count;
  	  s2->dest->frequency -= EDGE_FREQUENCY (s);
+ 	  if (s2->dest->frequency < 0)
+ 	    s2->dest->frequency = 0;
+ 	  if (s2->dest->count < 0)
+ 	    s2->dest->count = 0;
  	}
        if (!redirect_to->frequency && !src1->frequency)
  	s->probability = (s->probability + s2->probability) / 2;
Index: cfgrtl.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/cfgrtl.c,v
retrieving revision 1.10
diff -c -3 -p -r1.10 cfgrtl.c
*** cfgrtl.c	2001/11/11 11:25:14	1.10
--- cfgrtl.c	2001/11/13 15:24:31
*************** verify_flow_info ()
*** 1582,1594 ****
--- 1582,1619 ----
        int has_fallthru = 0;
        edge e;
  
+       if (bb->count < 0)
+         {
+           error ("verify_flow_info: Wrong count of block %i %i",
+ 	         bb->index, (int)bb->count);
+           err = 1;
+         }
+       if (bb->frequency < 0)
+         {
+           error ("verify_flow_info: Wrong frequency of block %i %i",
+ 	         bb->index, bb->frequency);
+           err = 1;
+         }
        e = bb->succ;
+       e = bb->succ;
        while (e)
  	{
  	  if (last_visited [e->dest->index + 2] == bb)
  	    {
  	      error ("verify_flow_info: Duplicate edge %i->%i",
  		     e->src->index, e->dest->index);
+ 	      err = 1;
+ 	    }
+ 	  if (e->probability < 0 || e->probability > REG_BR_PROB_BASE)
+ 	    {
+ 	      error ("verify_flow_info: Wrong probability of edge %i->%i %i",
+ 		     e->src->index, e->dest->index, e->probability);
+ 	      err = 1;
+ 	    }
+ 	  if (e->count < 0)
+ 	    {
+ 	      error ("verify_flow_info: Wrong count of edge %i->%i %i",
+ 		     e->src->index, e->dest->index, (int)e->count);
  	      err = 1;
  	    }
  	  last_visited [e->dest->index + 2] = bb;


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]