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: Branch taken rate of Linux kernel compiled with GCC 4.9


Thank you for the explanation!

I tried the following simple code:
int test(int k)
{
  int x = 0;
  for (int i = 0; i < k; ++i)
    x += i;
  return x;
}

It was compiled (-O2) to something like:
int test(int k)
{
  if (k == 0) goto ret0;
  int x = 0;
  int i = 0;
loop:
  x += i;
  i += 1;
  if (i != k) goto loop;
  return x;
ret0:
  return 0;
}

Now I figure out why it doesn't make sense to reverse the branch
(without profile feedback).

2015-01-13 20:44 GMT+08:00 Alexander Monakov <amonakov@ispras.ru>:
> Your measurement includes the conditional branches at the end of loop bodies.
> When loops iterate, those branches are taken, and it doesn't make sense to
> reverse them.
>
> HTH
> Alexander


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