This is the mail archive of the gcc@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]

Re: Problem in propagating profiling information through loop unrolling


> 
> The following line from "scale_bbs_frequencies" of cfgloopmanip.c
>       bbs[i]->count = (bbs[i]->count * num) / den;
> may cause a loop whose preheader has a count of 1 (and whose body has a
> very
> large count) to receive a zero preheader count after a precondition is
> inserted on the preheader edge.  This phenomena was observed after noticing
> that the doloop rewrite (of Zedenek Dvorak) produced less branch-on-counts
> than the original one when feedback is turned on.  The zero preheader count
> convinced the doloop optimization that it was not profitable to perform the
> doloop opt.

It seems to me that the doloop optimization shall not be at all
disabled by count/frequency of header being zero when the body has
nonzero count/frequency.  Does the attached patch fix your problem too?
> 
> 
> IMHO, the result of the division should be rounded instead of truncated.
> When I used the below patch it fixed the problem - the unrolled loop was
> successfully "doloop'ed".
> I am not sure that this is the correct fix, please comment.

Rounding instead of truncating never hurts here too ;)


Index: cfgloopanal.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cfgloopanal.c,v
retrieving revision 1.2.4.10.2.3
diff -c -3 -p -r1.2.4.10.2.3 cfgloopanal.c
*** cfgloopanal.c	30 Mar 2004 23:18:42 -0000	1.2.4.10.2.3
--- cfgloopanal.c	19 Apr 2004 21:26:42 -0000
*************** expected_loop_iterations (const struct l
*** 431,437 ****
  	  count_in += e->count;
  
        if (count_in == 0)
! 	return 0;
  
        expected = (count_latch + count_in - 1) / count_in;
  
--- 431,437 ----
  	  count_in += e->count;
  
        if (count_in == 0)
! 	return count_latch * 2;
  
        expected = (count_latch + count_in - 1) / count_in;
  
*************** expected_loop_iterations (const struct l
*** 452,458 ****
  	  freq_in += EDGE_FREQUENCY (e);
  
        if (freq_in == 0)
! 	return 0;
  
        return (freq_latch + freq_in - 1) / freq_in;
      }
--- 452,458 ----
  	  freq_in += EDGE_FREQUENCY (e);
  
        if (freq_in == 0)
! 	return freq_latch * 2;
  
        return (freq_latch + freq_in - 1) / freq_in;
      }


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