Problem in propagating profiling information through loop unrolling
Mostafa Hagog
MUSTAFA@il.ibm.com
Mon Apr 19 21:36:00 GMT 2004
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.
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.
I used the following example to track down the problem
(a snip of 164.gzip benchmark):
compiled with mainline, -O3 -fprofile-generate/-fprofile-use
on powerpc-apple-darwin7.2.0 target.
bct.c:
unsigned long crc_32_tab[1000];
unsigned long updcrc(s, n)
unsigned char *s; /* pointer to bytes to pump through
*/
unsigned n; /* number of bytes in s[] */
{
register unsigned long c; /* temporary variable */
static unsigned long crc = (unsigned long)0xffffffffL; /* shift
register contents */
if (s == 0) {
c = 0xffffffffL;
} else {
c = crc;
if (n) do {
c = crc_32_tab[((int)c ^ (*s++)) & 0xff] ^ (c >> 8);
} while (--n);
}
crc = c;
return c ^ 0xffffffffL; /* (instead of ~c for 64-bit machines) */
}
bct-main.c:
int main ()
{
char s[2000];
return updcrc (s,1000);
}
Mostafa & Ayal.
Index: cfgloopmanip.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/cfgloopmanip.c,v
retrieving revision 1.23
diff -c -p -r1.23 cfgloopmanip.c
*** cfgloopmanip.c 24 Feb 2004 23:39:54 -0000 1.23
--- cfgloopmanip.c 19 Apr 2004 21:18:24 -0000
*************** scale_bbs_frequencies (basic_block *bbs,
*** 458,464 ****
for (i = 0; i < nbbs; i++)
{
bbs[i]->frequency = (bbs[i]->frequency * num) / den;
! bbs[i]->count = (bbs[i]->count * num) / den;
for (e = bbs[i]->succ; e; e = e->succ_next)
e->count = (e->count * num) /den;
}
--- 458,464 ----
for (i = 0; i < nbbs; i++)
{
bbs[i]->frequency = (bbs[i]->frequency * num) / den;
! bbs[i]->count = (bbs[i]->count * num + (den/2)) / den;
for (e = bbs[i]->succ; e; e = e->succ_next)
e->count = (e->count * num) /den;
}
More information about the Gcc
mailing list