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]

Re: Bug in edge redirection code


> On Thu, Jul 26, 2001 at 07:28:44PM +0200, Jan Hubicka wrote:
> > +       gcov_type edge_count;
> > +       int edge_frequency;
> [...]
> > ! 	  edge_count = e->count;
> > ! 	  edge_frequency = ((e->probability * b->frequency + REG_BR_PROB_BASE / 2)
> > ! 			    / REG_BR_PROB_BASE);
> > ! 	  if (redirect_edge_and_branch (e, target))
> 
> Better as
> 
>     else
>       {
> 	gcov_type edge_count = e->count
> 	int edge_probability = e->probability;
> 
> 	if (redirect_edge_and_branch (e, target))
> 	  {
> 	    ...
.. or this combination.  I would like to see the multiplication and memory
access out of the internal loop.
Compiler is hardly going to be able to distringuish source BB from the
others.

Thu Jul 26 19:27:45 CEST 2001  Jan Hubicka  <jh@suse.cz>
	* flow.c (try_forward_edges): Avoid accessing freed memory.

Index: flow.c
===================================================================
RCS file: /cvs/gcc/egcs/gcc/flow.c,v
retrieving revision 1.442
diff -c -3 -p -r1.442 flow.c
*** flow.c	2001/07/25 20:51:24	1.442
--- flow.c	2001/07/26 17:56:55
*************** try_forward_edges (b)
*** 3133,3161 ****
  	}
        else if (target == first)
  	; /* We didn't do anything.  */
!       else if (redirect_edge_and_branch (e, target))
  	{
! 	  /* We successfully forwarded the edge.  Now update profile
! 	     data: for each edge we traversed in the chain, remove
! 	     the original edge's execution count.  */
! 	  do
  	    {
! 	      first->count -= e->count;
! 	      first->succ->count -= e->count;
! 	      first->frequency -= ((e->probability * b->frequency
! 				    + REG_BR_PROB_BASE / 2)
! 				   / REG_BR_PROB_BASE);
! 	      first = first->succ->dest;
! 	    }
! 	  while (first != target);
  
! 	  changed = true;
! 	}
!       else
! 	{
! 	  if (rtl_dump_file)
! 	    fprintf (rtl_dump_file, "Forwarding edge %i->%i to %i failed.\n",
! 		     b->index, e->dest->index, target->index);
  	}
      }
  
--- 3133,3170 ----
  	}
        else if (target == first)
  	; /* We didn't do anything.  */
!       else
  	{
! 	  /* Save the values now, as the edge may get removed.  */
! 	  gcov_type edge_count = e->count;
! 	  int edge_probability = e->probability;
! 
! 	  if (redirect_edge_and_branch (e, target))
  	    {
! 	      /* We successfully forwarded the edge.  Now update profile
! 		 data: for each edge we traversed in the chain, remove
! 		 the original edge's execution count.  */
! 	      int edge_frequency = ((edge_probability * b->frequency
! 				     + REG_BR_PROB_BASE / 2)
! 				    / REG_BR_PROB_BASE);
  
! 	      do
! 		{
! 		  first->count -= edge_count;
! 		  first->succ->count -= edge_count;
! 		  first->frequency -= edge_frequency;
! 		  first = first->succ->dest;
! 		}
! 	      while (first != target);
! 
! 	      changed = true;
! 	    }
! 	  else
! 	    {
! 	      if (rtl_dump_file)
! 		fprintf (rtl_dump_file, "Forwarding edge %i->%i to %i failed.\n",
! 			 b->index, e->dest->index, target->index);
! 	    }
  	}
      }
  


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