[CFG] loop fixes

Jan Hubicka jh@suse.cz
Sat May 4 12:51:00 GMT 2002


Hi,
this patch fixes two minor problems in loop unrolling.
First one is that loop for(i=0;i<5;i++) with '5' known at runtime and profile
feedback is peeled 4 times (as number of iterations is 4) instead of 5 wasting
majority of advantages of peeling.

The other problem is that when creating preheader, we set invalid value
for count of the entry edge resulting in wrong number of iterations to be
predicted.

Sat May  4 22:53:55 CEST 2002  Jan Hubicka  <jh@suse.cz>
	* unroll-new.c (unroll_or_peel_loop): Peel niter+1
	* cfgloopanal.c (create_preheader): Fix updating of profile.
*** unroll-new.c.old	Sat May  4 21:37:24 2002
--- unroll-new.c	Sat May  4 22:50:21 2002
*************** unroll_or_peel_loop (loops, loop, flags)
*** 1007,1013 ****
    if (exact)
      {
        /* If estimate is good, use it to decide and bound number of peelings.  */
!       if (niter > npeel)
  	{
  	  if ((flags & UAP_PEEL) && rtl_dump_file)
  	    fprintf (rtl_dump_file,
--- 1049,1055 ----
    if (exact)
      {
        /* If estimate is good, use it to decide and bound number of peelings.  */
!       if (niter + 1 > npeel)
  	{
  	  if ((flags & UAP_PEEL) && rtl_dump_file)
  	    fprintf (rtl_dump_file,
*************** unroll_or_peel_loop (loops, loop, flags)
*** 1015,1021 ****
  		     niter, npeel);
  	  flags &= ~UAP_PEEL;
  	}
!       npeel = niter;
  
        /* And unrollings.  */
        if (niter < 2 * nunroll)
--- 1057,1063 ----
  		     niter, npeel);
  	  flags &= ~UAP_PEEL;
  	}
!       npeel = niter + 1;
  
        /* And unrollings.  */
        if (niter < 2 * nunroll)
*** cfgloopanal.c.old	Sat May  4 22:31:23 2002
--- cfgloopanal.c	Sat May  4 22:31:24 2002
*************** create_preheader (loop, dom, flags)
*** 476,481 ****
--- 476,482 ----
  
    dummy->frequency -= EDGE_FREQUENCY (e);
    dummy->count -= e->count;
+   fallthru->count -= e->count;
    if (flags & CP_INSIDE_CFGLAYOUT)
      cfg_layout_redirect_edge (e, loop->header);
    else



More information about the Gcc-patches mailing list