This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Fix roundoff error in predictors
- From: Jan Hubicka <jh at suse dot cz>
- To: gcc-patches at gcc dot gnu dot org
- Date: Wed, 12 Feb 2003 15:26:27 +0100
- Subject: Fix roundoff error in predictors
Hi,
on stream benchmark we acutally predict all the code as infrequent.
It is because the initialization loop iterates 200000 times. This is
enought for GCC to decide that it has 0 probability to terminate and
thus all code after the loop has 0 probability to execute - including
the benchmark loops themselves.
I've installed the attached patch into mainline. 3.3 branch is not
affected as the roundoff error always happen in the correct direction
there.
Wed Feb 12 15:18:55 CET 2003 Jan Hubicka <jh@suse.cz>
* predict.c (estimate_probability): Fix roundoff error.
Index: predict.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/predict.c,v
retrieving revision 1.75.2.3
diff -c -3 -p -r1.75.2.3 predict.c
*** predict.c 11 Feb 2003 09:05:58 -0000 1.75.2.3
--- predict.c 12 Feb 2003 14:18:50 -0000
*************** estimate_probability (loops_info)
*** 447,460 ****
if (simple_loop_p (loops_info, loop, &desc)
&& desc.const_iter)
{
niter = desc.niter + 1;
if (niter == 0) /* We might overflow here. */
niter = desc.niter;
predict_edge (desc.in_edge, PRED_LOOP_ITERATIONS,
! REG_BR_PROB_BASE
! - (REG_BR_PROB_BASE + niter /2)
! / niter);
}
bbs = get_loop_body (loop);
--- 447,465 ----
if (simple_loop_p (loops_info, loop, &desc)
&& desc.const_iter)
{
+ int prob;
niter = desc.niter + 1;
if (niter == 0) /* We might overflow here. */
niter = desc.niter;
+ prob = (REG_BR_PROB_BASE
+ - (REG_BR_PROB_BASE + niter /2) / niter);
+ /* Branch prediction algorithm gives 0 frequency for everything
+ after the end of loop for loop having 0 probability to finish. */
+ if (prob == REG_BR_PROB_BASE)
+ prob = REG_BR_PROB_BASE - 1;
predict_edge (desc.in_edge, PRED_LOOP_ITERATIONS,
! prob);
}
bbs = get_loop_body (loop);