This is the mail archive of the gcc-patches@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: [PATCH] Print 2 digits after decimal delimiter for BB frequencies


On 12/08/2016 05:55 AM, Martin Liška wrote:
With the patch applied, one can distinguish between PROB_VERY_UNLIKELY and
real zero probability:

I tried to see if formatting the expression

  e->probability * 100.0 / REG_BR_PROB_BASE

with "%.2f" is guaranteed to output non-zero when e->probability
is non-zero.  If I got the values right then the smallest non-zero
e->probability can be as low as 1, and REG_BR_PROB_BASE is 10000.
That evaluates to 0.0099999999999999985 which Glibc formats as
0.01 because (AFAIK) its printf rounds to nearest.

If this is guaranteed then I think it's fine.  Otherwise, if there
is a chance that the printed result could be 0.00% for a non-zero
probability it might be worth to detect it and make sure it's at
least 0.01% to avoid the same confusion I had with the 0.00%.

FWIW, if GCC uses integers rather than floats internally to make
decisions (I don't know) then also printing integers would give
the most accurate results.  E.g., something like
  printf ("%2u.%u%%", e->probability / 100, e->probability % 100)

Thanks
Martin


f ()
{
  int _1;

  <bb 2> [100.00%]:
  _1 = __builtin_sprintf (&d2, "%i", 12);
  if (_1 != 2)
    goto <bb 3>; [0.04%]
  else
    goto <bb 4>; [99.96%]

  <bb 3> [0.04%]:
  __builtin_abort ();

  <bb 4> [99.96%]:
  return;

}

Patch can bootstrap on ppc64le-redhat-linux and survives regression tests.

Ready to be installed?
Martin



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