This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
PATCH: fix gcov branch percentage for large hit count
- To: gcc-patches at gcc dot gnu dot org
- Subject: PATCH: fix gcov branch percentage for large hit count
- From: Janis Johnson <janis at us dot ibm dot com>
- Date: Tue, 10 Jul 2001 09:28:41 -0700
- Cc: jh at suse dot cz
- Reply-To: Janis Johnson <janis at us dot ibm dot com>
This patch fixes gcov so that branch-taken percentages are not corrupted
by moving hit counts into ints, where the value itself or the percentage
calculation can cause the value to overflow, resulting in meaningless
(negative) percentages.
This is copied to Jan Hubicka who recently changed other values in gcov
to use gcov_type and can verify that this change is correct.
The following test case demonstrates this problem on ia64-unknown-linux
and i686-pc-linux-gnu. There's no test framework for this, but if I
continue looking into branch profiling I'll look into extending the test
support for gcov to cover branch information also.
#define LIMIT1 7000
#define LIMIT2 7000
int count;
void
doit (int i, int j)
{
if (i > j)
count++;
}
int
main ()
{
int i, j;
for (i = 0; i < LIMIT1; i++)
for (j = 0; j < LIMIT2; j++)
doit (i, j);
return 0;
}
Without the fix part of loop.c.gcov is:
void doit (int i, int j)
49000000 {
49000000 if (i > j)
branch 0 taken = -37%
24496500 count++;
}
I built and tried out gcov on ia64-unknown-linux and i686-pc-linux-gnu
but didn't bother bootstrap and test with this fix since gcov is not
used in the build and has only 2 tests (3 when my patch from yesterday
goes in).
Janis
2001-07-10 Janis Johnson <janis@us.ibm.com>
* gcc/gcov.c: Fix branch percentage for large hit count.
--- gcc/gcov.c.orig Mon Jul 9 16:45:34 2001
+++ gcc/gcov.c Mon Jul 9 16:46:46 2001
@@ -140,8 +140,8 @@
struct arcdata
{
- int hits;
- int total;
+ gcov_type hits;
+ gcov_type total;
int call_insn;
struct arcdata *next;
};