This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Branch taken rate of Linux kernel compiled with GCC 4.9
- From: Pengfei Yuan <0xcoolypf at gmail dot com>
- To: Alexander Monakov <amonakov at ispras dot ru>
- Cc: "gcc at gcc dot gnu dot org" <gcc at gcc dot gnu dot org>
- Date: Tue, 13 Jan 2015 22:21:28 +0800
- Subject: Re: Branch taken rate of Linux kernel compiled with GCC 4.9
- Authentication-results: sourceware.org; auth=none
- References: <CACmZjJLQK6y6+X-57BWmC9W-hfmaBe57ZVXrhqHKEUyW=WHatQ at mail dot gmail dot com> <alpine dot LNX dot 2 dot 11 dot 1501131541120 dot 20322 at monopod dot intra dot ispras dot ru>
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