This is the mail archive of the
gcc@gcc.gnu.org
mailing list for the GCC project.
Re: Loop oddity
- From: law at redhat dot com
- To: "John David Anglin" <dave at hiauly1 dot hia dot nrc dot ca>
- Cc: gcc at gcc dot gnu dot org
- Date: Tue, 22 Jan 2002 10:31:31 -0700
- Subject: Re: Loop oddity
- Reply-to: law at redhat dot com
In message <200201221708.g0MH8hj4015272@hiauly1.hia.nrc.ca>, "John David Anglin
" writes:
> Here is a loop oddity that I noticed. The loop
>
> for (i = 1000000; i; i--) {};
>
> yields the following assembly code when compiled at -O2 on the PA:
>
> ldil L'999424,%r19
> ldo 576(%r19),%r19
> ldo -625(%r19),%r19
> L$0109
> comib,<>,n 0,%r19,L$0109
> ldo -625(%r19),%r19
>
> You get similar results on other architectures. I was mystified by
> the transformation of the decrement from 1 to 625. Looking
> at the output of the loop pass, I see that it has unrolled the loop:
[ ... ]
The documentation needs to be updated.
The compiler will estimate the size of a rolled and unrolled loop -- if the
unrolled loop is likely to be as small or smaller than the rolled loop, then
it will proceed to unroll the loop.
jeff